#!/usr/bin/env python # coding: utf-8 # Open in Colab # # **Plotting Earth Engine vector data with cartoee** # # Uncomment the following line to install [geemap](https://geemap.org) and [cartopy](https://scitools.org.uk/cartopy/docs/latest/installing.html#installing) 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](https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/69_cartoee_vector.ipynb). # # 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[ ]: # !pip install cartopy scipy # !pip install geemap # In[ ]: import ee import geemap from geemap import cartoee from geemap.datasets import DATA import geemap.colormaps as cmap import cartopy.crs as ccrs get_ipython().run_line_magic('pylab', 'inline') # ## Plot a simple vector # In[ ]: 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 # In[ ]: # specify region to focus on bbox = [-180, -88, 180, 88] # In[ ]: 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() # ![](https://i.imgur.com/RTFGotE.png) # In[ ]: 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() # ![](https://i.imgur.com/GagRINK.png) # ## Plot a styled vector # In[ ]: 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 # In[ ]: 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() # ![](https://i.imgur.com/reecFZo.png) # In[ ]: 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() # ![](https://i.imgur.com/uW9p8vS.png)