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