<?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: pd.DataFrame.spatial.from_featureclass no longer working with selected features in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200620#M7619</link>
    <description>&lt;P&gt;The &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.from_featureclass" target="_self"&gt;arcgis API documentation&lt;/A&gt;&amp;nbsp;shows that &lt;FONT face="courier new,courier"&gt;from_featureclass()&lt;/FONT&gt; has a &lt;FONT face="courier new,courier"&gt;where_clause&lt;/FONT&gt; parameter:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = pd.DataFrame.spatial.from_featureclass(table, where_clause=where)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of running&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SelectLayerByAttribute()&lt;/FONT&gt; and then &lt;FONT face="courier new,courier"&gt;from_featureclass()&lt;/FONT&gt;, I now do it in one step, as shown above&lt;/P&gt;&lt;P&gt;So far, it has worked with the same where clause format, though this use case is admittedly pretty simple. I have no idea if all where clauses are fully compatible across both functions, so you might need to edit your where clause a bit. This seems simpler to just create the dataframe directly with the where clause, rather than calling the GP tool &lt;FONT face="courier new,courier"&gt;SelectLayerByAttribute()&lt;/FONT&gt;. I suspect it's also faster, but most importantly, it doesn't fail!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Aug 2022 23:03:06 GMT</pubDate>
    <dc:creator>davedoesgis</dc:creator>
    <dc:date>2022-08-08T23:03:06Z</dc:date>
    <item>
      <title>pd.DataFrame.spatial.from_featureclass no longer working with selected features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200528#M7615</link>
      <description>&lt;P&gt;I have some previously working code that is now failing. I am fairly certain I was using Pro version 2.5 when I last had it working (arcgis.__version__: 1.8.0, pandas.__version__: 0.25.1, Python: 3.6.9). I am currently in Pro 2.9.1 (arcgis.__version__: 1.9.1, pandas.__version__: 1.2.3, Python: 3.7.11).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; import pandas as pd
&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = "&amp;lt;path_to_fgdb&amp;gt;"
&amp;gt;&amp;gt;&amp;gt; sel_fc = arcpy.management.SelectLayerByAttribute("ACS2020_County",
&amp;gt;&amp;gt;&amp;gt;                 selection_type='NEW_SELECTION', 
&amp;gt;&amp;gt;&amp;gt;                 where_clause="State_FIPS in ('15')")
&amp;gt;&amp;gt;&amp;gt; type(sel_fc)
&amp;lt;class 'arcpy.arcobjects.arcobjects.Result'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; sdf = pd.DataFrame.spatial.from_featureclass(sel_fc)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Pro 2.9.1, it is returning an Exception of type ValueError:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ValueError: filename must be a `str`, `Path`, or `PurePath`, not &amp;lt;class 'arcpy.arcobjects.arcobjects.Result'&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I see 3 work-arounds for this, all sub-optimal:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Save the selection to a feature class (seems like a hassle, might be slow, and requires clean-up later)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Read the entire feature class with pd.DataFrame.spatial.from_featureclass and then do my selection in Pandas. For a trivial example like this, it's fine, but if the selection is more complicated and/or spatial, I wouldn't want to lose the capability to use ArcPy's selection.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Downgrading the versions of modules in my Conda environment -- I really don't want to go down this path...&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Before I go any of these routes, I'm curious if anyone has also seen this behavior and has a way to work with a selection set.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 19:08:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200528#M7615</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-08-08T19:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: pd.DataFrame.spatial.from_featureclass no longer working with selected features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200573#M7616</link>
      <description>&lt;P&gt;Does it make a difference if you use the getOutput function at the end? Right now you are passing a result object and not the resulting layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sel_fc = arcpy.management.SelectLayerByAttribute("ACS2020_County",selection_type='NEW_SELECTION', where_clause="State_FIPS in ('15')").getOutput(0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 20:29:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200573#M7616</guid>
      <dc:creator>dslamb2022</dc:creator>
      <dc:date>2022-08-08T20:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: pd.DataFrame.spatial.from_featureclass no longer working with selected features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200592#M7617</link>
      <description>&lt;P&gt;Thanks, that idea seemed really promising, but I just get a slightly different error message:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ValueError: filename must be a `str`, `Path`, or `PurePath`, not &amp;lt;class 'arcpy._mp.Layer'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 20:53:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200592#M7617</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-08-08T20:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: pd.DataFrame.spatial.from_featureclass no longer working with selected features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200595#M7618</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Side note -&lt;/STRONG&gt; I have always wondered about the return value from these tools. It seems like many ArcPy functions will work directly with the &lt;FONT face="courier new,courier"&gt;Result&lt;/FONT&gt; object, without running &lt;FONT face="courier new,courier"&gt;getOutput&lt;/FONT&gt;. Even in the&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/select-layer-by-attribute.htm" target="_self"&gt;SelectLayerByLocation documentation&lt;/A&gt;, they have this example:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import system modules
import arcpy

# Set the workspace
arcpy.env.workspace = 'c:/data/mexico.gdb'

# Select all cities that overlap the chihuahua polygon
chihuahua_cities = arcpy.management.SelectLayerByLocation('cities', 'INTERSECT', 
                                                          'chihuahua', 0, 
                                                          'NEW_SELECTION')

# Within selected features, further select only those cities with a 
# population &amp;gt; 10,000   
arcpy.management.SelectLayerByAttribute(chihuahua_cities, 'SUBSET_SELECTION', 
                                        '"population" &amp;gt; 10000')

# Write the selected features to a new feature class
arcpy.management.CopyFeatures(chihuahua_cities, 'chihuahua_10000plus')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, the Pandas &lt;FONT face="courier new,courier"&gt;from_featureclass&lt;/FONT&gt; method (which I think is in the &lt;FONT face="courier new,courier"&gt;arcgis&lt;/FONT&gt; API) used to accept the output, and now it does not.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 21:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200595#M7618</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-08-08T21:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: pd.DataFrame.spatial.from_featureclass no longer working with selected features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200620#M7619</link>
      <description>&lt;P&gt;The &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.from_featureclass" target="_self"&gt;arcgis API documentation&lt;/A&gt;&amp;nbsp;shows that &lt;FONT face="courier new,courier"&gt;from_featureclass()&lt;/FONT&gt; has a &lt;FONT face="courier new,courier"&gt;where_clause&lt;/FONT&gt; parameter:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = pd.DataFrame.spatial.from_featureclass(table, where_clause=where)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of running&amp;nbsp;&lt;FONT face="courier new,courier"&gt;SelectLayerByAttribute()&lt;/FONT&gt; and then &lt;FONT face="courier new,courier"&gt;from_featureclass()&lt;/FONT&gt;, I now do it in one step, as shown above&lt;/P&gt;&lt;P&gt;So far, it has worked with the same where clause format, though this use case is admittedly pretty simple. I have no idea if all where clauses are fully compatible across both functions, so you might need to edit your where clause a bit. This seems simpler to just create the dataframe directly with the where clause, rather than calling the GP tool &lt;FONT face="courier new,courier"&gt;SelectLayerByAttribute()&lt;/FONT&gt;. I suspect it's also faster, but most importantly, it doesn't fail!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 23:03:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/pd-dataframe-spatial-from-featureclass-no-longer/m-p/1200620#M7619</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-08-08T23:03:06Z</dc:date>
    </item>
  </channel>
</rss>

