I am atttempting to modify a feature twice using EditOperation in a loop. I am redacting certain subcurves from a given polyline at different sections of the line. The output polyline should be the original line without the two subcurves redacted by the for loop. But as you can see from the image below, only the redaction from the second loop is performed. Using the undo stack, I was able to see that after the first loop, the polyline is indeed modified correctly but on the second modification,(editop.Modify(poly, oid, redactedPoly);
) instead of using the modified feature in the first loop as the source poly, it seems like it's using the original unmodified polyline to perform the modification in loop two. How can I get it to modify the polyline correctly. I also attempted to use chained edit operation but the results were the same.
var poly = MapView.Active.Map.GetLayersAsFlattenedList().First() as FeatureLayer;
using (var TargetCursor = poly.Search(queryFTarget))
{
while (TargetCursor.MoveNext())
{
targetFeat = TargetCursor.Current as Feature;
var oid = targetFeat.GetObjectID();
var targetPoly = targetFeat.GetShape() as Polyline;
if (targetPoly == null || targetPoly.IsEmpty) //if the target feature is null or empty
{
file.WriteLine($"Unable to redact '{sourceID}' and '{targetID}'.");
file.WriteLine($"Feature '{targetID}' has no shape!");
}
else
{
var distancesAlongCurve = GetDistancesAlongCurve(targetPoly, ptCollection);//Get the distances along the source line for each demarkation point as ratios
distancesAlongCurve.Sort();
for (var i = 0; i < distancesAlongCurve.Count; i += 2)
{
var GetsubCurve = GeometryEngine.Instance.GetSubCurve(targetPoly, distancesAlongCurve[i], distancesAlongCurve[i + 1], AsRatioOrLength.AsRatio);
var subCurve = GeometryEngine.Instance.SimplifyAsFeature(GetsubCurve) as Polyline;
if (subCurve != null && !subCurve.IsEmpty)
{
var difference = GeometryEngine.Instance.Difference(targetPoly, subCurve);
var redactedPoly = GeometryEngine.Instance.SimplifyAsFeature(difference) as Polyline;
var editop = new EditOperation();
editop.Name = "Redact Polyline";
editop.Modify(poly, oid, redactedPoly);
await editop.ExecuteAsync();
}
}
}
}
}