Uncomment the following line to install geemap if needed.
# !pip install geemap
cartoee
quickstart¶cartoee
is a lightweight module to aid in creatig publication quality maps from Earth Engine processing results without having to download data. The cartoee
package does this by requesting png images from EE results (which are usually good enough for visualization) and cartopy
is used to create the plots. Utility functions are available to create plot aethetics such as gridlines or color bars.
%pylab inline
import ee
import geemap
# import the cartoee functionality from geemap
from geemap import cartoee
Map = geemap.Map()
In this first example we will explore the most basic functionality including plotting and image, adding a colorbar, and adding visual aethetic features. Here we will use SRTM data to plot global elevation.
# get an image
srtm = ee.Image("CGIAR/SRTM90_V4")
region = [-180, -60, 180, 85] # define bounding box to request data
vis = {"min": 0, "max": 3000} # define visualization parameters for image
fig = plt.figure(figsize=(10, 7))
# use cartoee to get a map
ax = cartoee.get_map(srtm, region=region, vis_params=vis)
# add a colorbar to the map using the visualization params we passed to the map
cartoee.add_colorbar(ax, vis, loc="bottom", label="Elevation", orientation="horizontal")
# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax, interval=[60, 30], linestyle=":")
# add coastlines using the cartopy api
ax.coastlines(color="red")
show()
This is a decent map for minimal amount of code. But we can also easily use matplotlib colormaps to visualize our EE results to add more color. Here we add a cmap
keyword to the .get_map()
and .add_colorbar()
functions.
fig = plt.figure(figsize=(10, 7))
cmap = "gist_earth" # colormap we want to use
# use cartoee to get a map
ax = cartoee.get_map(srtm, region=region, vis_params=vis, cmap=cmap)
# add a colorbar to the map using the visualization params we passed to the map
cartoee.add_colorbar(
ax, vis, cmap=cmap, loc="bottom", label="Elevation", orientation="horizontal"
)
# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax, interval=[60, 30], linestyle=":")
# add coastlines using the cartopy api
ax.coastlines(color="red")
show()
cartoee
also allows for plotting of RGB image results directly. Here is an example of plotting a Landsat false-color scene.
# get a landsat image to visualize
image = ee.Image("LANDSAT/LC08/C01/T1_SR/LC08_044034_20140318")
# define the visualization parameters to view
vis = {"bands": ["B5", "B4", "B3"], "min": 0, "max": 5000, "gamma": 1.3}
# use cartoee to get a map
ax = cartoee.get_map(image, vis_params=vis)
# pad the view for some visual appeal
cartoee.pad_view(ax)
# add the gridlines and specify that the xtick labels be rotated 45 degrees
cartoee.add_gridlines(ax, interval=0.5, xtick_rotation=45, linestyle=":")
# add the coastline
ax.coastlines(color="yellow")
show()
By default, if a region is not provided via the region
keyword the whole extent of the image will be plotted as seen in the previous Landsat example. We can also zoom to a specific region of an image by defining the region to plot.
# here is the bounding box of the map extent we want to use
# formatted a [W,S,E,N]
zoom_region = [-122.6265, 37.3458, -121.8025, 37.9178]
# plot the map over the region of interest
ax = cartoee.get_map(image, vis_params=vis, region=zoom_region)
# add the gridlines and specify that the xtick labels be rotated 45 degrees
cartoee.add_gridlines(ax, interval=0.15, xtick_rotation=45, linestyle=":")
# add coastline
ax.coastlines(color="yellow")
show()