<?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: Query and save an empty feature layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1361955#M9424</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86115"&gt;@JillianStanford&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using ArcPy&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

## url to the feature layer
fl = "https://services-eu1.arcgis.com/*******/arcgis/rest/services/County_Boundaries/FeatureServer/0"

## file geodatabase path
## NOTE you can use arcpy to create a geodatabase rather than having an existing
gdb = r"C:\Path\to\Documents\fgdb.gdb"

## path for saving output feature class
out_fc = "{0}\\exported_layer".format(gdb)

## create feature class from feature layer
## you can also use FeatureClassToFeatureClass in older versions of ArcGIS Pro
arcpy.conversion.ExportFeatures(fl, out_fc)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example above I have hardcoded the url but you could replace with the below.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl = feature_layer_item.layers[0].url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also change the hardcoded "exported_layer" name to be the name of the layer you are exporting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2023 11:24:29 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2023-12-18T11:24:29Z</dc:date>
    <item>
      <title>Query and save an empty feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1360970#M9418</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am using ArcGIS for Python to save some sub layers in a hosted feature service to a feature geodatabase.&lt;/P&gt;&lt;P&gt;My code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;feature_layer_item = gis.content.get("xxxxxxxxxxxxxxx")
layer = feature_layer_item.layers[0]                  
featureSet = layer.query()
featureSet.save(arcpy.env.workspace, "MyLayer")  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works perfectly except when there are no features in the layer. If that's the case then the save function creates a table in the fgdb instead of an empty polygon feature class. If I add a bogus record to the layer and execute the same tool, a polygon feature class is created.&lt;/P&gt;&lt;P&gt;Has anyone encountered this? I assume it's because the query returns an empty feature set. I have tried setting the spatial_reference and geometry_type on the feature set, which looks like it should be possible but no luck.&lt;/P&gt;&lt;P&gt;Anybody have a workaround?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Jill&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 17:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1360970#M9418</guid>
      <dc:creator>JillianStanford</dc:creator>
      <dc:date>2023-12-14T17:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Query and save an empty feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1361955#M9424</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86115"&gt;@JillianStanford&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using ArcPy&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

## url to the feature layer
fl = "https://services-eu1.arcgis.com/*******/arcgis/rest/services/County_Boundaries/FeatureServer/0"

## file geodatabase path
## NOTE you can use arcpy to create a geodatabase rather than having an existing
gdb = r"C:\Path\to\Documents\fgdb.gdb"

## path for saving output feature class
out_fc = "{0}\\exported_layer".format(gdb)

## create feature class from feature layer
## you can also use FeatureClassToFeatureClass in older versions of ArcGIS Pro
arcpy.conversion.ExportFeatures(fl, out_fc)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example above I have hardcoded the url but you could replace with the below.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl = feature_layer_item.layers[0].url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also change the hardcoded "exported_layer" name to be the name of the layer you are exporting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 11:24:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1361955#M9424</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-12-18T11:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Query and save an empty feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1362129#M9427</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;That worked perfectly.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Jill&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 18:03:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-and-save-an-empty-feature-layer/m-p/1362129#M9427</guid>
      <dc:creator>JillianStanford</dc:creator>
      <dc:date>2023-12-18T18:03:11Z</dc:date>
    </item>
  </channel>
</rss>

