Overview

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

With your ArcGIS Developer account, you can import different file formats (CSV, XLS, GPX, GeoJSON, Shapefiles, etc) to ArcGIS Online and then use them in your apps. This process is called publishing a hosted feature layer and behind every feature layer is a RESTful service that supports spatial queries and editing operations.

In this lab you will learn how to retrieve a layer stored in ArcGIS Online when you know its identifier, item id. You will get the layer item using its identifier and display the layer contents on a map.

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.

Steps

Load a dataset onto a Map

  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 to model a GIS portal from the ArcGIS API for Python.

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

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

    anon_gis = GIS()
    
  5. Access this dataset as an ArcGIS Python API Item object.

    trailheads_itm = anon_gis.content.get(trailheads_id)
    trailheads_itm
    
  6. Load a map of Los Angeles in your notebook at a zoom level of 8 and add the item's layer to the map.

    m1 = anon_gis.map("Los Angeles, CA", 8)
    m1.add_layer(trailheads_itm)
    m1
    

Congratulations, you're done!

Your layer should look something like this: Trailheads.

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 lab and search for interesting open data you could add in another layer in your app.