bixb0012

SpatialDataFrame.from_layer Incorrectly Returns DataFrame for Table

Discussion created by bixb0012 Champion on Jul 24, 2017
Latest reply on Mar 28, 2018 by bixb0012

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?

Outcomes