Get Geometry of Selected Feature

2193
1
Jump to solution
07-05-2012 08:07 AM
DaveCouture
New Contributor III
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)

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Why not just use the feature's Shape property to get a geometry, which has the GeometryType property?

View solution in original post

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor
Why not just use the feature's Shape property to get a geometry, which has the GeometryType property?
0 Kudos