How to Convert Vertex to Control Point?

295
3
02-24-2024 11:12 PM
by
New Contributor III

In Edit control points—ArcGIS Pro | Documentation, there is an operation called 'Convert Vertex to Control Point'. How to make it with SDK C# programming.

Because if I want to get the suppress symbol effect in a line feature, it needs control points.(Re: Suppress symbol effect in ArcGIS Pro - Esri Community)

By the way, I am using ArcGIS Pro SDK for .NET 3.0 version, and can it make it or needs higher version?

Tags (3)
1 Solution

Accepted Solutions
Esri Regular Contributor

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();
{
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;
}
vertexIndex++;
}
}
var newLine = PolylineBuilderEx.CreatePolyline(lineVertices);
changeVertexIDOperation.Modify(lineLayer, oid, newLine);
changeVertexIDOperation.Execute();
});``````

3 Replies
by
New Contributor III

All I want to do is as simple as convert the 4th and 7th vertex of a polyline feature to control points. The method you mentioned is a bit complicated for SDK programming, I haven't tried it before, and I'm not sure if it can achieve the same effect.

Esri Regular Contributor

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();
{
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;
}
vertexIndex++;
}
}
var newLine = PolylineBuilderEx.CreatePolyline(lineVertices);
changeVertexIDOperation.Modify(lineLayer, oid, newLine);
changeVertexIDOperation.Execute();
});``````

by
New Contributor III

U r my hero!