Skip to content

Commit

Permalink
folium to geemap in guide pages and notebooks
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 568655626
  • Loading branch information
jdbcode authored and copybara-github committed Sep 28, 2023
1 parent 47c96bf commit ed071b8
Show file tree
Hide file tree
Showing 33 changed files with 907 additions and 871 deletions.
51 changes: 16 additions & 35 deletions guides/linked/ee-api-colab-setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"id": "aV1xZ1CPi3Nw"
},
"source": [
"<table class=\"ee-notebook-buttons\" align=\"left\"><td>\n",
"<a target=\"_blank\" href=\"http://colab.research.google.com/github/google/earthengine-community/blob/master/guides/linked/ee-api-colab-setup.ipynb\">\n",
" <img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /> Run in Google Colab</a>\n",
"</td><td>\n",
"<a target=\"_blank\" href=\"https://github.com/google/earthengine-community/blob/master/guides/linked/ee-api-colab-setup.ipynb\"><img width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /> View source on GitHub</a></td></table>"
"\u003ctable class=\"ee-notebook-buttons\" align=\"left\"\u003e\u003ctd\u003e\n",
"\u003ca target=\"_blank\" href=\"http://colab.research.google.com/github/google/earthengine-community/blob/master/guides/linked/ee-api-colab-setup.ipynb\"\u003e\n",
" \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003e Run in Google Colab\u003c/a\u003e\n",
"\u003c/td\u003e\u003ctd\u003e\n",
"\u003ca target=\"_blank\" href=\"https://github.com/google/earthengine-community/blob/master/guides/linked/ee-api-colab-setup.ipynb\"\u003e\u003cimg width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003e View source on GitHub\u003c/a\u003e\u003c/td\u003e\u003c/table\u003e"
]
},
{
Expand Down Expand Up @@ -196,14 +196,12 @@
"source": [
"### Interactive map\n",
"\n",
"The [`folium`](https://python-visualization.github.io/folium/)\n",
"The [geemap](https://github.com/gee-community/geemap)\n",
"library can be used to display `ee.Image` objects on an interactive\n",
"[Leaflet](https://leafletjs.com/) map. Folium has no default\n",
"method for handling tiles from Earth Engine, so one must be defined\n",
"and added to the `folium.Map` module before use.\n",
"[ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) map.\n",
"\n",
"The following cell provides an example of adding a method for handing Earth Engine\n",
"tiles and using it to display an elevation model to a Leaflet map."
"The following cell provides an example of using the `geemap.Map` object to\n",
"display an elevation model."
]
},
{
Expand All @@ -212,40 +210,23 @@
"id": "VIiyf6azf4mU"
},
"source": [
"# Import the Folium library.\n",
"import folium\n",
"\n",
"# Define a method for displaying Earth Engine image tiles to folium map.\n",
"def add_ee_layer(self, ee_image_object, vis_params, name):\n",
" map_id_dict = ee.Image(ee_image_object).getMapId(vis_params)\n",
" folium.raster_layers.TileLayer(\n",
" tiles = map_id_dict['tile_fetcher'].url_format,\n",
" attr = 'Map Data &copy; <a href=\"https://earthengine.google.com/\">Google Earth Engine</a>',\n",
" name = name,\n",
" overlay = True,\n",
" control = True\n",
" ).add_to(self)\n",
"\n",
"# Add EE drawing method to folium.\n",
"folium.Map.add_ee_layer = add_ee_layer\n",
"# Import the geemap library.\n",
"import geemap\n",
"\n",
"# Set visualization parameters.\n",
"vis_params = {\n",
" 'min': 0,\n",
" 'max': 4000,\n",
" 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
"\n",
"# Create a folium map object.\n",
"my_map = folium.Map(location=[20, 0], zoom_start=3)\n",
"# Create a map object.\n",
"m = geemap.Map(center=[20, 0], zoom=3)\n",
"\n",
"# Add the elevation model to the map object.\n",
"my_map.add_ee_layer(dem.updateMask(dem.gt(0)), vis_params, 'DEM')\n",
"\n",
"# Add a layer control panel to the map.\n",
"my_map.add_child(folium.LayerControl())\n",
"m.add_ee_layer(dem.updateMask(dem.gt(0)), vis_params, 'DEM')\n",
"\n",
"# Display the map.\n",
"display(my_map)"
"display(m)"
],
"execution_count": null,
"outputs": []
Expand Down Expand Up @@ -297,4 +278,4 @@
"outputs": []
}
]
}
}
276 changes: 145 additions & 131 deletions guides/linked/generated/image_info.ipynb
Original file line number Diff line number Diff line change
@@ -1,134 +1,148 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#@title Copyright 2021 The Earth Engine Community Authors { display-mode: \"form\" }\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#@title Copyright 2021 The Earth Engine Community Authors { display-mode: \"form\" }\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Image Information and Metadata\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print image objects to explore band names, projection information, properties, and other metadata. The following examples demonstrate printing the entire set of image metadata as well as requesting specific metadata elements programmatically."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Earth Engine setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"ee.Authenticate()\n",
"ee.Initialize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import `geemap`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import geemap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting metadata"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load an image.\n",
"image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')\n",
"\n",
"# All metadata.\n",
"display('All metadata:', image)\n",
"\n",
"# Get information about the bands as a list.\n",
"band_names = image.bandNames()\n",
"display('Band names:', band_names) # ee.List of band names\n",
"\n",
"# Get projection information from band 1.\n",
"b1_proj = image.select('B1').projection()\n",
"display('Band 1 projection:', b1_proj) # ee.Projection object\n",
"\n",
"# Get scale (in meters) information from band 1.\n",
"b1_scale = image.select('B1').projection().nominalScale()\n",
"display('Band 1 scale:', b1_scale) # ee.Number\n",
"\n",
"# Note that different bands can have different projections and scale.\n",
"b8_scale = image.select('B8').projection().nominalScale()\n",
"display('Band 8 scale:', b8_scale) # ee.Number\n",
"\n",
"# Get a list of all metadata properties.\n",
"properties = image.propertyNames()\n",
"display('Metadata properties:', properties) # ee.List of metadata properties\n",
"\n",
"# Get a specific metadata property.\n",
"cloudiness = image.get('CLOUD_COVER')\n",
"display('CLOUD_COVER:', cloudiness) # ee.Number\n",
"\n",
"# Get version number (ingestion timestamp as microseconds since Unix epoch).\n",
"version = image.get('system:version')\n",
"display('Version:', version) # ee.Number\n",
"display(\n",
" 'Version (as ingestion date):',\n",
" ee.Date(ee.Number(version).divide(1000)).format(),\n",
") # ee.Date\n",
"\n",
"# Get the timestamp.\n",
"ee_date = ee.Date(image.get('system:time_start'))\n",
"display('Timestamp:', ee_date) # ee.Date\n",
"\n",
"# Date objects transferred to the client are milliseconds since UNIX epoch;\n",
"# convert to human readable date with ee.Date.format().\n",
"display('Datetime:', ee_date.format()) # ISO standard date string"
]
}
],
"metadata": {
"colab": {
"name": "Image Information and Metadata"
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Image Information and Metadata\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Print image objects to explore band names, projection information, properties, and other metadata. The following examples demonstrate printing the entire set of image metadata as well as requesting specific metadata elements programmatically."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Earth Engine setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"ee.Authenticate()\n",
"ee.Initialize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting metadata"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pprint\n",
"\n",
"# Load an image.\n",
"image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')\n",
"\n",
"# All metadata.\n",
"print('All metadata:')\n",
"pprint.pprint(image.getInfo())\n",
"\n",
"# Get information about the bands as a list.\n",
"band_names = image.bandNames()\n",
"print('Band names:', band_names.getInfo()) # ee.List of band names\n",
"\n",
"# Get projection information from band 1.\n",
"b1_proj = image.select('B1').projection()\n",
"print('Band 1 projection:', b1_proj.getInfo()) # ee.Projection object\n",
"\n",
"# Get scale (in meters) information from band 1.\n",
"b1_scale = image.select('B1').projection().nominalScale()\n",
"print('Band 1 scale:', b1_scale.getInfo()) # ee.Number\n",
"\n",
"# Note that different bands can have different projections and scale.\n",
"b8_scale = image.select('B8').projection().nominalScale()\n",
"print('Band 8 scale:', b8_scale.getInfo()) # ee.Number\n",
"\n",
"# Get a list of all metadata properties.\n",
"properties = image.propertyNames()\n",
"print('Metadata properties:',\n",
" properties.getInfo()) # ee.List of metadata properties\n",
"\n",
"# Get a specific metadata property.\n",
"cloudiness = image.get('CLOUD_COVER')\n",
"print('CLOUD_COVER:', cloudiness.getInfo()) # ee.Number\n",
"\n",
"# Get version number (ingestion timestamp as microseconds since Unix epoch).\n",
"version = image.get('system:version')\n",
"print('Version:', version.getInfo()) # ee.Number\n",
"print('Version (as ingestion date):',\n",
" ee.Date(ee.Number(version).divide(1000)).format().getInfo()) # ee.Date\n",
"\n",
"# Get the timestamp.\n",
"ee_date = ee.Date(image.get('system:time_start'))\n",
"print('Timestamp:', ee_date.getInfo()) # ee.Date\n",
"\n",
"# Date objects transferred to the client are milliseconds since UNIX epoch;\n",
"# convert to human readable date with ee.Date.format().\n",
"print('Datetime:', ee_date.format().getInfo()) # ISO standard date string"
]
}
],
"metadata": {
"colab": {
"name": "Image Information and Metadata"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit ed071b8

Please sign in to comment.