Skip to content

Commit

Permalink
Updated notebook example
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 8, 2020
1 parent bd6fa8a commit acd04e0
Showing 1 changed file with 96 additions and 40 deletions.
136 changes: 96 additions & 40 deletions examples/template.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<table class=\"ee-notebook-buttons\" align=\"left\">\n",
" <td><a target=\"_blank\" href=\"https://github.com/giswqs/geemap/tree/master/examples/template.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td>\n",
" <td><a target=\"_blank\" href=\"https://nbviewer.jupyter.org/github/giswqs/geemap/blob/master/examples/template.ipynb\"><img width=26px src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png\" />Notebook Viewer</a></td>\n",
" <td><a target=\"_blank\" href=\"https://mybinder.org/v2/gh/giswqs/geemap/master?filepath=examples/template.ipynb\"><img width=58px src=\"https://mybinder.org/static/images/logo_social.png\" />Run in binder</a></td>\n",
" <td><a target=\"_blank\" href=\"https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/template.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a></td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install Earth Engine API and geemap\n",
"Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package builds on the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) package and implements several methods for displaying Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
"The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically install its dependencies, including earthengine-api and ipyleaflet."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import geemap\n",
"import subprocess\n",
"\n",
"try:\n",
" import geemap\n",
"except ImportError:\n",
" print('geemap package not installed. Installing ...')\n",
" subprocess.check_call([\"python\", '-m', 'pip', 'install', 'geemap'])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
"\n",
"try:\n",
" ee.Initialize()\n",
Expand All @@ -17,18 +53,48 @@
]
},
{
"cell_type": "code",
"execution_count": 2,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()"
"## Create an interactive map"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "abad8bc63c1848638f8cee8fd5297909",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Map = geemap.Map(center=(40, -100), zoom=4)\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add Earth Engine Python script"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -54,17 +120,15 @@
"print('Mount Everest elevation (m):', elev)\n",
"\n",
"# Add Earth Eninge layers to Map\n",
"Map.addLayer(image, vis_params, 'DEM', True, 0.5)\n",
"Map.addLayer(image, vis_params, 'STRM DEM', True, 0.5)\n",
"Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"Map.centerObject(xy, 13)"
"## Change map positions"
]
},
{
Expand All @@ -73,7 +137,7 @@
"metadata": {},
"outputs": [],
"source": [
"Map.setCenter(-100, 40, 8)"
"Map.centerObject(xy, 13)"
]
},
{
Expand All @@ -82,8 +146,14 @@
"metadata": {},
"outputs": [],
"source": [
"url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'\n",
"Map.addWmsTileLayer(url=url, layers='0', name='NAIP')"
"Map.setCenter(-100, 40, 4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add custom TileLayer"
]
},
{
Expand All @@ -92,51 +162,37 @@
"metadata": {},
"outputs": [],
"source": [
"url = 'https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WMSServer?'\n",
"Map.addWmsTileLayer(url=url, layers='3DEPElevation:None')"
"url = 'https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'\n",
"Map.addTileLayer(url, name='Google Map', attribution='Google')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"Map.addTileLayer(name=\"OSM\")"
"## Add custom WMS TileLayer\n",
"\n",
"More WMS layers can be found at <https://viewer.nationalmap.gov/services/>"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"url = 'https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'\n",
"Map.addTileLayer(url, name='Google Map', attribution='Google')"
"url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'\n",
"Map.addWmsTileLayer(url=url, layers='0', name='NAIP Imagery')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7cd01a48600c4f339b673ed5511e3b30",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[40, -100], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_t…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"Map"
"url = 'https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WMSServer?'\n",
"Map.addWmsTileLayer(url=url, layers='3DEPElevation:None', name='3DEP Elevation')"
]
}
],
Expand Down

0 comments on commit acd04e0

Please sign in to comment.