I need do a python script to delete all features in a feature service from AGOL, someone know how can i do this?
thanks
Here is a Python sample that allows you to delete rows from a service:
ArcREST/delete_rows_from_service.py at master · Esri/ArcREST · GitHub
Stephen Lead also provided the follow example on Github as well:
<SPAN class="keyword token">import</SPAN> urllib<SPAN class="punctuation token">,</SPAN> urllib2<SPAN class="punctuation token">,</SPAN> json serviceEndPoint <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2F" target="_blank">http://</A><SPAN><server>/ArcGIS/rest/services/<name>/FeatureServer/<ID>/"</SPAN></SPAN> <SPAN class="comment token">#Query the server for the objects to be deleted</SPAN> params <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">'where'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="operator token"><</SPAN>whereclause<SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'returnIdsOnly'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'true'</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN> response <SPAN class="operator token">=</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>serviceEndPoint <SPAN class="operator token">+</SPAN> <SPAN class="string token">"query?"</SPAN><SPAN class="punctuation token">,</SPAN> params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Convert the response into JSON then extract the IDs. Convert to a string</SPAN> data <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN> IDs <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"objectIds"</SPAN><SPAN class="punctuation token">]</SPAN> range <SPAN class="operator token">=</SPAN> <SPAN class="string token">','</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>str<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> IDs<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Build the delete code, and submit it</SPAN> delParams <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">'objectIds'</SPAN><SPAN class="punctuation token">:</SPAN> range<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'json'</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>serviceEndPoint <SPAN class="operator token">+</SPAN> <SPAN class="string token">"deleteFeatures?"</SPAN><SPAN class="punctuation token">,</SPAN> delParams<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.