94 heremap
Using HERE Map Widget for Jupyter as a plotting backend
Uncomment the following line to install geemap if needed.
# !pip install geemap
Prerequisites¶
Before you run the below cells make sure you have:
- A HERE developer account, free and available under HERE Developer Portal
- An API key from the HERE Developer Portal
Export API key into environment variable
HEREMAPS_API_KEY
export HEREMAPS_API_KEY=YOUR-ACTUAL-API-KEY
import os
import geemap.heremap as geemap
# Read api_key from environment
api_key = os.environ["HEREMAPS_API_KEY"]
HERE default basemap¶
Create an interactive map.
m = geemap.Map()
m
Specify the default map center and zoom level.
m = geemap.Map(center=[50, 19], zoom=4) # center=[lat, lon]
m
Set the visibility of map controls.
m = geemap.Map(fullscreen_control=False)
m
Change the map width and height.
m = geemap.Map(height="450px")
m
Basemaps¶
Use built-in basemaps.
m = geemap.Map(basemap="HERE_RASTER_TERRAIN_MAP")
m
zoom to bounds¶
Zoom to map to a bounding box [South, West, North, East].
m.zoom_to_bounds((-9.0882278, -55.3228175, 168.2249543, 72.2460938)) #
m.add_basemap(basemap="Esri.WorldTopoMap")
Add a custom XYZ tile layer.
m = geemap.Map(layers_control=True)
m.add_tile_layer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
name="Google Satellite",
attribution="Google",
)
m
Add vector data¶
How to add GeoJSON to the map
Add a GeoJSON from an HTTP URL to the map.
m = geemap.Map(center=[0, 0], zoom=2, layers_control=True)
in_geojson = 'https://raw.githubusercontent.com/giswqs/geemap/master/examples/data/cable-geo.geojson'
m.add_geojson(in_geojson, layer_name="Cable lines")
m
Add a local GeoJSON file to the map.
import json
m = geemap.Map(center=[0, 0], zoom=2)
with open("../data/countries.geojson") as fh:
geo = json.load(fh)
m.add_geojson(geo, layer_name="Countries")
m
Customize style for the GeoJSON layer.
m = geemap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/geemap/master/examples/data/countries.geojson"
style = {
"fillColor": "rgba(0, 0, 255, 0.2)",
"strokeColor": "blue",
}
hover_style = {"fillColor": "rgba(0, 0, 255, 0.7)"}
m.add_geojson(url, layer_name="Countries", style=style, hover_style=hover_style)
m
in_shp = '../data/countries.shp'
in_geojson = '../data/us-states.json'
in_kml = '../data/us-states.kml'
Add a shapefile to the map.
m = geemap.Map(center=[0, 0], zoom=2)
m.add_shp(in_shp, layer_name="Shapefile")
m
Add a KML file to the map.
m = geemap.Map(center=[40.273502, -86.126976], zoom=4)
m.add_kml(in_kml, layer_name="KML")
m
The add_vector function supports any vector data format supported by GeoPandas.
m = geemap.Map(center=[0, 0], zoom=2)
url = "https://raw.githubusercontent.com/giswqs/geemap/master/examples/data/countries.geojson"
m.add_vector(url, layer_name="Countries")
m
Point style for GeoJSON¶
Customize the style of point layers.
m = geemap.Map(center=[0, 0], zoom=2)
url = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month.geojson"
point_style = {
"strokeColor": 'white',
"lineWidth": 1,
"fillColor": "red",
"fillOpacity": 0.7,
"radius": 5,
}
m.add_geojson(url, layer_name="Countries", point_style=point_style, default_popup=True)
m
import geopandas
import json
import os
countries = geopandas.read_file(geopandas.datasets.get_path("naturalearth_cities"))
point_style = {
"strokeColor": 'white',
"lineWidth": 1,
"fillColor": "blue",
"fillOpacity": 0.7,
"radius": 5,
}
m = geemap.Map(center=[0, 0], zoom=3)
m.add_gdf(countries, zoom_to_layer=False, point_style=point_style, default_popup=True)
m
Add Earth Engine layers¶
import ee
m = geemap.Map()
m.add_basemap("HYBRID")
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(
['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
)
states = ee.FeatureCollection("TIGER/2018/States")
# Set visualization parameters.
vis_params = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Eninge layers to Map
m.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
m.addLayer(
landsat7,
{'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
'Landsat 7',
)
m.addLayer(states, {}, "US States")
m.add_layer_control()
m