Select to view content in your preferred language

Capturing Edit event on Vertex basis

1210
3
01-21-2020 06:56 AM
SreenivasaRaoPigili
Frequent Contributor

Hi All,

    I would like to capture the Edit operation events. I am able to capture the Row level events based on Feature class. (ProSnippets Editing · Esri/arcgis-pro-sdk Wiki · GitHub ).

But i need to capture the events based on Vertex operation (i.e Adding Vertex and Delete Vertex). Can you please help me - how to handle these events.

Thank you in advance.

0 Kudos
3 Replies
by Anonymous User
Not applicable

Hi,

The sketch vertex events are not currently public or broadcast in the current releases. Its on the list.

You can listen to the sketch modified event in custom tools and work out the geometry changes in the sketch but thats a bit of work.

What workflows do you have that require the vertex events?

Thanks.

0 Kudos
SreenivasaRaoPigili
Frequent Contributor

Hi Sean Jones,

  Thanks for your reply.

Please find my scenario below.

We have created a relationship class between polygon feature class and standalone table. Due to this relationship, whenever we delete polygon – the associated entries from the table are also getting deleted.

But when we created a new polygon/ modify the existing polygon geometry – the corresponding records in the table are not getting updated.

to address this Modify geometry changes - i am trying to capture the vertex level events.

I have tried to use the "OnSketchModifiedAsync " virtual method now. But this method is not getting triggers for every vertex change. Please find the sample code snippet below.

internal class MapTool1 : MapTool
{

public MapTool1 ()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Point; 
SketchOutputMode = SketchOutputMode.Screen;
var systemCursor =System.Windows.Input.Cursors.Arrow; 
Cursor = systemCursor;

}

protected override async Task<bool> OnSketchModifiedAsync()
{

   MessageBox.Show("Entered into OnSketchModifiedAsync function");
   await QueuedTask.Run(async() =>{

   ActiveMapView.SelectFeatures(await GetCurrentSketchAsync());
   var sketch = await GetCurrentSketchAsync();
   var editOp = new EditOperation();
   editOp.Name = "Edit Vertex";
   editOp.SelectModifiedFeatures = true;
   editOp.SelectNewFeatures = true;
   MessageBox.Show(editOp.EditOperationType.ToString());


   //ArcGIS.Desktop.Editing.Events.RowChangedEvent.Subscribe(onRowChangedEvent, featureLayer.GetTable());

   //Execute the Edit Operation
   // editOp.Execute();
   //ArcGIS.Desktop.Editing.Events.RowChangedEvent.Unsubscribe(_rowChangedToken);
   //ArcGIS.Desktop.Editing.Events.RowChangedEvent.Unsubscribe(_rowCreatedToken);
   });
   return true;
}

Here if i enable the RowChangedEvent subscription - whenever there is a change in the feature table - the method is getting triggered and ideally this will happen only once we finish the geometry changes. In this situation, to achieve my goal i have to run multiple geoprocessing tools to get the vertices information from polygon feature and then load into table. But this will not a suitable option for us, since we are having complex polygons with thousands of vertex (some times).

Please correct me, if i am doing any wrong here. or please suggest any other alternative way to achieve my goal.

Thank you.

0 Kudos
SreenivasaRaoPigili
Frequent Contributor

Hi,

    Able to resolve this issue and please find my final workflow below.

Step 1: Capture the OnSketchCompleteAsync

OnSketchCompleteAsync
{
subscribe RowChangedEvent
}

Step 2: 
In the RowChangedEvent
{
      Compare the Polygon geometry(before and after the geometry modifications
      If there is any geometry change{
      a. Get the list of coordinates from Original Polygon

                  //Index of the shape field
                  var shapeIndex = lyrDefn.FindField(shapeField);
                  //Original geometry of the modified row
                  var geomOrig = obj.Row.GetOriginalValue(shapeIndex) as Geometry;
                  Polygon geometryOrig = geomOrig as Polygon;
                  IReadOnlyList<Coordinate2D> coordinatesOrig = geometryOrig.Copy2DCoordinatesToList();
      b. Get the list of coordinates from Modified Polygon
                  //Index of the shape field
                  var shapeIndex = lyrDefn.FindField(shapeField);
                  //New geometry of the modified row
                  var geomNew = obj.Row[shapeIndex] as Geometry;
                  Polygon geometryNew = geomNew as Polygon;
                  IReadOnlyList<Coordinate2D> coordinatesNew = geometryNew.Copy2DCoordinatesToList();
      c. Now Compare the coordinates and
                     i. If we add any vertexes - Modified Geometry.Except(Original Geometry), will return the newly added vertex coordinates details.
                     ii. If we delete vertexes - Original Geometry.Except(Modified Geometry), will return the deleted vertex coordinate details.

                              IEnumerable<Coordinate2D> differenceQuery1 = coordinatesNew.Except(coordinatesOrig);

              Now based on scenairo i or ii --> we will update the vertex table.
}

If anyone else has any other approach - please let me know. Thank you.

0 Kudos