Overlap area between two polygons

Discussion created by cpicciri on Apr 14, 2014
Latest reply on Apr 14, 2014 by cpicciri
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.


        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;

                pGeometry1 = pFeature1.Shape;
                pGeometry2 = pFeature2.Shape;

                //Simplify geometries.
                pTopologicalOperator = pGeometry1 as ITopologicalOperator2;
                pTopologicalOperator.IsKnownSimple_2 = false;

                pTopologicalOperator = pGeometry2 as ITopologicalOperator2;
                pTopologicalOperator.IsKnownSimple_2 = false;


                //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;
                    return false;
            catch (Exception ex)
                return true;