Skip to content

Commit

Permalink
Added blend function
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 8, 2022
1 parent d283f8e commit b283ce0
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 1 deletion.
185 changes: 185 additions & 0 deletions docs/notebooks/102_blend_hillshade.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/giswqs/geemap/blob/master/examples/notebooks/102_blend_hillshade.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Creating a shaded relief map by blending DEM and hillshade**\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": [
"Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
"import geemap.colormaps as cm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an interactive map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add DEM and hillshade to the map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dem = ee.Image(\"CGIAR/SRTM90_V4\")\n",
"hillsahde = ee.Terrain.hillshade(dem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vis = {'min': 0, 'max': 6000, 'palette': cm.palettes.dem}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(hillsahde, {}, 'Hillshade')\n",
"Map.addLayer(dem, vis, 'DEM')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a blended image by blending DEM and hillshade"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"blend = geemap.blend(top_layer=dem, top_vis=vis)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(blend, {}, 'Blend')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add NLCD land cover to the map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nlcd = ee.Image(\"USGS/NLCD_RELEASES/2019_REL/NLCD/2019\").select('landcover')\n",
"nlcd_vis = {'bands': ['landcover']}\n",
"Map.addLayer(nlcd, nlcd_vis, 'NLCD')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a blended image by blending NLCD and DEM."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = geemap.blend(nlcd, dem, top_vis=nlcd_vis, expression='a*b')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(result, {}, 'Blend NLCD')"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
1 change: 1 addition & 0 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
99. Visualizing Landsat 9 data ([notebook](https://geemap.org/notebooks/99_landsat_9/))
100. Converting numpy array to COG ([notebook](https://geemap.org/notebooks/100_numpy_to_cog))
101. Visualizing LiDAR data in 3D with only one line of code ([notebook](https://geemap.org/notebooks/101_lidar))
102. Creating a shaded relief by blending DEM and hillshade ([notebook](https://geemap.org/notebooks/102_blend_hillshade))
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ More video tutorials for geemap and Earth Engine are available on my [YouTube ch
99. Visualizing Landsat 9 data ([notebook](https://geemap.org/notebooks/99_landsat_9))
100. Converting numpy array to COG ([notebook](https://geemap.org/notebooks/100_numpy_to_cog))
101. Visualizing LiDAR data in 3D with only one line of code ([notebook](https://geemap.org/notebooks/101_lidar))
102. Creating a shaded relief by blending DEM and hillshade ([notebook](https://geemap.org/notebooks/102_blend_hillshade))

### 1. Introducing the geemap Python package for interactive mapping with Google Earth Engine

Expand Down
185 changes: 185 additions & 0 deletions examples/notebooks/102_blend_hillshade.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://githubtocolab.com/giswqs/geemap/blob/master/examples/notebooks/102_blend_hillshade.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
"\n",
"**Creating a shaded relief map by blending DEM and hillshade**\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": [
"Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ee\n",
"import geemap\n",
"import geemap.colormaps as cm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an interactive map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add DEM and hillshade to the map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dem = ee.Image(\"CGIAR/SRTM90_V4\")\n",
"hillsahde = ee.Terrain.hillshade(dem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vis = {'min': 0, 'max': 6000, 'palette': cm.palettes.dem}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(hillsahde, {}, 'Hillshade')\n",
"Map.addLayer(dem, vis, 'DEM')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a blended image by blending DEM and hillshade"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"blend = geemap.blend(top_layer=dem, top_vis=vis)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(blend, {}, 'Blend')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add NLCD land cover to the map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nlcd = ee.Image(\"USGS/NLCD_RELEASES/2019_REL/NLCD/2019\").select('landcover')\n",
"nlcd_vis = {'bands': ['landcover']}\n",
"Map.addLayer(nlcd, nlcd_vis, 'NLCD')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a blended image by blending NLCD and DEM."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = geemap.blend(nlcd, dem, top_vis=nlcd_vis, expression='a*b')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map.addLayer(result, {}, 'Blend NLCD')"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit b283ce0

Please sign in to comment.