Select to view content in your preferred language

ArcObjects - Error in cast an IGeometry object

3289
2
Jump to solution
10-27-2014 08:07 AM
ShaningYu
Honored Contributor

Referring to the code at

' http://stackoverflow.com/questions/9212398/how-to-determine-whether-a-geometry-is-multi-part

static bool IsMultiPart(this IGeometry geometry{
  
var geometryCollection = geometry as IGeometryCollection;
  
return geometryCollection != null && geometryCollection.GeometryCount > 1;
}

 

I wrote a piece of VBA as below, but got a compiling error (Sub or Function not defined) at the line as highlighted below.  What's wrong in this piece of code?  Appreciate if you can point out.

Function IsMultiPart(geo As IGeometry)

    Dim b As Boolean

    Dim geometryCollection As IGeometryCollection

    Set geometryCollection = CType(geo, IGeometryCollection)

    If geometryCollection <> Null And geometryCollection.GeometryCount > 1 Then

        b = True

    Else

        b = False

    End If

    IsMultiPart = b

End Function

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ShaningYu
Honored Contributor

by adding the following, the problem was gone.  Thanks.

        Set pCurve = pFeature.Shape
        Dim mAware As IMAware
        Set mAware = pCurve
        mAware.mAware = True
       ...
        Dim seg As IMSegmentation3

View solution in original post

0 Kudos
2 Replies
ShaningYu
Honored Contributor

I revised the code like that below, but got error at the highlighted line: The geometry is not M-aware.  Appreciate if you can help this issue - How to make the IMSegmentatione object as M-awared.

Sub CheckSegments()

    Dim pDoc As IMxDocument

    Set pDoc = ThisDocument

    Dim pMaps As IMaps

    Set pMaps = pDoc.Maps

    Dim pMap As IMap

    Set pMap = pMaps.Item(0)

    Dim pLayer As ILayer

    Dim pFLayer As IFeatureLayer

    Dim sFCName As String

    sFCName = "GIS_RAIL_TRK_SEG_LIN"

   

    Dim i As Integer

    For i = 0 To pMap.LayerCount - 1

        If pMap.Layer(i).Name = sFCName Then

            Set pLayer = pMap.Layer(i)

            If TypeOf pLayer Is IFeatureLayer Then

                Set pFLayer = pLayer

                Exit For

            End If

        End If

    Next i

   

    Dim pFClass As IFeatureClass

    Set pFClass = pFLayer.FeatureClass

   

    Dim pQFilter As IQueryFilter

    Set pQFilter = New QueryFilter

    pQFilter.WhereClause = "[TRACK_TYPE] LIKE 'MAIN TRACK'"

   

    Dim pFCursor As IFeatureCursor

    Set pFCursor = pFClass.Search(pQFilter, False)

   

    Dim pCurve As ICurve, pFeature As IFeature

    Set pFeature = pFCursor.NextFeature

   

    Do Until pFeature Is Nothing

        If pFLayer.FeatureClass.ShapeType = esriGeometryPolyline Then   ' esriGeometryPolyline-3  esriGeometryLine-13

            Set pCurve = pFeature.Shape

            Set pFeature.Shape = pCurve

            Dim seg As IMSegmentation3

            Set seg = pFeature.Shape      'pCurve

            If seg.MMonotonic <> esriMMonotonicEnum.esriMNotMonotonic Then

                Debug.Print

            End If

           

        End If

        Set pFeature = pFCursor.NextFeature

    Loop

End Sub

0 Kudos
ShaningYu
Honored Contributor

by adding the following, the problem was gone.  Thanks.

        Set pCurve = pFeature.Shape
        Dim mAware As IMAware
        Set mAware = pCurve
        mAware.mAware = True
       ...
        Dim seg As IMSegmentation3
0 Kudos