{
"cells": [
{
"cell_type": "markdown",
"id": "27844be8",
"metadata": {},
"source": [
"# Dynamic World\n",
"Use Dynamic World to compare land cover change over time.\n",
"\n",
"## Dynamic World, Party Time, Excellent\n",
"Dynamic World is a worldwide dataset for landcover at 10m resolution. Using the broad land types from the dataset is an excellent way to examine land use change. The code is adapted from geemap [tutorial 114](https://geemap.org/notebooks/114_dynamic_world/). Bonus!\n",
"\n",
""
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a61f05a4",
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [],
"source": [
"# Import earth engine geemap and create a map\n",
"import ee\n",
"import geemap\n",
"m = geemap.Map()\n",
"m.add_basemap(\"TERRAIN\")"
]
},
{
"cell_type": "markdown",
"id": "c6a368f9",
"metadata": {},
"source": [
"Here, we've used the [Polyline tool](https://www.keene.edu/campus/maps/tool/) to create a bounding box in the Chaco region of southeastern Bolivia. Remember, the bbox coordinates require lower left lat lon and upper right lat lon to make a rectangular box."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "63d31124",
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create a region of interest. \n",
"region = m.user_roi\n",
"if region is None:\n",
" region = ee.Geometry.BBox(-64.6523439, -25.9007305, -63.1115113, -24.8390856)\n",
"m.centerObject(region)"
]
},
{
"cell_type": "markdown",
"id": "e36f729c",
"metadata": {},
"source": [
"Then we'll set the date ranges for a before and after image then sentinel and dynamic world composites."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "56fb48e7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Set the 1st date range\n",
"start_date = \"2016-01-01\"\n",
"end_date = \"2017-01-01\"\n",
"\n",
"# Set the 2nd date range\n",
"start_date2 = \"2023-01-01\"\n",
"end_date2 = \"2024-01-01\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "bcc2d238",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"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",
"m.addLayer(image, vis_params, \"Sentinel-2 image\")\n",
"\n",
"# Create a Sentinel-2 image composite2\n",
"image2 = geemap.dynamic_world_s2(region, start_date2, end_date2)\n",
"vis_params = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"min\": 0, \"max\": 3000}\n",
"m.addLayer(image2, vis_params, \"Sentinel-2 image2\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5b63a547",
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create Dynamic World land cover composite\n",
"landcover = geemap.dynamic_world(region, start_date, end_date, return_type=\"hillshade\")\n",
"m.addLayer(landcover, {}, \"Land Cover\")\n",
"\n",
"# Create Dynamic World land cover composite2\n",
"landcover2 = geemap.dynamic_world(region, start_date2, end_date2, return_type=\"hillshade\")\n",
"m.addLayer(landcover2, {}, \"Land Cover2\")"
]
},
{
"cell_type": "markdown",
"id": "1982d377",
"metadata": {},
"source": [
"To compare the 2016 to the 2024 composite we'll add a swipe split panel."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4167f6c5",
"metadata": {
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Add split panel. Zooming with the split panel sometimes doesn't work\n",
"left_layer = geemap.ee_tile_layer(landcover, {}, \"Land Cover\")\n",
"right_layer = geemap.ee_tile_layer(landcover2, {}, \"Land Cover2\")\n",
"\n",
"m = geemap.Map()\n",
"m.split_map(left_layer, right_layer)"
]
},
{
"cell_type": "markdown",
"id": "02d9a4c4",
"metadata": {},
"source": [
"And then a legend and text"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "650c8db4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "397022ed87c94523bfa87b5332c946bf",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text'…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Add legend and explanatory text\n",
"m.add_legend(title=\"Dynamic World Land Cover\", builtin_legend=\"Dynamic_World\")\n",
"text = \"2017 (left) and 2024 (right) land cover\"\n",
"m.add_text(text, fontsize=14, position='bottomleft')\n",
"m.centerObject(region)\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "f973495d",
"metadata": {},
"source": [
"\n",
"\n",
"Schwing! To export the first map as a geotiff add this code"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80b395ec",
"metadata": {},
"outputs": [],
"source": [
"# Save Dynamic World 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)"
]
},
{
"cell_type": "markdown",
"id": "1a0e6256",
"metadata": {},
"source": [
"**HALRIGHT!**
\n",
"\n",
""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "spatial",
"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.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}