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!
Solved! Go to Solution.
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.
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.
This is exactly what I was looking for, thanks!