Select to view content in your preferred language

Python API: TypeError on geometry column for Spatial DataFrame of local data source

1738
5
03-27-2018 07:49 AM
by Anonymous User
Not applicable

At the DevSummit, I learned that you could load a feature class from a local source into a Spatial DataFrame using the ArcGIS API for Python. Specifically, the documentation implies this can be done using the from_featureclass() method in the features module to create a Spatial DataFrame. I followed the example in this notebook for loading a local shapefile into a Spatial DataFrame (sdf).

I am using Jupyter Notebook as my IDE. My environment is the default arcgispro-py3 environment from ArcGIS Pro. I know I am able to successfully create a Spatial DataFrame objectbecause when I run the object through the type() function in my Jupyter Notebook I get the following:

arcgis.features._data.geodataset.geodataframe.SpatialDataFrame‍‍

I am able to return  sdf.head() and sdf.describe() without issue.

However, if I run sdf.info() I get the following error:

I have tried this on point, line and multipolygon shapefiles, and file GDB feature classes. All locally loaded data eventually returns this error. I am able to successfully create Spatial DataFrames from AGOL data and do not receive the error above when running sdf.info().

The documentation and examples I've been able to find about properly loading local data into a Spatial DataFrame seems pretty scattered and undeveloped at the moment. Looking at this error and the process I've described, does anyone have any suggestions on how I might troubleshoot this further? Thanks!

0 Kudos
5 Replies
JoshuaBixby
MVP Esteemed Contributor

There must be a bug with the info() method.  I get an error when using ArcGIS API for Python 1.4 and a FGDB feature class, but the error is different than yours:

In[1]: from arcgis.features import SpatialDataFrame
In[2]: sdf = SpatialDataFrame.from_featureclass(r'D:\Default.gdb\rangerdistrict')

In[3]: sdf.head()
Out[3]: 
   OBJECTID ADMINISTRATIVEUNITID    GIS_ACRES  SUBTYPE_ADMINUNIT  \
0         1       99090906010343  1034747.229                  3   
1         2       99090901010343   751074.231                  3   
2         3       99090902010343   645092.789                  3   
3         4       99090905010343   718352.206                  3   
4         5       99090907010343   739293.634                  3   

        MODIFIED_DATE                       LAST_UPDATE STD_ADMINUNIT_FK  \
0 2012-11-21 20:27:01  D6A68001115E2DD6E04400144F6A461C   99090906010343   
1 2012-10-23 20:12:35  D6A6800111582DD6E04400144F6A461C   99090901010343   
2 2018-01-01 00:00:00  D6A68001115A2DD6E04400144F6A461C   99090902010343   
3                 NaT  D6A68001115C2DD6E04400144F6A461C   99090905010343   
4                 NaT  D6A6800111602DD6E04400144F6A461C   99090907010343   

   PROJECTED_ACRES                    UNITNAME  \
0      1035050.403     Lacroix Ranger District   
1       751068.672  Laurentian Ranger District   
2       645092.875    Gunflint Ranger District   
3       718380.285   Kawishiwi Ranger District   
4       739307.990       Tofte Ranger District   

                                               SHAPE  
0  {'rings': [[[-93.18671221699998, 48.6278650500...  
1  {'rings': [[[-91.90858970199997, 47.6436073560...  
2  {'rings': [[[-90.87772452699994, 48.2389176710...  
3  {'rings': [[[-91.16214670599999, 48.1362494970...  
4  {'rings': [[[-91.08318138799996, 48.0494390910...  

In[4]: sdf.describe()
Out[4]: 
       OBJECTID     GIS_ACRES  SUBTYPE_ADMINUNIT  PROJECTED_ACRES
count  5.000000  5.000000e+00                5.0     5.000000e+00
mean   3.000000  7.777120e+05                3.0     7.777800e+05
std    1.581139  1.494691e+05                0.0     1.495960e+05
min    1.000000  6.450928e+05                3.0     6.450929e+05
25%    2.000000  7.183522e+05                3.0     7.183803e+05
50%    3.000000  7.392936e+05                3.0     7.393080e+05
75%    4.000000  7.510742e+05                3.0     7.510687e+05
max    5.000000  1.034747e+06                3.0     1.035050e+06

In[5]: sdf.info()
Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-faf896058227>", line 1, in <module>
    sdf.info()
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\frame.py", line 1845, in info
    _verbose_repr()
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\frame.py", line 1809, in _verbose_repr
    counts = self.count()
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\frame.py", line 5645, in count
    result = notna(frame).sum(axis=axis)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\dtypes\missing.py", line 212, in notna
    res = isna(obj)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\dtypes\missing.py", line 45, in isna
    return _isna(obj)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\pandas\core\dtypes\missing.py", line 60, in _isna_new
    return obj._constructor(obj._data.isna(func=isna))
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\_data\geodataset\geodataframe.py", line 241, in __init__
    geometry = [_types.Geometry(g) for g in self['SHAPE'].tolist()]
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\_data\geodataset\geodataframe.py", line 241, in <listcomp>
    geometry = [_types.Geometry(g) for g in self['SHAPE'].tolist()]
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geometry\_types.py", line 137, in __call__
    if len(iterable) > 0:
TypeError: object of type 'bool' has no len()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
by Anonymous User
Not applicable

Thanks for checking this. I just generated this error from a layer loaded from AGOL using an environment with version 1.4 of the Python API. Frustrating 😕

0 Kudos
JustinPierre
Esri Contributor

I see the same behaviour.

It's solved by commenting out the check at lines 605 and 606 in the geodataframe.py file. So I suspect the geometry column in file geodatabases isn't being identified correctly.

I'm looking at the geometry that gets passed to set_geometry in that file to see if there's a way to correct it.

When you create the SpatialDataFrame from an object on AGOL and run .info() it doesn't pass through this geometry check at all.

by Anonymous User
Not applicable

I'll give this a try. I was going to include a piece about Spatial DataFrames in a presentation to colleagues this week, but I'm going to have to pass until this portion of the API is more reliable.

0 Kudos
RohitSingh2
Esri Contributor

Thank you for reporting this issue. We will investigate it and work on a fix.