Overview

You will learn: how to use the ArcGIS API for Python to load a web scene for display.

A web scene is a JSON structure that contains the settings required to display a 3D map. ArcGIS and custom applications can load web scenes and automatically configure the map extent, camera, basemap, layers and styles, labels and more. Web scenes can be created interactively with the Scene Viewer and ArcGIS Pro. Web scenes are stored in ArcGIS Online or ArcGIS Enterprise as an item with a unique ID.

In this tutorial you will search ArcGIS Online for an existing web scene and display it.

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. Import the GIS module.

    from arcgis.gis import GIS
    
  2. Make an anonymous connection to ArcGIS Online.

    gis = GIS()
    

Display a web scene with the ArcGIS API for Python

  1. Search for a publicly available web scene owned by esri_devlabs containing datasets about Los Angeles, CA trails.

    webscene_search = gis.content.search(query = "LA Trails *", item_type = "Web Scene")
    webscene_search
    
  2. Retrieve the web scene item from the resulting list.

    webscene_item = webscene_search[0]
    webscene_item
    
  3. Import the WebScene class from the arcgis.mapping module and visualize the web scene.

    from arcgis.mapping import WebScene
    
    la_trails = WebScene(webscene_item)
    la_trails
    

Congratulations, you're done!

Your scene and layers (feature services) should look something like this.

Challenge

Explore Web Scenes with the REST API

All hosted feature layers have a REST endpoint that you can use to access the data directly. This can be accomplished with a URL request from a web browser, a custom application, or the ArcGIS APIs.

Let's retrieve the layers from the web scene. You can query the web scene as a dictionary.

  1. operational_layers = la_trails['operationalLayers']
    n = len(operational_layers)
    print("The web scene has {} layers.".format(n))
    
  2. Query the list for the title and url values of each layer.

    for layer in operational_layers:
        print("{}\n\t{}".format(layer['title'], layer['url']))
    
  3. In your browser, add the url for the Trails layer to the browser (or just copy/paste from below) to explore the REST endpoint:

    https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0
    
  4. Explore the other layers through the same steps.

To learn more about querying data with the REST API, see the Query a feature layer tutorial.