Install the Earth Engine Python API and geemap. The geemap Python package is built upon the ipyleaflet and folium packages and implements several methods for interacting with Earth Engine data layers, such as Map.addLayer()
, Map.setCenter()
, and Map.centerObject()
.
The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its dependencies, including earthengine-api, folium, and ipyleaflet.
# Installs geemap package
import subprocess
try:
import geemap
except ImportError:
print('Installing geemap ...')
subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
import ee
import geemap
The default basemap is Google Maps
. Additional basemaps can be added using the Map.add_basemap()
function.
#mport geemap.eefolium as geemap
Map = geemap.Map(center=[-19.82,34.55], zoom=10)
Map.add_basemap('SATELLITE')
Map
Map(center=[-19.82, 34.55], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=SearchDataG…
# Add Earth Engine dataset
###############################
# Asset List
###############################
gsw = ee.Image('JRC/GSW1_1/GlobalSurfaceWater')
occurrence = gsw.select('occurrence')
###############################
# Constants
###############################
VIS_OCCURRENCE = {
'min':0,
'max':100,
'palette': ['red', 'blue']
}
VIS_WATER_MASK = {
'palette': ['white', 'black']
}
###############################
# Calculations
###############################
# Create a water mask layer, and set the image mask so that non-water areas
# are opaque.
water_mask = occurrence.gt(90).selfMask()
###############################
# Initialize Map Location
###############################
# Uncomment one of the following statements to center the map.
Map.setCenter(34.55,-19.82, 10) # coastal region Beira, Mozambique
###############################
# Map Layers
###############################
Map1 = geemap.Map(center=[-19.82,34.55], zoom=10)
Map1.add_basemap('SATELLITE')
Map1.addLayer(occurrence.updateMask(occurrence.divide(100)), VIS_OCCURRENCE, "Water Occurrence (1984-2018)")
Map1.addLayer(water_mask, VIS_WATER_MASK, '90% occurrence water mask', False)
Map1
# Use the options provided under he upper right hand tool icon, e.g. inspect the 'i'
Map(center=[-19.82, 34.55], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=SearchDataG…