Hi,
To convert a vertex to a control point, you have to simply change the ID of the vertex from 0 to 1. Control points have a vertex of 1.
So you can iterate through the vertices to find the 4th and 7th vertices.
In the following code snippet, I am changing two vertices in a selected polyline feature to be Control points.
- I iterate through the points in the selected line.
- Each point is converted into a MapPoint and gets added to a list. Points 6 and 7 are added as Control points. Notice the if statement on 20. These points are made "ID.Aware" and the IDs are set to be 1. Check out this page for more info: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic27355.html
- I create a new polyline using the point collection.
- Then I use an edit operation to modify the selected line with the new line I just made.
var lineLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
if (lineLayer == null)
return;
var changeVertexIDOperation = new EditOperation();
QueuedTask.Run( () =>
{
var lineLayerCursor = lineLayer.GetSelection().Search();
var lineVertices = new List<MapPoint>();
long oid = -1;
while (lineLayerCursor.MoveNext())
{
var lineFeature = lineLayerCursor.Current as Feature;
var line = lineFeature.GetShape() as Polyline;
int vertexIndex = 1;
oid = lineFeature.GetObjectID();
foreach ( var point in line.Points )
{
MapPointBuilderEx mapPointBuilderEx = new MapPointBuilderEx(point);
//I am changing the vertex 6 and 7 to control points
if (vertexIndex == 6 || vertexIndex == 7)
{
mapPointBuilderEx.HasID = true;
mapPointBuilderEx.ID = 1;
}
lineVertices.Add(mapPointBuilderEx.ToGeometry() as MapPoint);
vertexIndex++;
}
}
var newLine = PolylineBuilderEx.CreatePolyline(lineVertices);
changeVertexIDOperation.Modify(lineLayer, oid, newLine);
changeVertexIDOperation.Execute();
});