Skip to content

Commit

Permalink
Improve support for xee (gee-community#1861)
Browse files Browse the repository at this point in the history
* Improve support for xee

* Add array_to_image function

* Add basemap example

* Add notebook example

* Clean up notebook

* Improve zonal stats
  • Loading branch information
giswqs authored Dec 25, 2023
1 parent e7fed01 commit 130e289
Show file tree
Hide file tree
Showing 16 changed files with 1,256 additions and 369 deletions.
26 changes: 26 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ Map = geemap.Map(center=(40, -100), zoom=4)
Map
```

## Use basemaps

Basemaps can be added to the map using the `add_basemap()` function. The default basemap is `OpenStreetMap`.

```python
Map = geemap.Map()
Map.add_basemap("Esri.WorldImagery")
Map.add_basemap("OpenTopoMap")
Map
```

All Google basemaps have been removed from the geemap since [v0.26.0](https://geemap.org/changelog/#v0270-sep-21-2023) to comply with Google Maps' terms of service. Users can choose to add Google basemaps at their own risks by setting environment variables as follows. If no env variables are detected, Esri basemaps will be used.

```python
import os

os.environ["ROADMAP"] = 'https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'
os.environ["SATELLITE"] = 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}'
os.environ["TERRAIN"] = 'https://mt1.google.com/vt/lyrs=p&x={x}&y={y}&z={z}'
os.environ["HYBRID"] = 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}'

Map = geemap.Map()
Map.add_basemap("HYBRID")
Map
```

## Add Earth Engine data

```python
Expand Down
258 changes: 141 additions & 117 deletions docs/notebooks/114_dynamic_world.ipynb
Original file line number Diff line number Diff line change
@@ -1,119 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/114_dynamic_world.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Creating near real-time global 10-m land cover maps with geemap and Dynamic World**\n",
"\n",
"- App: https://www.dynamicworld.app\n",
"- App2: https://earthoutreach.users.earthengine.app/view/dynamicworld\n",
"- Paper: https://doi.org/10.1038/s41597-022-01307-4\n",
"- Model: https://github.com/google/dynamicworld\n",
"- Training data: https://doi.pangaea.de/10.1594/PANGAEA.933475\n",
"- Data: https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_DYNAMICWORLD_V1\n",
"- JavaScript tutorial: https://developers.google.com/earth-engine/tutorials/community/introduction-to-dynamic-world-pt-1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map.add_basemap('HYBRID')\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set the region of interest by simply drawing a polygon on the map\n",
"region = Map.user_roi\n",
"if region is None:\n",
" region = ee.Geometry.BBox(-89.7088, 42.9006, -89.0647, 43.2167)\n",
"\n",
"Map.centerObject(region)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set the date range\n",
"start_date = '2021-01-01'\n",
"end_date = '2022-01-01'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a Sentinel-2 image composite\n",
"image = geemap.dynamic_world_s2(region, start_date, end_date)\n",
"vis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 3000}\n",
"Map.addLayer(image, vis_params, 'Sentinel-2 image')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create Dynamic World land cover composite\n",
"landcover = geemap.dynamic_world(region, start_date, end_date, return_type='hillshade')\n",
"Map.addLayer(landcover, {}, 'Land Cover')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Add legend to the map\n",
"Map.add_legend(title=\"Dynamic World Land Cover\", builtin_legend='Dynamic_World')\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/GEzsSii.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
"cells": [
{
"cell_type": "markdown",
"metadata": {
},
"source": [
"<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/114_dynamic_world.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Creating near real-time global 10-m land cover maps with geemap and Dynamic World**\n",
"\n",
"- App: <https://www.dynamicworld.app>\n",
"- App2: <https://earthoutreach.users.earthengine.app/view/dynamicworld>\n",
"- Paper: <https://doi.org/10.1038/s41597-022-01307-4>\n",
"- Model: <https://github.com/google/dynamicworld>\n",
"- Training data: <https://doi.pangaea.de/10.1594/PANGAEA.933475>\n",
"- Data: <https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_DYNAMICWORLD_V1>\n",
"- JavaScript tutorial: <https://developers.google.com/earth-engine/tutorials/community/introduction-to-dynamic-world-pt-1>"
]
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"import ee\n",
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map.add_basemap('HYBRID')\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"# Set the region of interest by simply drawing a polygon on the map\n",
"region = Map.user_roi\n",
"if region is None:\n",
" region = ee.Geometry.BBox(-89.7088, 42.9006, -89.0647, 43.2167)\n",
"\n",
"Map.centerObject(region)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"# Set the date range\n",
"start_date = '2021-01-01'\n",
"end_date = '2022-01-01'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"# Create a Sentinel-2 image composite\n",
"image = geemap.dynamic_world_s2(region, start_date, end_date)\n",
"vis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 3000}\n",
"Map.addLayer(image, vis_params, 'Sentinel-2 image')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"# Create Dynamic World land cover composite\n",
"landcover = geemap.dynamic_world(region, start_date, end_date, return_type='hillshade')\n",
"Map.addLayer(landcover, {}, 'Land Cover')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Add legend to the map\n",
"Map.add_legend(title=\"Dynamic World Land Cover\", builtin_legend='Dynamic_World')\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {
},
"source": [
"![](https://i.imgur.com/GEzsSii.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
},
"outputs": [],
"source": [
"# Save Dynamic World class data in GeoTIFF format\n",
"output_path = 'landcover.tif'\n",
"landcover = geemap.dynamic_world(region, start_date, end_date, return_type='class')\n",
"geemap.ee_export_image(landcover, filename=output_path, scale=10, region=region, file_per_band=False)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 130e289

Please sign in to comment.