arcgis.mapping module

The arcgis.mapping module contains classes and functions to represent and interact with web maps, scenes, and certain layer types such as map image and vector tiles. In this page we will observe how to visualize maps, scenes and layers using the map widget in Jupyter notebook environment.

Using the map widget

The GIS object includes a map widget for displaying geographic locations, visualizing GIS content, as well as the results of your analysis. To use the map widget, call gis.map() and assign it to a variable, that you can then query to bring up the widget in the notebook:

In [ ]:
import arcgis
from arcgis.gis import GIS
# Create a GIS object, as an anonymous user for this example
gis = GIS()
In [ ]:
# Create a map widget
map1 = gis.map('Paris') # Passing a place name to the constructor
                        # will initialize the extent of the map.
map1

paris map

The map widget has several properties that you can query and set, such as its zoom level, basemap, height, etc:

In [ ]:
map1.zoom
Out[ ]:
2

Assigning a value to the zoom property will update the widget.

In [ ]:
map1.zoom = 10

Let us query the basemap property of the widget

In [ ]:
map1.basemap
Out[ ]:
'topo'

Your notebook can have as many of these widgets as you wish. Let us create another map widget and modify some of its properties.

In [ ]:
map2 = gis.map() # creating a map object with default parameters
map2

topo map of New York

Assigning a basemap of your choice to the basemap property will update the widget.

In [ ]:
map2.basemap = 'streets' # more about this in the next section of the sample

You can make the widget bigger or smaller by modifying the height property.

In [ ]:
map2.height = '200px'

The center property reveals the coordinates of the center of the map.

In [ ]:
map2.center
Out[ ]:
[0, 0]

If you know the latitude and longitude of your place of interest, you can assign it to the center property.

In [ ]:
map2.center = [34,-118] # here we are setting the map's center to Los Angeles

You can use geocoding to get the coordinates of place names and drive the widget. Geocoding convert place names to coordinates and can be used using arcgis.geocoding.geocode() function.

Let us geocode Times Square, NY and set the map's extent to the geocoded location's extent.

In [ ]:
location = arcgis.geocoding.geocode('Times Square, NY', max_locations=1)[0]
map2.extent = location['extent']

Basemaps

ArcGIS Online includes several basemaps from Esri that you can use in your maps. Let us list them.

In [ ]:
from IPython.display import display

#basemaps are of type Web Map
basemaps = gis.content.search("tags:esri_basemap AND owner:esri", item_type = "web map")
for basemap in basemaps:
    display(basemap)
Streets
Presents highway-level data for the world and street-level data for North America, Europe and more.Web Map by esri
Last Modified: November 04, 2016
0 comments, 2,429,857 views
Topographic
Topographic map which includes boundaries, cities, water features, physiographic features, parks, landmarks, transportation, and buildings.Web Map by esri
Last Modified: November 04, 2016
3 comments, 1,345,442 views
Imagery with Labels
Satellite and high-resolution aerial imagery for the world with political boundaries and place names. You can turn on transportation including street names.Web Map by esri
Last Modified: November 04, 2016
2 comments, 1,270,589 views
Terrain with Labels
Basemap features shaded relief, bathymetry and coastal water features that provide neutral background with political boundaries and placenames.Web Map by esri
Last Modified: November 04, 2016
0 comments, 1,090,005 views
Imagery Hybrid
Satellite and high-resolution aerial imagery for the world with political boundaries, roads, and labels for places and roads.Web Map by esri
Last Modified: November 04, 2016
0 comments, 448,225 views
Light Gray Canvas
This web map draws attention to your thematic content by providing a neutral background with minimal colors, labels, and features.Web Map by esri
Last Modified: November 23, 2016
44 comments, 379,662 views
National Geographic Map
This map is designed to be used as a general reference map for informational and educational purposes as well as a basemap by GIS professionals and other users for creating web maps and web mapping applications.Web Map by esri
Last Modified: November 04, 2016
4 comments, 347,444 views
Imagery with Labels and Transportation
Satellite and high-resolution aerial imagery for the world with political boundaries, roads, and labels for places and roads.Web Map by esri
Last Modified: November 04, 2016
2 comments, 315,676 views
Shaded Relief with Labels
Displays surface elevation as shaded relief with political boundaries and placenames.Web Map by esri
Last Modified: November 04, 2016
0 comments, 298,052 views
Ocean Basemap
The Ocean Basemap includes bathymetry, surface and subsurface feature names, and derived depths.  This map is designed to be used as a basemap by marine GIS professionals and as a reference map by anyone interested in ocean data.Web Map by esri
Last Modified: November 04, 2016
6 comments, 224,339 views

When a map widget is created as seen in the samples above, a number of Esri basemaps are included with widget. You can list them using the basemaps property.

In [ ]:
# Let us create another map widget for this part of the sample
map3 = gis.map('New York')
In [ ]:
map3.basemaps
Out[ ]:
['streets',
 'satellite',
 'hybrid',
 'topo',
 'gray',
 'dark-gray',
 'oceans',
 'national-geographic',
 'terrain',
 'osm']
In [ ]:
map3

basemap animation

Let us animate our widget by cycling through basemaps and assigning it to the basemap property of the map widget.

In [ ]:
import time

for basemap in map3.basemaps:
    map3.basemap = basemap
    time.sleep(3)

Some Esri partners and other users have also shared their basemaps for everyone to use. Let us search for them, but this time using tags property of the items:

In [ ]:
stamenbasemaps = gis.content.search("tags:partner_basemap owner:dkensok stamen",
                                    item_type="web map", max_items=3)
for basemap in stamenbasemaps:
    display(basemap)
Stamen Watercolor
Reminiscent of hand drawn maps, our watercolor maps apply raster effect area washes and organic edges over a paper texture to add warm pop to any map.Web Map by dkensok
Last Modified: January 02, 2015
0 comments, 5,177 views
Stamen Toner
These high-contrast B+W (black and white) maps are perfect for data mashups and exploring river meanders and coastal zones.Web Map by dkensok
Last Modified: January 02, 2015
0 comments, 4,369 views
Stamen Terrain
Orient yourself with our terrain maps, featuring hill shading and natural vegetation colors. Available in the USA only.Web Map by dkensok
Last Modified: January 02, 2015
0 comments, 4,219 views

Next, head over to the topic on Smart mapping to learn how to make maps using the map widget.


Feedback on this topic?