Learn how to use an item
You can host a variety of geographic data and other resources using ArcGIS Online
In this tutorial, you will add a hosted feature layer to display trailheads in the Santa Monica Mountains of Southern California. The hosted layer defines the trailhead locations (points) as well as the symbols used to display them.
Prerequisites
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
Import modules and log in
-
Import the
arcgis.gismodule. This module is the entry point into the GIS and provides the functionality to manage GIS contentContent is a collection of items in a portal that belong to a user, group, or organization. , users, and groups.Use dark colors for code blocks from arcgis.gis import GIS -
Log in anonymously to access publicly shared content. The data used in this tutorial is public so you do not need credentials to access it. If it were private data, you would be required to provide authentication.
Use dark colors for code blocks from arcgis.gis import GIS gis = GIS()
Access the item by ID
-
Create a variable to hold the item ID
An item ID is a unique identifier representing a single item stored, managed, and accessed in a portal, such as a web map, hosted layer, or file. of the public dataset. An item hosted in ArcGIS has a unique item ID attribute that can be referenced. For example, the item ID for this feature layer is:Use dark colors for code blocks gis = GIS() trailheads_id = "2e4b3df6ba4b44969a3bc9827de746b3" -
Use the
contentproperty on theGISclass, passing in thetrailheadsvariable to return an_id itemobject.Use dark colors for code blocks trailheads_id = "2e4b3df6ba4b44969a3bc9827de746b3" trailheads_item = gis.content.get(trailheads_id) trailheads_item
Display the item on a map
-
Create a map widget instance by calling the
mapmethod. Pass the item object to theaddmethod to display the layer._layer Use dark colors for code blocks trailheads_item = gis.content.get(trailheads_id) trailheads_item m = gis.map() m.add_layer(trailheads_item) m -
Use the
centerandzoommethods to set the display extent of the map.Use dark colors for code blocks m = gis.map() m.add_layer(trailheads_item) m m.center = [34.09042, -118.71511] # [latitude, longitude] m.zoom = 11
Your map should display the locations of trailheads in the Santa Monica Mountains.
Optional: Export the map widget
- Create a standalone HTML page that can be shared and rendered in a web browser.
Use dark colors for code blocks from os import path, getcwd export_dir = path.join(getcwd(), "home") if not path.isdir(export_dir): os.mkdir(export_dir) export_path = path.join(export_dir, "add-a-layer-from-an-item.html") m.export_to_html(export_path, title="Add a layer from an item")
What's next?
Learn how to use additional functionality in these tutorials:

Display a web map
Search ArcGIS Online for an existing web map and display it.

Query a feature layer (spatial)
Learn how to execute a spatial query to access polygon features from feature services.

Query a feature layer (SQL)
Learn how to execute a SQL query to access polygon features from feature services.