Overview

You will learn: how to load a layer from an ArcGIS Online item and add it to a map.

In this tutorial you will learn how to retrieve a layer stored in ArcGIS Online when you know its Item ID. You will get the layer item using its ID and display the layer on a map.

Before you begin

The ArcGIS API for Python tutorials use Jupyter Notebooks to execute Python code. If you are new to this environment, please see the guide to install the API and use notebooks locally.

Steps

Create a new notebook

  1. Go to Esri Juptyter Notebooks 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.

  1. Add the following code to model a GIS portal from the ArcGIS API for Python.

    from arcgis.gis import GIS
    
  2. Create a variable to hold the item ID of the public dataset.

    trailheads_id = '883cedb8c9fe4524b64d47666ed234a7'
    
  3. Create an anonymous connection to ArcGIS Online to retrieve this public data.

    gis = GIS()
    
  4. Access this dataset as an ArcGIS Python API Item object.

    trailheads_item = gis.content.get(trailheads_id)
    trailheads_item
    
  5. Create a map and add the new layer.

    m = gis.map()
    m.add_layer(trailheads_item)
    
  6. Display the map in your Juptyer notebook.

    m
    
  7. Set the zoom level and center point of the map.

    m.center = [34.09042, -118.71511]           # `[latitude, longitude]`
    m.zoom = 11
    

Congratulations, you're done!

Your layer should look something like this Trailheads Feature Layer.

Challenge

Use your portal item

Search for the Parks and Open Space and Trails layers and retrieve their item id values. Use those values to obtain the item and draw each layer on a map.

Discover data

If you have not already done so, visit the Discover data tutorial and search for interesting open data you could add as another layer to your map.