Overlap area between two polygons

2605
3
04-14-2014 10:27 AM
CarlosPiccirillo
New Contributor III
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


        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;
            }
        }
0 Kudos
3 Replies
KevinYanuk
Occasional Contributor
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


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



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.
0 Kudos
CarlosPiccirillo
New Contributor III
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.
0 Kudos
CarlosPiccirillo
New Contributor III
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.


Never mind, I found the problem. It was the projection on one of the layers. Eventough both layers have the same factory code (2881) one is listed as "feet" while the other is not. That is the ONLY difference between the two layers, coordinate system, projection, etc. were all identical.

The ONLY difference is esriSRProjCS_NAD1983HARN_StatePlane_Florida_East_FIPS_0901_Ft (2881) versus esriSRProjCS_NAD1983HARN_StatePlane_Florida_East_FIPS_0901 (2881)

Hopefully this will save someone from having the headache I did today trying to fix this!

Carlos
0 Kudos