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 mamba -c conda-forge
mamba install cartopy scipy -c conda-forge
mamba install geemap -c conda-forge
jupyter notebook
In [1]:
Copied!
# !pip install cartopy scipy
# !pip install geemap
# !pip install cartopy scipy
# !pip install geemap
Creating publication-quality maps with multiple Earth Engine layers¶
In [2]:
Copied!
import ee
import geemap
from geemap import cartoee
import cartopy.crs as ccrs
%pylab inline
import ee
import geemap
from geemap import cartoee
import cartopy.crs as ccrs
%pylab inline
cartopy is not installed. Please see https://scitools.org.uk/cartopy/docs/latest/installing.html#installing for instructions on how to install cartopy. The easiest way to install cartopy is using conda: conda install -c conda-forge cartopy
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Input In [2], in <cell line: 4>() 2 import geemap 3 from geemap import cartoee ----> 4 import cartopy.crs as ccrs 6 get_ipython().run_line_magic('pylab', 'inline') ModuleNotFoundError: No module named 'cartopy'
Create an interactive map¶
In [3]:
Copied!
Map = geemap.Map()
image = (
ee.ImageCollection('MODIS/MCD43A4_006_NDVI')
.filter(ee.Filter.date('2018-04-01', '2018-05-01'))
.select("NDVI")
.first()
)
vis_params = {
'min': 0.0,
'max': 1.0,
'palette': [
'FFFFFF',
'CE7E45',
'DF923D',
'F1B555',
'FCD163',
'99B718',
'74A901',
'66A000',
'529400',
'3E8601',
'207401',
'056201',
'004C00',
'023B01',
'012E01',
'011D01',
'011301',
],
}
Map.setCenter(-7.03125, 31.0529339857, 2)
Map.addLayer(image, vis_params, 'MODIS NDVI')
countries = ee.FeatureCollection('users/giswqs/public/countries')
style = {"color": "00000088", "width": 1, "fillColor": "00000000"}
Map.addLayer(countries.style(**style), {}, "Countries")
ndvi = image.visualize(**vis_params)
blend = ndvi.blend(countries.style(**style))
Map.addLayer(blend, {}, "Blend")
Map
Map = geemap.Map()
image = (
ee.ImageCollection('MODIS/MCD43A4_006_NDVI')
.filter(ee.Filter.date('2018-04-01', '2018-05-01'))
.select("NDVI")
.first()
)
vis_params = {
'min': 0.0,
'max': 1.0,
'palette': [
'FFFFFF',
'CE7E45',
'DF923D',
'F1B555',
'FCD163',
'99B718',
'74A901',
'66A000',
'529400',
'3E8601',
'207401',
'056201',
'004C00',
'023B01',
'012E01',
'011D01',
'011301',
],
}
Map.setCenter(-7.03125, 31.0529339857, 2)
Map.addLayer(image, vis_params, 'MODIS NDVI')
countries = ee.FeatureCollection('users/giswqs/public/countries')
style = {"color": "00000088", "width": 1, "fillColor": "00000000"}
Map.addLayer(countries.style(**style), {}, "Countries")
ndvi = image.visualize(**vis_params)
blend = ndvi.blend(countries.style(**style))
Map.addLayer(blend, {}, "Blend")
Map
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Plot an image with the default projection¶
In [4]:
Copied!
# specify region to focus on
bbox = [180, -88, -180, 88]
# specify region to focus on
bbox = [180, -88, -180, 88]
In [5]:
Copied!
fig = plt.figure(figsize=(15, 10))
# plot the result with cartoee using a PlateCarre projection (default)
ax = cartoee.get_map(blend, region=bbox)
cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')
ax.set_title(label='MODIS NDVI', fontsize=15)
# ax.coastlines()
plt.show()
fig = plt.figure(figsize=(15, 10))
# plot the result with cartoee using a PlateCarre projection (default)
ax = cartoee.get_map(blend, region=bbox)
cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')
ax.set_title(label='MODIS NDVI', fontsize=15)
# ax.coastlines()
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [5], in <cell line: 1>() ----> 1 fig = plt.figure(figsize=(15, 10)) 3 # plot the result with cartoee using a PlateCarre projection (default) 4 ax = cartoee.get_map(blend, region=bbox) NameError: name 'plt' is not defined
Plot an image with a different projection¶
In [6]:
Copied!
fig = plt.figure(figsize=(15, 10))
projection = ccrs.EqualEarth(central_longitude=-180)
# plot the result with cartoee using a PlateCarre projection (default)
ax = cartoee.get_map(blend, region=bbox, proj=projection)
cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')
ax.set_title(label='MODIS NDVI', fontsize=15)
# ax.coastlines()
plt.show()
fig = plt.figure(figsize=(15, 10))
projection = ccrs.EqualEarth(central_longitude=-180)
# plot the result with cartoee using a PlateCarre projection (default)
ax = cartoee.get_map(blend, region=bbox, proj=projection)
cb = cartoee.add_colorbar(ax, vis_params=vis_params, loc='right')
ax.set_title(label='MODIS NDVI', fontsize=15)
# ax.coastlines()
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [6], in <cell line: 1>() ----> 1 fig = plt.figure(figsize=(15, 10)) 3 projection = ccrs.EqualEarth(central_longitude=-180) 5 # plot the result with cartoee using a PlateCarre projection (default) NameError: name 'plt' is not defined
Last update:
2022-03-14