IRelationalOperator2 IsNear: Polygon Vs Polygons ?

268
0
10-08-2018 07:57 AM
TieshengWu
Occasional Contributor

Hi everyone,

I would like to judge whether a polygon IsNear many polygons. I consider to use a GeometryBag to contain many polygons but it doesn't work.

My VB.NET snippet is like below:

Dim polygons_allbag As IGeometryBag = New GeometryBagClass
polygons_allbag.SpatialReference =...
Dim polygons_all As IGeometryCollection = CType(polygons_allbag, IGeometryCollection)

polygons_all.AddGeometry...

dim polygon as IPolygon=...

Dim pTopoOp2 As ESRI.ArcGIS.Geometry.IRelationalOperator2 = CType(polygon, IRelationalOperator2)
MsgBox(pTopoOp2.IsNear(polygons_all, 0))          ' This always display FALSE even if the polygon overlaps some polygons in polygons_all

Dim pTopoOp2 As ESRI.ArcGIS.Geometry.IRelationalOperator2 = CType(polygons_all, IRelationalOperator2)   'This will give an "unable to cast COM object..." error. 

MsgBox(pTopoOp2.IsNear(polygons , 0))

 

What's wrong with my code and what's the best solution for my problem?  The Union method will do but  very slow since there are many polygons to be compared with.

0 Kudos
0 Replies