Select to view content in your preferred language

Fix Loops or Knots.

2077
5
03-24-2021 10:58 AM
MKa
by
Frequent Contributor

I need to find a way to remove Loops or Knots when a user saves a new edit.  These polygons that I create are sent to as boundries for images to be gathered and some are being rejected because of these self intersecting loops.  They are not self intersecting as they dont have self intersections as two vertices are added.  I need a way to either find the loop/knot or remove it automatically.  My removing self intersection code doesn't seem to fix this issue.  It appears I need to remove the loop entirely.

 

MKa_0-1616608635022.png

 

 

        protected void RemoveSelfIntersections()
        {            
            try
            {
                Geometry originalShape = _dataInspector.Shape;
                if (!GeometryEngine.Instance.IsSimpleAsFeature(originalShape))
                {
                    Geometry intersectionShape = GeometryEngine.Instance.SimplifyAsFeature(originalShape, true);
                }
            }
            catch (Exception e)
            {
                
            }

        }

 

 

Tags (1)
5 Replies
KirkKuykendall1
Frequent Contributor

Can you draw a picture of what your desired result would be?

Did you try creating a polyline from the points in the polygon?  Since the first and last point in the polygon presumably coincide, I'd guess you should make a List of all but the last point in the polygon and then pass that list to CreatePolyline.  After that you could to simplify the polyline.

Also there's the SimplifyPolyline method.  I've never used it, I'm waiting until they simplify its documentation before digging into that one.

 

 

0 Kudos
MKa
by
Frequent Contributor

The result would be without that knot in the middle of the drawing.  This is where someone either turned around in the area while walking/driving or digitizing.  So it made a loop.  I am able to add points and remove the self intersection, but i am interested in either flagging or removing this part completely (Filled in with green).

MKa_0-1616688829275.png

 

 

0 Kudos
KirkKuykendall1
Frequent Contributor

Perhaps making a list of vertices with duplicate coordinates could be used for flagging.

protected override async void OnClick()
{
    try
    {
        var fLayer = MapView.Active?.GetSelectedLayers()
            .OfType<FeatureLayer>()
            .Where(lyr => lyr.ShapeType == esriGeometryType.esriGeometryPolygon)
            .FirstOrDefault();
        if (fLayer == null)
            return;
        await QueuedTask.Run(() =>
        {
            using (var sel = fLayer.GetSelection()) 
            using (var cur = sel.Search())
            {
                if (cur.MoveNext())
                {
                    using (var feat = cur.Current as Feature)
                    {
                        var list = GetSelfIntersects(feat.GetShape() as Polygon);
                        Debug.Print($"{list.Count} duplicate vertices");
                    }
                }
            }
        });
    }
    catch(Exception ex)
    {
        Debug.Print(ex.Message);
    }
}
private List<MapPoint> GetSelfIntersects(Polygon polygon)
{
    // assumes vertices have been snapped
    // (skip this first point, since it will coincide with last point)            
    return polygon.Points.Skip(1)
        // could round here to cluster
        //.GroupBy(pnt => (Math.Round(pnt.X,2),Math.Round(pnt.Y,2)) 
        .GroupBy(pnt => (pnt.X, pnt.Y)) // could round here to cluster
        .Where(g => g.Count() > 1)
        .Select(g =>
        {
            var sr = polygon.SpatialReference;
            return MapPointBuilder.CreateMapPoint(g.Key.X, g.Key.Y, sr);
        })
        .ToList();
}
0 Kudos
MKa
by
Frequent Contributor

I will give this a shot.  I think in my case two points can not share the same location.  So I could do this and flag the field.  I will try and implement something like this now and post my solution or what I came up with.

0 Kudos
by Anonymous User
Not applicable

Hi @MKa ,

This is my thought, if you want to remove inner white area from your geometry.

If you list the geometry rings from your polygon, there will be two rings from your example.

Anti-clockwise ring shall be inner white color ring and just remove it.

But for ArcGIS Pro sdk, I noticed that function GetExteriorRings of polygon. you may try and create polygon from these rings, I think this will remove inner white colour ring.

Best Regards,

0 Kudos