<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Query and deleting feature in a AGOL layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-deleting-feature-in-a-agol-layer/m-p/821613#M2825</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to query and export features to a CSV file from an AGOl layer, and then have these features deleted from the layer aftwerwards: My code goes as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcgis&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;gis = GIS("https://arcgis.com", "User", "Password")&lt;BR /&gt;from arcgis.gis import *&lt;BR /&gt;import os&lt;BR /&gt;icy_conditions = gis.content.get('a6be839d462d4441802abad0728cc857')&lt;BR /&gt;icy_layers = icy_conditions.layers&lt;BR /&gt;icy_reports = icy_layers[0]&lt;BR /&gt;Status_query = icy_reports.query(where="Status='Cleared'")&lt;BR /&gt;output_file = icy_conditions.export(title=icy_reports,export_format="CSV",parameters=Status_query)&lt;BR /&gt;output_file.download(r'\\vm-gis-catalog\Web_GIS\AGOL\IceReporting\Archived_Reports')&lt;BR /&gt;if icy_reports.query(Status_query):&lt;BR /&gt; icy_reports.delete_features()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script will run and export the features, but it does not select the records I want, it just exports all records in the layer. Can anyone help with regards to the export function and how you can incorporate querying a layer into this function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Feb 2019 00:29:45 GMT</pubDate>
    <dc:creator>GregThistle</dc:creator>
    <dc:date>2019-02-27T00:29:45Z</dc:date>
    <item>
      <title>Query and deleting feature in a AGOL layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-deleting-feature-in-a-agol-layer/m-p/821613#M2825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to query and export features to a CSV file from an AGOl layer, and then have these features deleted from the layer aftwerwards: My code goes as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcgis&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;gis = GIS("https://arcgis.com", "User", "Password")&lt;BR /&gt;from arcgis.gis import *&lt;BR /&gt;import os&lt;BR /&gt;icy_conditions = gis.content.get('a6be839d462d4441802abad0728cc857')&lt;BR /&gt;icy_layers = icy_conditions.layers&lt;BR /&gt;icy_reports = icy_layers[0]&lt;BR /&gt;Status_query = icy_reports.query(where="Status='Cleared'")&lt;BR /&gt;output_file = icy_conditions.export(title=icy_reports,export_format="CSV",parameters=Status_query)&lt;BR /&gt;output_file.download(r'\\vm-gis-catalog\Web_GIS\AGOL\IceReporting\Archived_Reports')&lt;BR /&gt;if icy_reports.query(Status_query):&lt;BR /&gt; icy_reports.delete_features()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script will run and export the features, but it does not select the records I want, it just exports all records in the layer. Can anyone help with regards to the export function and how you can incorporate querying a layer into this function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Feb 2019 00:29:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-deleting-feature-in-a-agol-layer/m-p/821613#M2825</guid>
      <dc:creator>GregThistle</dc:creator>
      <dc:date>2019-02-27T00:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Query and deleting feature in a AGOL layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-deleting-feature-in-a-agol-layer/m-p/821614#M2826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are multiple ways to do it. You can create a replica or do a query then use pandas dataframe to export the result to a CSV file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try if the following code works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcgis
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;gis &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; GIS
gis &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; GIS&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"https://arcgis.com"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"User"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Password"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;gis &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os
icy_conditions &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; gis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;content&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'a6be839d462d4441802abad0728cc857'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
icy_layers &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; icy_conditions&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;layers
icy_reports &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; icy_layers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
Status_query &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; icy_reports&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;query&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;where&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Status='Cleared'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# use pandas dataframe to export the data into csv&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# you have chance to reshape your data, for example, which fields to be exported&lt;/SPAN&gt;
sdf_temp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Status_query&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sdf

&lt;SPAN class="comment token"&gt;# specify the fields you want to export if needed&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#refined_sdf = sdf_temp[["field1","fields",...]]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# save to a csv file in a particular folder&lt;/SPAN&gt;
sdf_temp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;to_csv&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;'c:\temp\xyz.csv'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# delete features permantly, use with great causion!!&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#icy_reports.delete_features(where="Status='Cleared'")&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;delete_features function is very powerful, but very dangerous. make sure you backup your data before deleting any records, here is the doc:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html?highlight=create%20replica#arcgis.features.FeatureLayer.delete_features" title="https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html?highlight=create%20replica#arcgis.features.FeatureLayer.delete_features" rel="nofollow noopener noreferrer" target="_blank"&gt;arcgis.features module — arcgis 1.5.3 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:45:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-deleting-feature-in-a-agol-layer/m-p/821614#M2826</guid>
      <dc:creator>simoxu</dc:creator>
      <dc:date>2021-12-12T09:45:30Z</dc:date>
    </item>
  </channel>
</rss>

