1

I would like to intersect a polygon and a polyline to know if the polyline is in the polygon.

The code works but when i do it on more than 100 000 times in a for, there is this error :

System.Runtime.InteropServices.COMException (0x80040239): Exception de HRESULT : 0x80040239
    à ESRI.ArcGIS.Geometry.ITopologicalOperator.Intersect(IGeometry other, esriGeometryDimension resultDimension)

My code :

ITopologicalOperator4 topoOperateur = secteurPsr.Shape as ITopologicalOperator4;
topoOperateur.IsKnownSimple_2 = false;
topoOperateur.Simplify();
IGeometry geomPsr = currentPsr.Value.Shape;
IPolyline polylinePsr = geomPsr as IPolyline;
(geomPsr as ITopologicalOperator2).Simplify();
IGeometry geomResult = null;
try 
{
    geomResult = topoOperateur.Intersect(geomPsr,esriGeometryDimension.esriGeometry1Dimension);
 }
1

I found the solution at ArcObjects: Memory leak in IFeatureClass.Search (only on SDE with direct connect)

Code correction :

ITopologicalOperator4 topoOperateur = ((IClone)secteurPsr.Shape).Clone() as ITopologicalOperator4;
                IGeometry geomPsr = ((IClone)currentPsr.Value.Shape).Clone();
                IPolyline polylinePsr = geomPsr as IPolyline;
                IGeometry geomResult = null;
                geomResult = topoOperateur.Intersect(geomPsr, esriGeometryDimension.esriGeometry1Dimension);
 if (geomPsr != null)
                    Marshal.FinalReleaseComObject(geomPsr );
 if (topoOperateur != null)
                    Marshal.FinalReleaseComObject(topoOperateur);

Not the answer you're looking for? Browse other questions tagged or ask your own question.