Common Custom EditorTaskCommon_CustomEditorTask_VBNet\CustomEditorTask_VBNet\PolygonToLine.vb
' Copyright 2007 ESRI
'
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
'
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
'
' See the use restrictions.
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ESRI.ArcGIS.ADF.ArcGISServer
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools
Imports ESRI.ArcGIS.ADF.ArcGISServer.Editor
Imports ESRI.ArcGIS.Carto
Namespace CustomEditorTask_VBNet
Friend Class PolygonToLine
Inherits EditorServerCommandAction
Private features_Renamed As List(Of Integer) = New List(Of Integer)()
Private destinationFeatureClass_Renamed As IFeatureClass
' Maintain a list of new polyline features
Public ReadOnly Property Features() As List(Of Integer)
Get
Return features_Renamed
End Get
End Property
' Reference to feature class for IPolyline layer
Public ReadOnly Property DestinationFeatureClass() As IFeatureClass
Get
If destinationFeatureClass_Renamed Is Nothing Then
destinationFeatureClass_Renamed = GetDestinationFeatureClass()
End If
Return destinationFeatureClass_Renamed
End Get
End Property
' Clear the feature id list during initialization
Protected Overrides Function Init(ByVal editor As Editor) As Boolean
features_Renamed.Clear()
Return MyBase.Init(editor)
End Function
' Implementation code to convert selected polygon features to polylines and store in user defined feature layer.
Protected Overrides Sub EditorServerAction()
Dim agsSOAPMapDescription As ESRI.ArcGIS.ADF.ArcGISServer.MapDescription = Editor.MapFunctionality.MapDescription
Dim fidSet As Integer() = LayerDescription.SelectionFeatures
If Not fidSet Is Nothing AndAlso fidSet.Length > 0 Then
If DestinationFeatureClass Is Nothing Then
Return
End If
Dim agsCOMTopoOp3 As ITopologicalOperator3 = Nothing
Dim agsCOMFeature As IFeature = Nothing
Dim agsCOMNewFeature As IFeature = Nothing
Try
StartEditOperation()
Dim agsCOMFeatureCursor As IFeatureCursor = FeatureLayer.FeatureClass.GetFeatures(fidSet, False)
agsCOMFeature = agsCOMFeatureCursor.NextFeature()
Do While Not agsCOMFeature Is Nothing
agsCOMTopoOp3 = CType(agsCOMFeature.ShapeCopy, ITopologicalOperator3)
Dim agsCOMGeometry As IGeometry = CType(agsCOMTopoOp3, IGeometry)
If (Not agsCOMGeometry.IsEmpty) Then
agsCOMNewFeature = DestinationFeatureClass.CreateFeature()
' Store the boundary of selected polygon
agsCOMNewFeature.Shape = agsCOMTopoOp3.Boundary
agsCOMNewFeature.Store()
' Keep track of converted features
features_Renamed.Add(agsCOMNewFeature.OID)
End If
agsCOMFeature = agsCOMFeatureCursor.NextFeature()
Loop
StopEditOperation()
Catch e As Exception
AbortEditOperation(e)
End Try
If features_Renamed.Count > 0 Then
' Refresh the Map
Editor.Map.Refresh()
End If
End If
End Sub
' Retreive polyline feature class using drop down list in custom PolygonToLineLayerEditorPanel.
' Drop down sets a custom property on the Editor, PolylineLayerID.
Private Function GetDestinationFeatureClass() As IFeatureClass
Dim destinationLayerID As Integer = (CType(Editor, CustomEditor)).PolylineLayerID
If destinationLayerID = -1 Then
Return Nothing
End If
Dim agsCOMMapServerObjects2 As ESRI.ArcGIS.Carto.IMapServerObjects2 = TryCast(Me.IMapServer, ESRI.ArcGIS.Carto.IMapServerObjects2)
Dim agsCOMFeatureLayerDestination As IFeatureLayer = CType(agsCOMMapServerObjects2.Layer(Resource.DataFrame, destinationLayerID), IFeatureLayer)
If Not agsCOMFeatureLayerDestination Is Nothing Then
Return (agsCOMFeatureLayerDestination.FeatureClass)
Else
Return (Nothing)
End If
End Function
End Class
End Namespace