0

I'm struggling to build a dataframe out of a featureclass (via a layer), where I'm getting this error message:

Exception: Could not load the dataset: 'Layer' object has no attribute 'filter'

from this code:

from arcgis.features import GeoAccessor, GeoSeriesAccessor
from arcgis.gis import GIS
import pandas as pd
import arcpy

aprx = arcpy.mp.ArcGISProject('C:/....../MyProject.aprx'))
project_map = aprx.listMaps("NiftyMap")[0]
lyr = project_map.listLayers("MyLayer")[0]
sdf = pd.DataFrame.spatial.from_layer(lyr)


Exception: Could not load the dataset: 'Layer' object has no attribute 'filter'

I can't see what the issue is?

1 Answer 1

0

The wrong GeoAccessor method is being called to load the data set. From GeoAccessor - ArcGIS API for Python:

static from_layer(layer)¶

The from_layer method imports a FeatureLayer to a Spatially Enabled DataFrame

The from_layer method wants a data set, specifically a FeatureLayer. What is being passed in the current code is an ArcPy Mapping Layer (arcpy.mp.Layer), which isn't a data set but an object holding a reference to a data set. If the data set referenced in the ArcPy layer is a FeatureLayer, then the current code works; however, if the data set referenced in the ArcPy layer is a feature class, then the code needs to be changed:

from arcgis.features import GeoAccessor, GeoSeriesAccessor
from arcgis.gis import GIS
import pandas as pd
import arcpy

aprx = arcpy.mp.ArcGISProject('C:/....../MyProject.aprx'))
project_map = aprx.listMaps("NiftyMap")[0]
lyr = project_map.listLayers("MyLayer")[0]
sdf = pd.DataFrame.spatial.from_featureclass(lyr)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.