<?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 Re: ArcGIS API for Python - FeatureSet.save() Error in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599977#M11267</link>
    <description>&lt;P&gt;OK, so we discovered that the code is actually correct, but the backend service has data integrity errors. Which is unfortunate.&amp;nbsp; There is a record that does not have a geometry value, that causes errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ewmahaffey_0-1743089229819.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128841iFC1CEA0D11D9C81F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ewmahaffey_0-1743089229819.png" alt="ewmahaffey_0-1743089229819.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tested a couple of the other layers coming from this service, and found a similar issue. However, I tested layers from&amp;nbsp;&lt;A href="https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_v1/FeatureServer/3" target="_blank"&gt;https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_v1/FeatureServer/3&lt;/A&gt;&amp;nbsp;and it works fine. I hope this helps someone else who might stumble upon this. Maybe the data will get fixed in the "Active_Hurricanes_Sampler" service.&amp;nbsp; For now I just plan to query out the Null records.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Mar 2025 15:34:47 GMT</pubDate>
    <dc:creator>ewmahaffey</dc:creator>
    <dc:date>2025-03-27T15:34:47Z</dc:date>
    <item>
      <title>ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599599#M11258</link>
      <description>&lt;P&gt;I'm trying to use the ArcGIS API for Python without ArcPy. I've written a basic script that connects to a WFS, creates a FeatureLayer, then FeatureSet. I then tried to use the &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureSet.save" target="_self"&gt;FeatureSet.save()&lt;/A&gt;&amp;nbsp;function to simply save the data to a local Shapefile. When I run the script (in the Idle IDE), I get an error saying: "ImportError: ArcPy is required to export a feature class".&amp;nbsp; From a few other threads that I've read, I should be able to run this without ArcPy. Any thoughts?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayer
from arcgis.features import FeatureSet

hurricaneDir = r'C:/Workspace/Temp'
PastTracksURL = 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_Sampler/FeatureServer/3'

feature_layer = FeatureLayer(PastTracksURL)
feature_set = feature_layer.query(out_fields='*')

feature_set.save(hurricaneDir, "PastTracks_Temp_Data.shp")
print ("WFS Data Successfully Saved as a Shapefile")&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

======= RESTART: C:\Workspace\Temp\WFS_to_FeatureClass_forEsriSupport.py =======
Traceback (most recent call last):
  File "C:\Workspace\Temp\WFS_to_FeatureClass_forEsriSupport.py", line 10, in &amp;lt;module&amp;gt;
    feature_set.save(hurricaneDir, "PastTracks_Temp_Data.shp")
  File "C:\Workspace\Python_Virtual_Environment\Lib\site-packages\arcgis\features\feature.py", line 1409, in save
    raise ImportError("ArcPy is required to export a feature class.")
ImportError: ArcPy is required to export a feature class.&lt;/LI-CODE&gt;&lt;P&gt;Results&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 18:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599599#M11258</guid>
      <dc:creator>ewmahaffey</dc:creator>
      <dc:date>2025-03-26T18:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599607#M11259</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/812828"&gt;@ewmahaffey&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may be able to use geopandas to save as a Shapefile is this here is giving you some issues:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayer
from arcgis.features import FeatureSet
import geopandas as gpd
import json

hurricaneDir = r'C:/Workspace/Temp'
PastTracksURL = 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_Sampler/FeatureServer/3'

feature_layer = FeatureLayer(PastTracksURL)
feature_set = feature_layer.query(out_fields='*')

geojson_str = feature_set.to_geojson
gdf = gpd.read_file(json.dumps(json.loads(geojson_str)))

output_shp = hurricaneDir + '/PastTracks_Temp_Data.shp'
gdf.to_file(output_shp)
# Here you may need to_file like this: to_file(output_shp, driver='ESRI Shapefile')

print("WFS Data Successfully Saved as a Shapefile")&lt;/LI-CODE&gt;&lt;P&gt;I haven't used this method in quite a long time, you might need to try a couple different conversions out!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 18:41:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599607#M11259</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-03-26T18:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599631#M11260</link>
      <description>&lt;P&gt;Thanks Cody.&amp;nbsp; I've tried using Pandas GDFs and SDFs but haven't had much luck. One thing I did notice was that this code would work for a WFS that has point data, but not a WFS with polylines&lt;/P&gt;&lt;LI-CODE lang="python"&gt;feature_set.sdf.spatial.to_featureclass(PastTracks_Temp_Output, overwrite=True)&lt;/LI-CODE&gt;&lt;P&gt;I tried running your code sample and got a KeyError&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;KeyError: 'geometry'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 19:33:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599631#M11260</guid>
      <dc:creator>ewmahaffey</dc:creator>
      <dc:date>2025-03-26T19:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599856#M11263</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/812828"&gt;@ewmahaffey&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Give this a whirl. While this works for me, it could be that I have access to ArcPy, so it would be interesting to see if it works in your environment,&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import GeoAccessor
from arcgis.features import FeatureLayer

## the filepath for the output shapefile
hurricane_shp = r'C:/Workspace/Temp/PastTracks_Temp_Data.shp'

## the url to the feature layer
PastTracksURL = 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_Sampler/FeatureServer/3'

## create FeatureLayer object
feature_layer = FeatureLayer(PastTracksURL)

## convert to df
df = GeoAccessor.from_layer(feature_layer)

## export to shapefile
df.spatial.to_featureclass(hurricane_shp)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let us know.&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 09:32:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599856#M11263</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-03-27T09:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599927#M11264</link>
      <description>&lt;P&gt;Thanks Glen. I ran your code in my Python VENV and I'm getting a similar error message that I received when I was testing the use of SDFs and GDFs. It seems like I need to define the geometry type or something.&amp;nbsp; From I can tell it thinks the geometry is in polygon format even though it's polylines, and no results come back. It's so strange&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

= RESTART: C:/Workspace/Temp/WFS_to_FeatureClass_forEsriSupport_wGeoAccessor.py
Traceback (most recent call last):
  File "C:/Workspace/Temp/WFS_to_FeatureClass_forEsriSupport_wGeoAccessor.py", line 17, in &amp;lt;module&amp;gt;
    df.spatial.to_featureclass(hurricane_shp)
  File "C:\Workspace\Python_Virtual_Environment\Lib\site-packages\arcgis\features\geo\_accessor.py", line 2107, in to_featureclass
    result = to_featureclass(
  File "C:\Workspace\Python_Virtual_Environment\Lib\site-packages\arcgis\features\geo\_io\fileops.py", line 1297, in to_featureclass
    res = _pyshp2(df=df, out_path=out_location, out_name=fc_name)
  File "C:\Workspace\Python_Virtual_Environment\Lib\site-packages\arcgis\features\geo\_io\fileops.py", line 1510, in _pyshp2
    if geom.type == "Polygon":
AttributeError: 'NoneType' object has no attribute 'type'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 13:31:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599927#M11264</guid>
      <dc:creator>ewmahaffey</dc:creator>
      <dc:date>2025-03-27T13:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599977#M11267</link>
      <description>&lt;P&gt;OK, so we discovered that the code is actually correct, but the backend service has data integrity errors. Which is unfortunate.&amp;nbsp; There is a record that does not have a geometry value, that causes errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ewmahaffey_0-1743089229819.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128841iFC1CEA0D11D9C81F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ewmahaffey_0-1743089229819.png" alt="ewmahaffey_0-1743089229819.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tested a couple of the other layers coming from this service, and found a similar issue. However, I tested layers from&amp;nbsp;&lt;A href="https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_v1/FeatureServer/3" target="_blank"&gt;https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_v1/FeatureServer/3&lt;/A&gt;&amp;nbsp;and it works fine. I hope this helps someone else who might stumble upon this. Maybe the data will get fixed in the "Active_Hurricanes_Sampler" service.&amp;nbsp; For now I just plan to query out the Null records.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 15:34:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1599977#M11267</guid>
      <dc:creator>ewmahaffey</dc:creator>
      <dc:date>2025-03-27T15:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1600046#M11270</link>
      <description>&lt;P&gt;Although I wasn't able to get the FeatureSet.save() function to work like the &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureSet.save" target="_self"&gt;API Reference guide&lt;/A&gt; said it would.&amp;nbsp; I kept getting the "ImportError: ArcPy is required to export a feature class" error.&amp;nbsp; Here's the final script in case anyone needs it.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayer
from arcgis.features import FeatureSet

## the filepath for the output shapefile
hurricane_shp = r'C:/Workspace/Temp/PastTracks_Temp_Data.shp'

## the url to the feature layer
PastTracksURL = 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_Sampler/FeatureServer/2'
#PastTracksURL = 'https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/Active_Hurricanes_v1/FeatureServer/3'

## create FeatureLayer object
feature_layer = FeatureLayer(PastTracksURL)

df = feature_layer.query(where = "Shape__Length is not null", out_fields = "*", return_geometry=True).sdf
print (df)

## export to shapefile
df.spatial.to_featureclass(hurricane_shp)

print ("Done")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 18:04:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1600046#M11270</guid>
      <dc:creator>ewmahaffey</dc:creator>
      <dc:date>2025-03-27T18:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS API for Python - FeatureSet.save() Error</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1620848#M11430</link>
      <description>&lt;P&gt;curious,....now that you are filtering out the bad geometry, can you go back to the .save method, without pandas .sdf&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl = FeatureLayer(_itemUrl)
features = fl.query(where='Shape is not NULL', out_sr=26911)

# save to disk
print('saving the Feature Layer to Shapefile')
features.save(save_location=_pathShps, out_name=_friendlyName + '.shp')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 15:48:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-api-for-python-featureset-save-error/m-p/1620848#M11430</guid>
      <dc:creator>RDCOGIS</dc:creator>
      <dc:date>2025-06-04T15:48:07Z</dc:date>
    </item>
  </channel>
</rss>

