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.
Although this is not a full recipe, here is the snippet:
You can delete features by calling delete_features() method on your FeatureLayer object like shown below:
feature_layer_item = gis.content.search("your search criteria")flayers = feature_layer_item.layersflayer = flayersflayer.delete_features(where="objectid > 0")
You can specify any other query to selectively delete some features. Alternately, if you want to delete call, then call the truncate() method on the FeatureLayerManager
Truncate will delete all features and reset the objectid or fid count back to 0. Help for truncate
Thank you! Just what I needed!
Hi Amber Lauzon ,
Could you mark Atma Mani 's post as the correct answer please? This will help other users to quickly find the correct solution.
One caveat, Truncate is not yet supported on ArcGIS Enterprise, it works for ArcGIS Online though.
Pardon my inexperience, but I am trying to install the py for api package and I cannot using ArcGIS Pro 1.4, do you have any suggestions? The "Updates" and "Add" tabs are blank too...
One more caveat: looks like truncate doesn't work if sync is enabled on the dataset.
Not much of a problem though as the delete features seems to work fine and reasonably quickly.
flayer.delete_features(where="objectid > 0")
I used the sample that Atma Mani provided and created a small script to delete features from a Hosted Feature Service in AGOL that has multiple sub-layers.
import osimport jsonimport arcgisfrom arcgis.gis import GISimport arcgis.featureslayerName = 'title:Your Layer Name'maxLayerAmount = 10 # number of sublayersagolURL = "https://<your org>.maps.arcgis.com"agolUN = "<Your UserName>"agolPass = "<Your Password>"# connect to your GISgis = GIS(agolURL, agolUN, agolPass) layerCount = -1while (layerCount < maxLayerAmount): layerCount += 1 feature_layer_item = gis.content.search(layerName, item_type = 'Feature Service')  flayers = feature_layer_item.layers flayer = flayers[layerCount] print("Layer ID: " + str(layerCount) + " Layer Name: " + flayer.properties.name) flayer.delete_features(where="objectid > 0")
I also added some logging to display the name of the layers as it loops through them.
The logging looks something like this:
Layer ID: 0 Layer Name: Point LayerLayer ID: 1 Layer Name: Line LayerLayer ID: 2 Layer Name: Polygon Layer
I am still new to Python, so if there are any suggestions/comments, please let me know!
Hope this helps!
Retrieving data ...