1

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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 4, 2018 at 23:52
3
  • 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. Commented 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. Commented 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? Commented Apr 5, 2018 at 3:28

1 Answer 1

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)
answered Dec 9, 2018 at 3:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.