1

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 belowattached image, 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();
                                                }
                                            }
                                        }
                                    }
                                }                     
1

Yes, targetPoly will still reference the original geometry. I think you need to use targetPoly = redactedPoly to continue with the modified version.

BTW, you don't really need to do the operation inside the loop, you can calculate the new geometry, and write it back after the for loop.

1
  • You sir, have saved me from my hours of anguish. Thank you :) – ketar Nov 21 '19 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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