Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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