AnsweredAssumed Answered

ITopologicalOperator.Difference

Question asked by FugroGermany on Nov 29, 2017
Latest reply on Dec 11, 2017 by FugroGermany

Does anyone have some experience with ITopologicalOperator:Difference?

I want to erase features or feature parts (points, multipoints, lines or polygons) inside the polygons of a polygon featureclass.

I'm looking for an example how to use it. I always get an error when calling the method:

NotImplementedException

I know, in the helptext is written: "This method does not support GeometryBags."

But it works for ConstructUnion in the same manner, so I think that's not the problem.

 

(infeatclass is type of multipoint, erasefeatclass is type of polygon)

 

Friend Function funcEraseTest(pInFClass As IFeatureClass, _pEraseFClass As IFeatureClass) As IGeometry

        ' put all geometries to be erased into a collection

        Dim pPointSearchCur As IFeatureCursor = pInFClass.Search(Nothing, False)

        Dim pPointGeomBag As IGeometryBag = New GeometryBag

        Dim pPointGeomColl As IGeometryCollection = pPointGeomBag

        Dim pSimplify As ITopologicalOperator2

        Dim pFeat As IFeature

        pFeat = pPointSearchCur.NextFeature

        Do While Not pFeat Is Nothing

            pSimplify = pFeat.ShapeCopy

            pSimplify.IsKnownSimple_2 = False

            pSimplify.Simplify()

            pPointGeomColl.AddGeometry(pSimplify)

            pFeat = pPointSearchCur.NextFeature

        Loop

        ' put all erase geometries (polys) into a collection

        Dim pPolySearchCur = pEraseFClass.Search(Nothing, False)

        Dim pEraseGeomBag As IGeometryBag = New GeometryBag

        Dim pEraseGeomColl As IGeometryCollection = pEraseGeomBag

        Dim pEraseSimplify As ITopologicalOperator2

        pFeat = pPolySearchCur.NextFeature

        Do While Not pFeat Is Nothing

            pEraseSimplify = pFeat.ShapeCopy

            pEraseSimplify.IsKnownSimple_2 = False

            pEraseSimplify.Simplify()

            pEraseGeomColl.AddGeometry(pEraseSimplify)

            pFeat = pPolySearchCur.NextFeature

        Loop

 

        ' make erase

        Dim pResultMultiPoint As IMultipoint

        Dim pTopoOp As ITopologicalOperator

        pTopoOp = pPointGeomColl

 

        ' THIS THROWS THE ERROR:

        pResultMultiPoint = pTopoOp.Difference(pEraseGeomColl) 

    

        Return pResultMultiPoint

    End Function

Outcomes