Quantcast
Channel: Forums - ArcObjects SDKs
Viewing all articles
Browse latest Browse all 1374

Overlap area between two polygons

$
0
0
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,
Carlos


Code:

        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;
            }
        }


Viewing all articles
Browse latest Browse all 1374

Trending Articles