Does anyone have a python API recipe for deleting features in an ArcGIS Online hosted feature layer? I'm specifically looking to clear out all the features in several layers.

11996
10
Jump to solution
08-03-2017 11:44 AM
AmberLauzon
New Contributor II

We have several emergency operation layers that we want to clear out quickly before an event. We will use juniper to share it with our staff too. Thank you.

0 Kudos
10 Replies
RoryBennison
New Contributor III

Thanks that worked perfectly for me, the only change I had to make was to change OBJECTID to OID because it was throwing up an error.

max_objid = flayer.query(out_statistics=[{"statisticType":"MAX","onStatisticField":"OID","outStatisticFieldName":"MAX_OBJ"}], return_geometry=False)
maxoid = max_objid.features[0].attributes['MAX_OBJ']

#delete in steps of 20000 or more, in case the dataset is large

i = 0
step = 20000

#replace maxoid with count if attempting to delete features based on feature count
while i <= maxoid:
i += step
flayer.delete_features(where=f"OID<= {i}")
print(i)

Cheers

0 Kudos