How to Convert Vertex to Control Point?

295
3
Jump to solution
02-24-2024 11:12 PM
HaoWong
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?

1 Solution

Accepted Solutions
UmaHarano
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();
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();
});

 

 

 

 

View solution in original post

3 Replies
HaoWong
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.

0 Kudos
UmaHarano
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();
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();
});

 

 

 

 

HaoWong
New Contributor III

U r my hero!