Select to view content in your preferred language

ITopologicalOperator.Difference

1351
3
11-29-2017 01:17 AM
HagenProbsthain1
New Contributor III

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

0 Kudos
3 Replies
AbhishekKabra
Esri Contributor

Hi,

GeometryBag does not implement all the methods from ITopologicalOperator interface. BufferClip, and Simplify are the only methods of ITopologicalOperator supported on GeometryBags. 

I think you can do it like this:

For each multipoint in multipoint_feature_class

   For each polygon in polygon_feature_class

      // C++ syntax     

      IGeometryPtr ipRes; 

      ITopologicalOperatorPtr(multipoint )->Difference(polygon, &ipRes);

      Add ipRes to result geometry bag

   end 

end

HagenProbsthain1
New Contributor III

OK, thank you for your response, I'll try to test it. In the meantime I've called the Toolbox-Tool "Erase" inside my code. It is easier to use as to call the method in loops.

0 Kudos
HagenProbsthain1
New Contributor III

The problem is, that the documentation says for most of the methods: "This method does not support GeometryBags". But this is not correct, i. e. ConstructUnion works with it. So I thought, the sentence is obsolete and it was forgotten to delete. But at least for the Difference method the documentation is correct.

Therefore my workaround is to use the ConstructUnion method to create a multipart geometry for both input and erase features and then put these geometries to the Difference method. It works fine.

0 Kudos