private static bool DetermineOverlapArea(IFeature pFeature1, IFeature pFeature2) { ITopologicalOperator2 pTopologicalOperator = null; IGeometry pGeometry1 = null; IGeometry pGeometry2 = null; IGeometry pIntersectGeometry = null; IArea pIntersectArea = null; IArea pFeature1Area = null; IArea pFeature2Area = null; try { pGeometry1 = pFeature1.Shape; pGeometry2 = pFeature2.Shape; //Simplify geometries. pTopologicalOperator = pGeometry1 as ITopologicalOperator2; pTopologicalOperator.IsKnownSimple_2 = false; pTopologicalOperator.Simplify(); pTopologicalOperator = pGeometry2 as ITopologicalOperator2; pTopologicalOperator.IsKnownSimple_2 = false; pTopologicalOperator.Simplify(); pGeometry1.SnapToSpatialReference(); pGeometry2.SnapToSpatialReference(); //Get intersection area. pTopologicalOperator = pGeometry1 as ITopologicalOperator2; pIntersectGeometry = pTopologicalOperator.Intersect(pGeometry2, esriGeometryDimension.esriGeometry2Dimension) as IGeometry; pIntersectArea = pIntersectGeometry as IArea; pFeature1Area = pGeometry1 as IArea; pFeature2Area = pGeometry2 as IArea; //Get overlap area. int appOverlap = Convert.ToInt32((pIntersectArea.Area / pFeature1Area.Area) * 100); int ensOverlap = Convert.ToInt32((pIntersectArea.Area / pFeature2Area.Area) * 100); if (appOverlap > 5 || ensOverlap > 5) return true; else return false; } catch (Exception ex) { return true; } }
Hi everyone,
I have a script that checks the percentage of overlap between two polygons. The code below was working fine in 9.3 but now in 10.1 it crashes every time on the pTopologicalOperator.Intersect line with an error of "Exception from HRESULT: 0x80040215." I looked this code up on the Web but only found a few results and none of them matched my problem. I also followed the ESRI instructions to convert the hexidecimal number but I got no results when using ErrorLookup. Any help is greatly appreciated.
Thanks,
Carlosprivate static bool DetermineOverlapArea(IFeature pFeature1, IFeature pFeature2) { ITopologicalOperator2 pTopologicalOperator = null; IGeometry pGeometry1 = null; IGeometry pGeometry2 = null; IGeometry pIntersectGeometry = null; IArea pIntersectArea = null; IArea pFeature1Area = null; IArea pFeature2Area = null; try { pGeometry1 = pFeature1.Shape; pGeometry2 = pFeature2.Shape; //Simplify geometries. pTopologicalOperator = pGeometry1 as ITopologicalOperator2; pTopologicalOperator.IsKnownSimple_2 = false; pTopologicalOperator.Simplify(); pTopologicalOperator = pGeometry2 as ITopologicalOperator2; pTopologicalOperator.IsKnownSimple_2 = false; pTopologicalOperator.Simplify(); pGeometry1.SnapToSpatialReference(); pGeometry2.SnapToSpatialReference(); //Get intersection area. pTopologicalOperator = pGeometry1 as ITopologicalOperator2; pIntersectGeometry = pTopologicalOperator.Intersect(pGeometry2, esriGeometryDimension.esriGeometry2Dimension) as IGeometry; pIntersectArea = pIntersectGeometry as IArea; pFeature1Area = pGeometry1 as IArea; pFeature2Area = pGeometry2 as IArea; //Get overlap area. int appOverlap = Convert.ToInt32((pIntersectArea.Area / pFeature1Area.Area) * 100); int ensOverlap = Convert.ToInt32((pIntersectArea.Area / pFeature2Area.Area) * 100); if (appOverlap > 5 || ensOverlap > 5) return true; else return false; } catch (Exception ex) { return true; } }
Ah yes, the HRESULT error. Give this a look:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002zz000000
find out what the code is representing, and that may narrow down what exactly is happening... also migrating from 9.3 to 10 has caused some bad/weird problems for me in the past.
Thanks for the reply. Unfortunately, I already went through that exercise and the resulting code I got returned a new error, grrr! That is what I was refering to in the last sentence of my post. Thanks anyhow, I appreciate it. If you have other ideas, I'm all ears.