What BaseMaps are Available for my WebMaps in ArcGIS Online using the ArcGIS API for Python?

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 will focus 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.

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. We will need to import the WebMap class to access the basemap property which holds the key to the list of basemaps available. The WebMap class is a part of the mapping module. This mapping module provides components for working with 2D and 3D maps and scenes, and also includes classes for map layers such as the MapFeatureLayer, MapImageLayer, and VectorTileLayer.
				
					## 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

Our first port of call is to access your ArcGIS Online via the 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.
				
					## Access AGOL
agol = GIS("home")
				
			
				
					## Access AGOL
agol = GIS(
    url = "https://your_organisation.maps.arcgis.com/",
    username = "Your_Username",
    password = "Your_Password"
)
				
			

The WebMap Object basemap Property

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.
				
					## 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

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/api-reference/arcgis.gis.toc.html
##  https://developers.arcgis.com/python/api-reference/arcgis.mapping.toc.html#webmap
##  https://developers.arcgis.com/python/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
##
################################################################################

## Access AGOL
agol = GIS("home")

## Print a list of Basemaps available
for basemap_name in WebMap().basemaps:
    print(basemap_name)

################################################################################
print("\nSCRIPT COMPLETE")


				
			

Leave a Comment

Your email address will not be published. Required fields are marked *