Select to view content in your preferred language

Delete features from featureservice

8009
6
06-22-2015 08:21 AM
ChristianSailer
New Contributor

Hello

I have collected > 100k features in a hosted feature service (Service definition with 1000 records) and like to delete the features from time to time.

Doing manually, ArcMap allows downloading only 1000 features by time (Service definition with 1000 records), REST (with the WHERE-query 1=1) doesn't work. I get a weird, cryptical answer form the server.

Has anybody experience and a solution?

Thx!

Chris

Tags (2)
0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Christian,

You can use the deleteFeatures with your REST URL.  Ex:

http://services.arcgis.com/BJUji5ArUSDM/ArcGIS/rest/services/Parcels/FeatureServer/0/deleteFeatures

If you want to download the feature class, perform the delete, and then overwrite the hosted feature service take a look at the following tool:

http://epro.maps.arcgis.com/home/item.html?id=16e5cc64178941839eca62837f168ec9

ChristianSailer2
Occasional Contributor

Hi Jake

Thank for your quick reply.

In my case deleteFeatures with your REST URL works for around 2'000 features... but not for 95'000...

Using your script in ArcGIS 10.2.2 results in error message;

Failed script DownloadService...

Traceback (most recent call last):

  File "C:\Users\csailer\Downloads\Export_Feature_Service\Download Service with Attachments.py", line 92, in <module>

    fs.load(fsURL)

  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\arcobjects\arcobjects.py", line 173, in load

    return convertArcObjectToPythonObject(self._arc_object.Load(*gp_fixargs(args)))

RuntimeError: RecordSetObject: Cannot open table for Load

Failed to execute (DownloadService).

However, you have mentioned overwriting the hosted fs with your script?

Thank you!

Christian

0 Kudos
ChristianSailer2
Occasional Contributor

Hi Jake

again me. I tried to do some workaroudn. I can delete stepwise features (each time 1000) of my 95'000 fs. services. THE question is why I cannot delete more than ~2000 features from hosted fs per request?

Is ArcGIS Online limiting this request due to server traffic? Why I'm not able to leave a sql statement like;

DELETE FROM table_name;

or

DELETE * FROM table_name;

Thx

Christian

0 Kudos
JakeSkinner
Esri Esteemed Contributor

I'm not sure the max amount of features you can delete at once for an ArcGIS Online Hosted Feature Service.  One thing you could do is use a pythons script to delete features 1000 at a time.  Ex:

import urllib, urllib2, json, smtplib

username = "user"
password = "password"

tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']

x = 1000

while x <= 95000:
    url = 'http://services.arcgis.com/Fz6ji5ArUSDM/ArcGIS/rest/services/Parcels/FeatureServer/0/deleteFeatures'
    where = "OBJECTID <= " + str(x)
    params = {'f': 'pjson', 'where': where, 'token': token}
    req = urllib2.Request(url, urllib.urlencode(params))
    response = urllib2.urlopen(req)
    x += 1000
ChristianSailer2
Occasional Contributor

Hi Jake

Thank you this workaround works!

Christian

0 Kudos
RossCBrewer
New Contributor III

I successfully deleted over 100,000 records from a hosted feature layer using the REST Delete Features tool by way of putting 1=1 in the where clause (and nothing in the Object ID field), BUT I did this in my organization's Portal 10.7.1 environment; so, ArcGIS Online might limit how many can be deleted due to cloud resource usage...

*I'm also posting to thank Chris for the 1=1 in where syntax help!

0 Kudos