You will learn: how to use the ArcGIS API for Python to load a spatial data frame from a feature layer.
Data frames are a common data structure for data scientists. This lab demonstrates how to load a spatial data frame, a data frame extended for spatial operations, from a feature layer. The resulting spatial data frame can be used for visualization, to perform analysis, or to integrate with third party libraries.
Complete the Create a new dataset DevLab. You will use the output feature layer to complete this DevLab.
Go to the Esri Jupyter Notebook and click New > Python 3 to create a new notebook.
In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.
Add the following code in a cell to import the ArcGIS API for Python.
from arcgis.gis import GIS from arcgis.features import SpatialDataFrame
Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace
password with your own credentials.
gis = GIS("https://www.arcgis.com", "username", "password")
Search for the Griffith Park Access layer created in the Create a new dataset DevLab.
feature_service_srch_results = gis.content.search(query='title: "Griffith*" AND type: "Feature Service"') feature_service_srch_results
Retrieve the feature service item from the list of results. Then, get the layer from that service.
feature_service_item = feature_service_srch_results feature_layer = feature_service_item.layers feature_layer
Build the Spatial Data Frame!
sdf = SpatialDataFrame.from_layer(feature_layer) sdf.head()
Your notebook should now look something like this.