Hi JeffYes the CutPolygonFeature() is called in a loop. A cursor does retrieve the pFeatPoly in another method (with recycling enabled) which I've included in the code below. The whole process is wrapped in an edit session but I have to save edits as I go because the next iteration relies on the results of the current iteration.I�??ve included the basic code that encompasses the CutPolygonFeature() method to reflect the overall process involved. I hope this is enough info. I�??m happy to clarify further if needed.Cheers
//==== Pre set variables ======
IPointArray centerPoints; //points derived from intervals along a line
IPointArray offsetPointsA; //points offset from reciprocal centerPoints
IPointArray offsetPointsB; //points offset from reciprocal centerPoints in other direction
IApplication App;
IFeatureLayer polyLayer; //Polygon feature layer
IFeatureClass polyFC; //Feature class of polyLayer
//==============================
public void ProcessPolygonCuts()
{
IEditor pEditor;
IFeature pFeatPoly;
IPoint offsetPoint1;
IPoint offsetPoint2;
IPolyline pLine;
pEditor = EditSessionStart(App, polyLayer); //method included below
//for each densify point set skipping end points
for (int i = 1; i < centerPoints.Count - 1; i++)
{
//get intersect of poly feature from densified centre point
//there should be no overlapping polygons so this should only return one feature
pFeatPoly = GetIntersectPolygon(polyLayer, centerPoints.get_Element(i)); //method included below
//draw line between offset line points and get centre point
pLine = CreatePolylineByPoints(offsetPointsA.get_Element(i), offsetPointsB.get_Element(i));
pLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, centrePoint);
//calc closest intersect point with poly feature from a polyline ray in one direction from centre point
offsetPoint1 = GetClosestIntersectPoint((IPolygon5)pFeatPoly.ShapeCopy, centrePoint, offsetPointsA.get_Element(i), 2000); //distance in metres
// calc closest intersect point with poly feature from a polyline ray in other direction from centre point
offsetPoint2 = GetClosestIntersectPoint((IPolygon5)pFeatPoly.ShapeCopy, centrePoint, offsetPointsB.get_Element(i), 2000);
//cut poly feature
if (offsetPoint1 != null && offsetPoint2 != null)
{
//cut the polygon feature with the line created from the two offset points.
CutPolygonFeature(offsetPoint1, offsetPoint2, ref pFeatPoly, ref polyFC, ref App);
}
}
pEditor.StopEditing(true);
MessageBox("Finished");
}
//============================================================================
private IFeature GetIntersectPolygon(IFeatureLayer pFL, IPoint focalPoint)
{
IFeatureSelection intFSelection;
ISpatialFilter pSpatialFilter = null;
ICursor cursor;
IFeatureCursor MapCursor;
try
{
intFSelection = (IFeatureSelection)pFL;
pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = (IGeometry)focalPoint;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
intFSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
if (intFSelection.SelectionSet.Count > 1) {
return null;
//throw new Exception("More than one feature selected in polygon layer - Function GetIntersectPolygon");
}
intFSelection.SelectionSet.Search(null, true, out cursor);
MapCursor = (IFeatureCursor)cursor;
return MapCursor.NextFeature();
}
finally
{
intFSelection = null;
pSpatialFilter = null;
cursor = null;
MapCursor = null;
pFL = null;
focalPoint = null;
}
}
//============================================================================
public IEditor EditSessionStart(IApplication application, IFeatureLayer pFLayer)
{
UID pUID = new UID();
pUID.Value = "esriEditor.Editor";
IDataset pDS;
IEditor2 pEd = (IEditor2)application.FindExtensionByCLSID(pUID);
try{
if (pEd.EditState != esriEditState.esriStateEditing)
{
pDS = (IDataset)pFLayer.FeatureClass; //.FeatureDataset;
pEd.StartEditing(pDS.Workspace);
}
return pEd;
}
catch (Exception ex)
{
throw new Exception(ex.Message + " - EditSessionStart");
}
finally
{
application = null;
pFLayer = null;
pUID = null;
pEd = null;
pDS = null;
}
}