2

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?

asked Sep 5, 2014 at 2:01

1 Answer 1

4

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)
answered Sep 5, 2014 at 2:01
4
  • 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? Commented Feb 4, 2016 at 23:41
  • It may be better if you ask this as a new question Commented Feb 5, 2016 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 Commented Feb 5, 2016 at 0:19
  • @ErnestoCD yes, to do this put OBJECTID > 0 as the whereclause Commented Feb 5, 2016 at 0:38

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.