In my ArcObjects program, I need to check where a polygon feature (named f_A here) is included / overlapped with another polygon feature (named f_B hear). Is there an ArcObjects method for the this check-up? Thanks.
Solved! Go to Solution.
How to Execute Spatial Queries—ArcObjects 10.4 Help for Java | ArcGIS for Desktop . The article is for Java, but the concepts translate to .NET.
Hi Shaning,
This would be really easy with arcpy, but from what I can tell this article might help you out with how to use the Intersect tool with ArcObjects geoprocessing:
https://www.esri.com/news/arcuser/1207/files/gp_arcobjects.pdf
Or, the ITopologicalOperator.Intersect method could be used to determine if there is overlap.
Good luck!
Micah
Here's how I determine if a polygon overlaps another polygon
pTopoOp = pFeature.Shape
Dim pInGeometry As ESRI.ArcGIS.Geometry.IGeometry5
pInGeometry = pOtherFeature.Shape
If pInGeometry.Dimension = ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension Then 'check if the feature is a polygon
pOverlapGeometry = pTopoOp.Intersect(pInGeometry, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension)
If Not pOverlapGeometry Is Nothing And Not pOverlapGeometry.IsEmpty Then
'you've got an overlapping polygon
End If
End If
Ken: Thanks for your code. Could you tell me what is the data type of pOverlapGeometry since I need to convert your VB into c#. Thanks.
It's an IGeometry5 object
Before I sent my last message to you, I did try but got error:
'ESRI.ArcGIS.Geometry.IGeometry5' does not contain a definition for 'Intersect' and no extension method 'Intersect' accepting a first argument of type 'ESRI.ArcGIS.Geometry.IGeometry5' could be found (are you missing a using directive or an assembly reference?) .
My code is below:
bool feature_In_Other(IFeature f1, IFeature f2) {
IGeometry g = (IGeometry)f1.ShapeCopy; // also tried IGeometry5 g = (IGeometry5)f1.ShapeCopy;
ESRI.ArcGIS.Geometry.IGeometry5 pInGeometry = (ESRI.ArcGIS.Geometry.IGeometry5)f2.ShapeCopy;
if (pInGeometry.Dimension == ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension) {
if (f1.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPolygon) {
ESRI.ArcGIS.Geometry.IGeometry5 pOverlapGeometry = g.Intersect(pInGeometry, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension); // Got error on this line
}
}
}
What's wrong in my code? Thanks.
The Intersect method is called on the ITopologyOperator object. In my code, that's what the pTopoOp is.
Dim pTopoOp As ESRI.ArcGIS.Geometry.ITopologicalOperator
Ken: I revised the code per your feedback. The error was gone. Thanks.
How to Execute Spatial Queries—ArcObjects 10.4 Help for Java | ArcGIS for Desktop . The article is for Java, but the concepts translate to .NET.
Thanks a lot.