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
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
-
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– Ernesto CD2016年02月04日 23:41:17 +00:00Commented Feb 4, 2016 at 23:41
-
It may be better if you ask this as a new question2016年02月05日 00:11:35 +00:00Commented 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 Reviewalphabetasoup– alphabetasoup2016年02月05日 00:19:16 +00:00Commented Feb 5, 2016 at 0:19
-
@ErnestoCD yes, to do this put
OBJECTID > 0
as thewhereclause
Stephen Lead– Stephen Lead2016年02月05日 00:38:36 +00:00Commented Feb 5, 2016 at 0:38
Explore related questions
See similar questions with these tags.
lang-py