Select to view content in your preferred language

SpatialDataFrame.from_layer Incorrectly Returns DataFrame for Table

1301
2
07-24-2017 12:26 PM
JoshuaBixby
MVP Esteemed Contributor

Looking at the SpatialDataFrame documentation:

staticfrom_layer(layer, **kwargs)

Returns a SpatialDataFrame from a FeatureLayer or Table object. Inputs:

param layer:FeatureLayer or Table
param gis:GIS object

Returns a SpatialDataFrame

However, I see something different when using a Table object:

>>> tbl_url = # URL to AGOL table
>>> 
>>> tbl = arcgis.features.Table(tbl_url)
>>> type(tbl)
<class 'arcgis.features.layer.Table'>
>>> SDF = SpatialDataFrame.from_layer(tbl)
>>> type(SDF)
<class 'pandas.core.frame.DataFrame'>
>>> ‍‍‍‍‍‍‍‍‍

So, passing a table returns a DataFrame, even though the documentation says a SpatialDataFrame is returned.  Even more interesting are the methods and properties of this "DataFrame":

>>> SDF_attrs = ['copy', 'erase', 'from_featureclass', 'from_hdf', 'from_layer',
                 'geoextent', 'geometry', 'merge_datasets', 'plot', 'reproject',
                 'select_by_location', 'set_geometry', 'to_featureclass',
                 'to_featurelayer', 'to_featureset', 'to_hdf']
>>>
>>> for attr in SDF_attrs:
...     print(attr, hasattr(SDF, attr))
... 
copy True
erase False
from_featureclass False
from_hdf False
from_layer False
geoextent False
geometry False
merge_datasets False
plot True
reproject False
select_by_location False
set_geometry True
to_featureclass False
to_featurelayer False
to_featureset False
to_hdf True
>>> ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I can understand some of these because there is both a pandas DataFrame version and ArcGIS SpatialDataFrame version of the property/method, but why is set_geometry showing up?

0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor

Joshua,

Can you email me the URL you are using? achapkowski@esri.com

Additionally, can you tell me what version you are using? I cannot reproduce your issue.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Andrew, I just sent an e-mail.  I am currently using ArcGIS API for Python 1.4, and a quick check showed the same results.  I temporarily made an AGOL table publicly viewable and sent you the URL.

0 Kudos