How to add point/vertex to existing polygon

1615
2
Jump to solution
04-14-2021 04:16 AM
SreenivasaRaoPigili
Occasional Contributor

Hi All,

    We are using ArcGIS Pro SDK 2.7. We want to add a vertex/point to the polygon. We have tried multiple ways to achieve this.

1. a. Read existing polygon points into List .

    b. Add the desired points (needs to add into polygon) to the list

    c. Update the geometry with latest geometry.

Snippet;

var selectedTargetFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
var inspTargetInspector = new Inspector();

inspTargetInspector.Load(selectedTargetFeatures.Keys.First(), targetID);

Polygon objTargetPolygon = inspTargetInspector.Shape as Polygon;
ReadOnlyPointCollection objTargetPolyPointCollection = objTargetPolygon.Points;

ICollection<MapPoint> objMapPoints = new List<MapPoint>(objTargetPolyPointCollection.Count);
objTargetPolyPointCollection.CopyPointsToList(0, objTargetPolyPointCollection.Count - 1, ref objMapPoints);


objMapPoints.Add(resultMultipoint1.Points[0]);
objMapPoints.Add(resultMultipoint2.Points[0]);
Polygon polygon = PolygonBuilder.CreatePolygon(objMapPoints, SpatialReferences.WGS84);

inspTargetInspector.Shape = polygon;

//create and execute the edit operation
var op = new EditOperation()
{
Name = "Add vertex",
SelectModifiedFeatures = false,
SelectNewFeatures = false
};
op.Modify(inspTargetInspector);

op.Execute();

 

But here Problem is - all these new points are creating under new Part. We want all these points into existing polygon part.

2. We tried to follow runtime sdk approach.

     a. Create PolygonBuilder object

      b. Tried to read Part, Point index in ProximityResult , AddPoint in particular index -- We dont have access to these functionality in Pro SDK.

Code Snippet:

PolygonBuilder builder = new PolygonBuilder(objTargetPolygon); // Create builder from existing polygon

builder.Parts[0].InsertPoint(index, new MapPoint(x, y)); // Insert point into specific location

graphic.Geometry = builder.ToGeometry(); // Create geometry and assign it back to the graphic / feature

https://community.esri.com/t5/arcgis-runtime-sdk-for-net/command-addvertex/td-p/758557 

----------------

Can someone please help us - how can we add vertex/point into existing polygon.

Also, @Wolf  @UmaHarano  - is there any plans to make it available all these functionalities in ArcGIS Pro SDK.

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hello, 

 

Have you tried the 

GeometryEngine.Instance.SplitAtPoint function?

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic27292.html

In your scenario the projectOnto and createPart parameters should be false. 

 

Narelle

View solution in original post

0 Kudos
2 Replies
NarelleChedzey
Esri Contributor

Hello, 

 

Have you tried the 

GeometryEngine.Instance.SplitAtPoint function?

https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic27292.html

In your scenario the projectOnto and createPart parameters should be false. 

 

Narelle

0 Kudos
SreenivasaRaoPigili
Occasional Contributor

Thank you Narelle. This helped me. Thanks a lot.

0 Kudos