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.

Before You Begin

The ArcGIS API for Python DevLabs use Jupyter Notebooks to execute Python code. If you are new to Python, please see the ArcGIS API for Python guide to Using the Jupyter notebook environment.

Complete the Create a new dataset DevLab. You will use the output feature layer to complete this DevLab.


Search for an item and construct a Spatial Data Frame

  1. 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.

  2. Add the following code in a cell to import the ArcGIS API for Python.

    from arcgis.gis import GIS
    from arcgis.features import SpatialDataFrame
  3. Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace username and password with your own credentials.

    gis = GIS("https://www.arcgis.com", "username", "password")
  4. 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"')
  5. Retrieve the feature service item from the list of results. Then, get the layer from that service.

    feature_service_item = feature_service_srch_results[0]
    feature_layer = feature_service_item.layers[0]
  6. Build the Spatial Data Frame!

    sdf = SpatialDataFrame.from_layer(feature_layer)

Congratulations, you're done!

Your notebook should now look something like this.