<?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 Unable to write a featureSet as shapefile (via sdf) in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777084#M992</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I would like to write a shapefile from a featureSet created after .query()&lt;/P&gt;&lt;P&gt;As you can see in the picture I have the featureSet, I cast it as a panda.DataFrame but then supposedly I should be able to&amp;nbsp;use the method&amp;nbsp; to_featureclass following the instructions from here:&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/guide/introduction-to-the-spatial-dataframe/#Saving-Spatial-DataFrames"&gt;https://developers.arcgis.com/python/guide/introduction-to-the-spatial-dataframe/#Saving-Spatial-DataFrames&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But my object does not have this method. I am really confused why it doesn't.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only question similar to mine that I have found is this one:&amp;nbsp;&lt;A _jive_internal="true" href="https://community.esri.com/message/824163-cant-export-spatialdataframe-to-shapefile"&gt;https://community.esri.com/message/824163-cant-export-spatialdataframe-to-shapefile&lt;/A&gt;&amp;nbsp;But I am afraid it didn't help me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for any input.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jul 2019 17:23:03 GMT</pubDate>
    <dc:creator>GretaVega</dc:creator>
    <dc:date>2019-07-03T17:23:03Z</dc:date>
    <item>
      <title>Unable to write a featureSet as shapefile (via sdf)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777084#M992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I would like to write a shapefile from a featureSet created after .query()&lt;/P&gt;&lt;P&gt;As you can see in the picture I have the featureSet, I cast it as a panda.DataFrame but then supposedly I should be able to&amp;nbsp;use the method&amp;nbsp; to_featureclass following the instructions from here:&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/guide/introduction-to-the-spatial-dataframe/#Saving-Spatial-DataFrames"&gt;https://developers.arcgis.com/python/guide/introduction-to-the-spatial-dataframe/#Saving-Spatial-DataFrames&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But my object does not have this method. I am really confused why it doesn't.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only question similar to mine that I have found is this one:&amp;nbsp;&lt;A _jive_internal="true" href="https://community.esri.com/message/824163-cant-export-spatialdataframe-to-shapefile"&gt;https://community.esri.com/message/824163-cant-export-spatialdataframe-to-shapefile&lt;/A&gt;&amp;nbsp;But I am afraid it didn't help me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for any input.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2019 17:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777084#M992</guid>
      <dc:creator>GretaVega</dc:creator>
      <dc:date>2019-07-03T17:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write a featureSet as shapefile (via sdf)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777085#M993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Greta,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may have already figured this out, but it looks like you missed 'spatial' - it should read:&lt;/P&gt;&lt;P&gt;'&lt;SPAN style="font-family: 'courier new', courier, monospace; color: #ff0000;"&gt;xx_sdf.spatial.to_featureclass&lt;/SPAN&gt;'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see this working with the below example script using version 1.6.2 of the API. This particular example maintains the source projection:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; GIS
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;features &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; FeatureLayerCollection&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; GeoAccessor&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; GeoSeriesAccessor
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;geometry &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; SpatialReference
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pandas &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; pd


&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;search_item&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;conn&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; item_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; item_type&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; flc&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    search_results &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; conn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;content&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;search&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;item_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; item_type&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;item_type&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    proper_index &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; s &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; enumerate&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;search_results&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'"'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; item_name &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'"'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    found_item &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; search_results&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;proper_index&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;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; flc &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        get_item &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; conn&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;found_item&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;id&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; get_item
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; flc &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        flc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; FeatureLayerCollection&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fromitem&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;found_item&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; flc
    
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;main&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    conn &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://www.arcgis.com"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Username"&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;
    flc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; search_item&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;conn&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Name_of_Feature_Layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Feature Layer"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; flc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;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;
    epsg_code &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; layer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;properties&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'extent'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'spatialReference'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'latestWkid'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    feature_set &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; layer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;query&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    sdf &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; feature_set&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sdf
    srs &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; SpatialReference&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"wkid"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;epsg_code&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    sdf&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;spatial&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;project&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;srs&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    sdf&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;spatial&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;to_featureclass&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;location&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"/home/test.shp"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'__main__'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    main&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&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;/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;&lt;/P&gt;&lt;P&gt;An alternative approach would be to use the &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;fiona&lt;/SPAN&gt; library instead of sdf to write the shapefile. The equivalent workflow is something like this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Get the EPSG code from the Spatial Reference&amp;nbsp;in the Feature Layer properties (obtained as shown above).&lt;/LI&gt;&lt;LI&gt;Run &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;to_geojson&lt;/SPAN&gt; on the Feature Set.&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Load and op&lt;/SPAN&gt;en the Feature Set geojson with &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;fiona.ogrext.buffer_to_virtual_file&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Write to a new file using the Esri Shapefile driver:&lt;UL&gt;&lt;LI&gt;Here, I set the optional crs parameter equal to the result of Fiona's &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;from_epsg&amp;nbsp;&lt;/SPAN&gt;with the EPSG code from before.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Earl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:44:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777085#M993</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2021-12-12T08:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to write a featureSet as shapefile (via sdf)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777086#M994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Earl,&lt;/P&gt;&lt;P&gt;Apologies for my confusion and thank you so much for your detailed answer it is super useful!&lt;/P&gt;&lt;P&gt;I have managed to export the data.&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;P&gt;Greta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jul 2019 08:55:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-write-a-featureset-as-shapefile-via-sdf/m-p/777086#M994</guid>
      <dc:creator>GretaVega</dc:creator>
      <dc:date>2019-07-04T08:55:31Z</dc:date>
    </item>
  </channel>
</rss>

