Table of Contents
Introduction
The ArcGIS API for Python is a powerful Python library that allows users to interact with and automate tasks in ArcGIS Online (or Portal). The API is excellent for programmatically creating, maintaining, and updating webmaps in ArcGIS Online. In an earlier post we focused on the first of those – creating! We created a simple and empty webmap in ArcGIS Online with the gray-vector basemap. In this post, we will take a look at listing all the available basemaps for your WebMaps.
At ArcGIS API for Python version 2.4.0 there was a major change with the removal of the WebMap
class and the Map
class taking its place. The code snippets below cater for versions <2.4.0 and for 2.4.0
Geospatial Professionals, GIS Analysts, and enthusiasts will discover the power of automation and script-based operations to efficiently interact and update WebMaps in ArcGIS Online. Throughout this course, you will gain practical, hands-on experience in leveraging the ArcGIS API for Python to perform a wide range of WebMap tasks with ease.
We will dissect WebMaps for all that they are and by the end of this course you will be comfortable with manipulating the JSON, which is the behind the scenes configuration of a WebMap, to produce scripts for workflows where there is currently no API Python method, such as grouping layers.
arcgis modules
The API provides access to your organisations ArcGIS Online via the GIS class in the gis
module. This GIS
class is the gateway to ArcGIS Online.
Versions 2.4.0: We will need to import the Map
class to create a Map
object. The Map
class is a part of the Map
module. This Map module provides components for working with 2D and 3D maps and scenes.
# 2.4.0
## import GIS which provides the gateway entry to your AGOL
from arcgis.gis import GIS
## import WebMap from the mapping module
from arcgis.map import Map
Versions <2.4.0: We will need to import the WebMap
class to create a WebMap
object. The WebMap
class is a part of the mapping
module. This mapping
module provides components for working with 2D and 3D maps and scenes.
# <2.4.0
## import GIS which provides the gateway entry to your AGOL
from arcgis.gis import GIS
## import WebMap from the mapping module
from arcgis.mapping import WebMap
Accessing ArcGIS Online
GIS
class. There are a handful of ways to achieve access, if you are logged into your ArcGIS Online in ArcGIS Pro you can simply use "home"
, otherwise, another common way is to provide the ArcGIS Online URL, followed by your username and password.
# <2.4.0 & 2.4.0
## Access AGOL
agol = GIS("home")
# <2.4.0 & 2.4.0
## Access AGOL
agol = GIS(
url = "https://your_organisation.maps.arcgis.com/",
username = "Your_Username",
password = "Your_Password"
)
The (Web)Map Object basemap Property
basemap
property for the Map
object returns a BasemapManager
object! The BasemapManager allows users to manage the basemap of a webmap. Users can view their basemap options, set the basemap to a new one, and add layers to the basemap. The BasemapManager has a property called basemaps that returns a list of all available basemaps. In the snippet below we iterate over this list and print the name of each basemap to screen.
# 2.4.0
## Print a list of Basemaps available
for basemap_name in WebMap().basemap.basemaps:
print(basemap_name)
Version <2.4.0: We can simply use the WebMap
class and access the basemaps
property. The basemaps
property is a list of all available basemaps. In the code snippet below, we loop through this list and print each to screen.
# <2.4.0
## Print a list of Basemaps available
for basemap_name in WebMap().basemaps:
print(basemap_name)
The Output
Below is an indicative list of the basemaps available. You might have access to some, all, or alternate basemaps. If you go back to our post Create a WebMap in ArcGIS Online using the ArcGIS API for Python, you can substitute gray-vector for an alternate basemap from this list.
dark-gray-vector
gray-vector
hybrid
oceans
osm
satellite
streets-navigation-vector
streets-night-vector
streets-relief-vector
streets-vector
terrain
topo-vector
arcgis-imagery
arcgis-imagery-standard
arcgis-imagery-labels
arcgis-light-gray
arcgis-dark-gray
arcgis-navigation
arcgis-navigation-night
arcgis-streets
arcgis-streets-night
arcgis-streets-relief
arcgis-topographic
arcgis-oceans
osm-standard
osm-standard-relief
osm-streets
osm-streets-relief
osm-light-gray
osm-dark-gray
arcgis-terrain
arcgis-community
arcgis-charted-territory
arcgis-colored-pencil
arcgis-nova
arcgis-modern-antique
arcgis-midcentury
arcgis-newspaper
arcgis-hillshade-light
arcgis-hillshade-dark
arcgis-human-geography
arcgis-human-geography-dark
Unlock the full potential of ArcGIS Online by mastering the art of efficient Content Management with the ArcGIS API for Python. In this comprehensive course, you will embark on a journey to streamline your geospatial workflows, enhance data organization, and maximize the impact of your ArcGIS Online platform.
Geospatial Professionals, GIS Analysts, Data Managers, and enthusiasts will discover the power of automation and script-based operations to efficiently manage content in ArcGIS Online. Throughout this course, you will gain practical, hands-on experience in leveraging the ArcGIS API for Python to perform a wide range of content management tasks with ease.
All the code in one place
Version 2.4.0: You can find the entire code workflow below with links to important components in the documentation that were used.
from arcgis.gis import GIS
from arcgis.map import Map
################################################################################
## API Reference Links:
## https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#gis
## https://developers.arcgis.com/python/latest/api-reference/arcgis.map.toc.html#map
## https://developers.arcgis.com/python/latest/api-reference/arcgis.map.toc.html#arcgis.map.Map.basemap
## https://developers.arcgis.com/python/latest/api-reference/arcgis.map.toc.html#arcgis.map.map_widget.BasemapManager
## https://developers.arcgis.com/python/latest/api-reference/arcgis.map.toc.html#arcgis.map.map_widget.BasemapManager.basemaps
##
## Description:
## Get a list of available Basemaps for your WebMap.
##
## API Version: 2.4.0
##
################################################################################
## Access AGOL
agol = GIS("home")
## Print a list of Basemaps available
for basemap_name in Map().basemap.basemaps:
print(basemap_name)
################################################################################
print("\nSCRIPT COMPLETE")
Version <2.4.0: You can find the entire code workflow below with links to important components in the documentation that were used.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
################################################################################
## API Reference Links:
## https://developers.arcgis.com/python-2-3/api-reference/arcgis.gis.toc.html
## https://developers.arcgis.com/python-2-3/api-reference/arcgis.mapping.toc.html#webmap
## https://developers.arcgis.com/python-2-3/api-reference/arcgis.mapping.toc.html#arcgis.mapping.WebMap.basemaps
##
## Description:
## Get a list of available Basemaps for your WebMap.
##
## API Version: 2.2.0.1, 2.3.0
##
################################################################################
## Access AGOL
agol = GIS("home")
## Print a list of Basemaps available
for basemap_name in WebMap().basemaps:
print(basemap_name)
################################################################################
print("\nSCRIPT COMPLETE")