69 cartoee vector
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
In [1]:
Copied!
# !pip install cartopy scipy
# !pip install geemap
# !pip install cartopy scipy
# !pip install geemap
In [2]:
Copied!
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
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
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: 6>() 4 from geemap.datasets import DATA 5 import geemap.colormaps as cmap ----> 6 import cartopy.crs as ccrs 8 get_ipython().run_line_magic('pylab', 'inline') ModuleNotFoundError: No module named 'cartopy'
Plot a simple vector¶
In [3]:
Copied!
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
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
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
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(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))
# 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()
--------------------------------------------------------------------------- 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(features, region=bbox, style=style) NameError: name 'plt' is not defined
In [6]:
Copied!
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()
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()
--------------------------------------------------------------------------- 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) 4 ax = cartoee.get_map(features, region=bbox, proj=projection, style=style) NameError: name 'plt' is not defined
Plot a styled vector¶
In [7]:
Copied!
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
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
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
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()
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()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [8], in <cell line: 2>() 1 bbox = [180, -88, -180, 88] ----> 2 fig = plt.figure(figsize=(15, 10)) 4 ax = cartoee.get_map(features_styled, region=bbox) 5 ax.set_title(label='Countries', fontsize=15) NameError: name 'plt' is not defined
In [9]:
Copied!
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()
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()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [9], in <cell line: 1>() ----> 1 fig = plt.figure(figsize=(15, 10)) 3 projection = ccrs.EqualEarth(central_longitude=-180) 4 ax = cartoee.get_map(features_styled, region=bbox, proj=projection) NameError: name 'plt' is not defined
Last update:
2022-03-14