Plotting Earth Engine vector data with cartoee
Uncomment the following line to install geemap and cartopy if needed. Keep in mind that cartopy can be challenging to install. If you are unable to install cartopy on your computer, you can try Google Colab with this the notebook example.
See below the commands to install cartopy and geemap using conda/mamba:
conda create -n carto python=3.8
conda activate carto
conda install cartopy scipy -c conda-forge
conda install geemap -c conda-forge
jupyter notebook
# !pip install cartopy scipy
# !pip install geemap
import ee
import geemap
from geemap import cartoee
from geemap.datasets import DATA
import geemap.colormaps as cmap
import cartopy.crs as ccrs
%pylab inline
Map = geemap.Map()
features = ee.FeatureCollection(DATA.users_giswqs_public_countries)
style = {"color": "000000ff", "width": 1, "lineType": "solid", "fillColor": "0000ff40"}
Map.addLayer(features.style(**style), {}, "Polygons")
Map.setCenter(-14.77, 34.70, 2)
Map
# specify region to focus on
bbox = [180, -88, -180, 88]
fig = plt.figure(figsize=(15, 10))
# plot the result with cartoee using a PlateCarre projection (default)
ax = cartoee.get_map(features, region=bbox, style=style)
ax.set_title(label="Countries", fontsize=15)
cartoee.add_gridlines(ax, interval=30)
plt.show()
fig = plt.figure(figsize=(15, 10))
projection = ccrs.EqualEarth(central_longitude=-180)
ax = cartoee.get_map(features, region=bbox, proj=projection, style=style)
ax.set_title(label="Countries", fontsize=15)
plt.show()
Map = geemap.Map()
features = ee.FeatureCollection(DATA.users_giswqs_public_countries)
palette = cmap.palettes.gist_earth
features_styled = geemap.vector_styling(features, column="name", palette=palette)
Map.add_styled_vector(features, column="name", palette=palette, layer_name="Polygon")
Map.setCenter(-14.77, 34.70, 2)
Map
bbox = [180, -88, -180, 88]
fig = plt.figure(figsize=(15, 10))
ax = cartoee.get_map(features_styled, region=bbox)
ax.set_title(label="Countries", fontsize=15)
cartoee.add_gridlines(ax, interval=30)
plt.show()
fig = plt.figure(figsize=(15, 10))
projection = ccrs.EqualEarth(central_longitude=-180)
ax = cartoee.get_map(features_styled, region=bbox, proj=projection)
ax.set_title(label="Countries", fontsize=15)
plt.show()