Can you help me with my code below to delete/send multiple ObjectIDs to a delete parameter?
Currently the code just finds one record and send that Object ID to the delete paramter, but id like to be able to select a certain value in a attribute field and delete all or setup some sort of For or While Loop to pass all Object IDs to the delete paramter. One of the field names is 'Biologist' and a test record/value for the example is 'jah'.
from arcgis.gis import GIS
from IPython.display import display
gis = GIS(username="xxx", password="xx")
search_result = gis.content.search('test url')
search_result[1]
test_item = search_result[1]
test_layers = test_item.layers
test_layers
test_fset = test_layers[0].query()
test_fset.df
test_flayer = test_layers[0]
test_flayer.properties.capabilities
test_features = test_fset.features
remove_feature = [f for f in test_features if f.attributes['Biologist'] == 'jah'][0]
dele = remove_feature.get_value('OBJECTID')
delete_result = test_flayer.edit_features(deletes=str(dele))
delete_result
-
create a feature layer, select layer by attribute (or use a where clause in your create feature layer) then use Delete_Features resources.arcgis.com/en/help/main/10.2/index.html#//… warning deletion outside an edit session has no undo, be sure to have a backup.Michael Stimson– Michael Stimson2018年04月05日 00:05:00 +00:00Commented Apr 5, 2018 at 0:05
-
@MichaelStimson I don't think the Delete_Features tool available in ArcGIS Pro/Map is supported in Hosted Feature Services/AGO data.user117985– user1179852018年04月05日 03:11:07 +00:00Commented Apr 5, 2018 at 3:11
-
Ah, so it's not arcpy, your revision of tags has cleared that up. Does esri.github.io/arcgis-python-api/apidoc/html/… (search for delete_features) help?Michael Stimson– Michael Stimson2018年04月05日 03:28:36 +00:00Commented Apr 5, 2018 at 3:28
1 Answer 1
The edit_features function expects a comma-separated list of object ids for the deletes argument. See https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features for documentation.
The following should work:
remove_features = [f for f in test_features if f.attributes['Biologist'] == 'jah']
object_ids = [f.get_value('OBJECTID') for f in remove_features]
object_ids_str = ",".join(object_ids)
delete_result = test_flayer.edit_features(deletes=object_ids_str)