How can I use python to delete records from a table, or features from a featureclass, when they are stored in ArcGIS Server?

using REST "delete features" in arcgis api for javascript shows how to do this in JavaScript - what is the Python syntax?


I couldn't find this syntax listed anywhere so I'm sharing it in case it helps someone else.

import urllib, urllib2, json

serviceEndPoint = "http://<server>/ArcGIS/rest/services/<name>/FeatureServer/<ID>/"

#Query the server for the objects to be deleted
params = urllib.urlencode({'where': <whereclause>, 'f': 'json', 'returnIdsOnly': 'true'})
response = urllib2.urlopen(serviceEndPoint + "query?", params).read()

#Convert the response into JSON then extract the IDs. Convert to a string
data = json.loads(response)
IDs = data["objectIds"]
range = ','.join([str(x) for x in IDs])

#Build the delete code, and submit it
delParams = urllib.urlencode({'objectIds': range, 'f': 'json'})
urllib2.urlopen(serviceEndPoint + "deleteFeatures?", delParams)
  • Is the <whereclause> the only piece of the script that I need to modify to make this work? Lets say that I need to delete all the features, can I say objectIds>0? Is there any other other part that I need to modify?
    – Ernesto CD
    Feb 4 '16 at 23:41
  • It may be better if you ask this as a new question
    – Midavalo
    Feb 5 '16 at 0:11
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review Feb 5 '16 at 0:19
  • @ErnestoCD yes, to do this put OBJECTID > 0 as the whereclause Feb 5 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.