Update cursor in ArcGIS Pro SDK

1923
2
Jump to solution
06-13-2019 08:29 AM
TimWitt2
MVP Alum

Currently I have a feature layer from which I want to select features that have a certain value and then delete them.

With arcpy it  was quiet easy, I would use the following code

with arcpy.da.UpdateCursor( "C:\\topo.gdb\\DangleErrors_buffer_join", "Join_Count") as cursor:
  for row in cursor:
    if row[0] == 1:
      cursor.deleteRow()

How would I do this with the ArcGISPro SDK?

Thanks!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Tim,

There's a few ways you can do this, as always.

The delete row/feature snippet shows an example of using a row cursor within an edit operation callback. This would be used if the feature class/table wasn't in the map.

You can also use a simple edit operation delete with a list of oids from a queryfilter.

      QueuedTask.Run(() =>
      {
        //find the layer in the map
        var streams = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Streams") as FeatureLayer;

        //queryfilter and selection
        QueryFilter queryFilter = new QueryFilter { WhereClause = "FType = 460" };
        var selection = streams.GetTable().Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal);

        //edit operation
        var op = new EditOperation();
        op.Name = "Delete with queryfilter";
        op.Delete(streams,selection.GetObjectIDs());
        op.Execute();
      });

You could also iterate through a rowcursor (table.search) to get the OID's and feed those into delete.

View solution in original post

2 Replies
by Anonymous User
Not applicable

Tim,

There's a few ways you can do this, as always.

The delete row/feature snippet shows an example of using a row cursor within an edit operation callback. This would be used if the feature class/table wasn't in the map.

You can also use a simple edit operation delete with a list of oids from a queryfilter.

      QueuedTask.Run(() =>
      {
        //find the layer in the map
        var streams = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Streams") as FeatureLayer;

        //queryfilter and selection
        QueryFilter queryFilter = new QueryFilter { WhereClause = "FType = 460" };
        var selection = streams.GetTable().Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal);

        //edit operation
        var op = new EditOperation();
        op.Name = "Delete with queryfilter";
        op.Delete(streams,selection.GetObjectIDs());
        op.Execute();
      });

You could also iterate through a rowcursor (table.search) to get the OID's and feed those into delete.

TimWitt2
MVP Alum

This is exactly what I was looking for, thanks!

0 Kudos