AnsweredAssumed Answered

Get Geometry of Selected Feature

Question asked by davecouture on Jul 5, 2012
Latest reply on Jul 5, 2012 by kenbuja
Iâ??m able to get the Geometry of a Feature Class, but I would like to get the Geometry of the selected Feature. I think I have to find a way to get the Index of the selected, before getting the Geometry. I'm just having a little problem with it. This is what I have:



            ' Check if Zoning Polygon is in ArcMap           
            Dim pMap As IMap = My.ArcMap.Document.ActiveView
            Dim featLayerUid As New UIDClass
            featLayerUid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}"
            Dim enumLayer As IEnumLayer = pMap.Layers(featLayerUid, True) 
            enumLayer.Reset()
            Dim layer As ILayer = enumLayer.Next
            Dim fLayer As IFeatureLayer = CType(layer, IFeatureLayer)
            Do While Not (layer Is Nothing)

                If CType(fLayer.FeatureClass, IDataset).Name = "CSJGISSDE.GISDATA.Zoning" Or
                    CType(fLayer.FeatureClass, IDataset).Name = "Zoning" Then
                    Exit Do
                End If
                layer = enumLayer.Next()
            Loop
            If layer Is Nothing Then
                MsgBox("Zoning Polygon Feature Class is missing.")
                Return
            End If


             ' Check if feature is selected
            Dim featureSelection As IFeatureSelection = TryCast(fLayer, IFeatureSelection)
            If featureSelection.SelectionSet.Count() = 0 Then
                MsgBox("No Selection")
                Return
            End If


             ' Get the Geometry.
            Dim shapeFieldName As String = fLayer.FeatureClass.ShapeFieldName
            Dim shapeFieldIndex As Integer = fLayer.FeatureClass.FindField(shapeFieldName)           
            Dim fields As IFields = fLayer.FeatureClass.Fields
            Dim shapeField As IField = fields.Field(shapeFieldIndex)
            Dim geometryDef As IGeometryDef = shapeField.GeometryDef
            Dim featureShape As String = ""

            Select Case geometryDef.GeometryType
                Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint
                    featureShape = "Point"
                Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint
                    featureShape = "Multipoint"
                Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline
                    featureShape = "Polyline"
                Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon
                    featureShape = "Polygon"
                Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch
                    featureShape = "MultiPatch"
            End Select

            MsgBox(featureShape)

Outcomes