From a09fde6a2a9c3c537383420ea0bb2a80e82f7580 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Wed, 6 Nov 2024 20:55:13 -0500 Subject: [PATCH] Add Lab 9 (#144) * Add lab 9 * Update geemap notebook * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- book/geospatial/geemap.ipynb | 4 +- book/geospatial/geemap.md | 90 +++++++++++++++++++- book/labs/lab_09.ipynb | 160 +++++++++++++++++++++++++++++++++++ book/labs/lab_09.md | 96 +++++++++++++++++++++ 4 files changed, 347 insertions(+), 3 deletions(-) create mode 100644 book/labs/lab_09.ipynb create mode 100644 book/labs/lab_09.md diff --git a/book/geospatial/geemap.ipynb b/book/geospatial/geemap.ipynb index 9b5f004..7c67f55 100644 --- a/book/geospatial/geemap.ipynb +++ b/book/geospatial/geemap.ipynb @@ -5190,7 +5190,7 @@ ], "metadata": { "kernelspec": { - "display_name": "geo", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -5204,7 +5204,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/book/geospatial/geemap.md b/book/geospatial/geemap.md index ced17d0..d22daf9 100644 --- a/book/geospatial/geemap.md +++ b/book/geospatial/geemap.md @@ -6,7 +6,7 @@ jupytext: format_version: 0.13 jupytext_version: 1.16.4 kernelspec: - display_name: geo + display_name: Python 3 (ipykernel) language: python name: python3 --- @@ -180,6 +180,12 @@ m.add_tile_layer(url, name="Google Satellite", attribution="Google") m ``` +You can also add text to the map using the `add_text` method. The text will be displayed at the specified location on the map. + +```{code-cell} ipython3 +m.add_text(text="Hello from Earth Engine", position="bottomright") +``` + ## Introduction to Interactive Maps and Tools ### Basemap Selector @@ -527,6 +533,23 @@ m.add_layer(fc, {}, "Southeastern U.S.") m.center_object(fc, 6) ``` +A FeatureCollection can be used to clip an image. The `clipToCollection` method clips an image to the geometry of a feature collection. For example, to clip a Landsat image to the boundary of France: + +```{code-cell} ipython3 +m = geemap.Map(center=(40, -100), zoom=4) +landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003") +countries = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level0") +fc = countries.filter(ee.Filter.eq("ADM0_NAME", "Germany")) +image = landsat7.clipToCollection(fc) +m.add_layer( + image, + {"bands": ["B4", "B3", "B2"], "min": 20, "max": 200, "gamma": 2.0}, + "Landsat 7", +) +m.center_object(fc, 6) +m +``` + ### Visualizing Feature Collections Once loaded, feature collections can be visualized on an interactive map. For example, visualizing U.S. state boundaries from the census data: @@ -2958,6 +2981,71 @@ fig +++ +## Exercises + +### Exercise 1: Visualizing DEM Data + +Find a DEM dataset in the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) and clip it to a specific area (e.g., your country, state, or city). Display it with an appropriate color palette. For example, the sample map below shows the DEM of the state of Colorado. + +![](https://i.imgur.com/OLeSt7n.png) + +```{code-cell} ipython3 + +``` + +### Exercise 2: Cloud-Free Composite with Sentinel-2 or Landsat + +Use Sentinel-2 or Landsat-9 data to create a cloud-free composite for a specific year in a region of your choice. + +Use [Sentinel-2](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED) or [Landsat-9 data](https://developers.google.com/earth-engine/datasets/catalog/landsat-9) data to create a cloud-free composite for a specific year in a region of your choice. Display the imagery on the map with a proper band combination. For example, the sample map below shows a cloud-free false-color composite of Sentinel-2 imagery of the year 2021 for the state of Colorado. + +![](https://i.imgur.com/xkxpkS1.png) + +```{code-cell} ipython3 + +``` + +### Exercise 3: Visualizing NAIP Imagery + +Use [NAIP](https://developers.google.com/earth-engine/datasets/catalog/USDA_NAIP_DOQQ) imagery to create a cloud-free imagery for a U.S. county of your choice. For example, the sample map below shows a cloud-free true-color composite of NAIP imagery for Knox County, Tennessee. Keep in mind that there might be some counties with the same name in different states, so make sure to select the correct county for the selected state. + +![](https://i.imgur.com/iZSGqGS.png) + +```{code-cell} ipython3 + +``` + +### Exercise 4: Visualizing Watershed Boundaries + +Visualize the [USGS Watershed Boundary Dataset](https://developers.google.com/earth-engine/datasets/catalog/USGS_WBD_2017_HUC04) with outline color only, no fill color. + +![](https://i.imgur.com/PLlNFq3.png) + +```{code-cell} ipython3 + +``` + +### Exercise 5: Visualizing Land Cover Change + +Use the [USGS National Land Cover Database](https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2019_REL_NLCD) and [US Census States](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States) to create a split-panel map for visualizing land cover change (2001-2019) for a US state of your choice. Make sure you add the NLCD legend to the map. + +![](https://i.imgur.com/Au7Q5Ln.png) + +```{code-cell} ipython3 + +``` + +### Exercise 6: Creating a Landsat Timelapse Animation + +Generate a timelapse animation using Landsat data to show changes over time for a selected region. + +![Spain](https://github.com/user-attachments/assets/f12839c0-1c30-404d-b0ab-0fa12ce12d24) + +```{code-cell} ipython3 + +``` + + ## Summary This lecture introduced **geemap**, a Python library designed to streamline geospatial data visualization and analysis in the **Google Earth Engine (GEE)** environment. Geemap enables users to perform GIS and remote sensing tasks with GEE data interactively in Python notebooks. Key topics included setting up GEE with geemap, loading and manipulating data from the Earth Engine Data Catalog, and processing vector and raster data. Techniques for creating animated timelapses using data from Landsat, Sentinel, MODIS, and GOES illustrated dynamic landscape monitoring, while interactive charting tools, like scatter plots and time series, supported data exploration and trend analysis. The lecture also covered exporting images and features in multiple formats, such as GeoTIFF, Shapefile, and CSV, to facilitate data sharing. Overall, this session provided a foundational understanding of geemap's capabilities, enabling users to efficiently visualize, analyze, and derive insights from Earth observation data in a Python setting. diff --git a/book/labs/lab_09.ipynb b/book/labs/lab_09.ipynb new file mode 100644 index 0000000..96df44d --- /dev/null +++ b/book/labs/lab_09.ipynb @@ -0,0 +1,160 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab 9\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/giswqs/geog-312/blob/main/book/labs/lab_09.ipynb)\n", + "\n", + "## Overview\n", + "\n", + "This lab introduces Google Earth Engine (GEE) for accessing and analyzing geospatial data in Python. You will explore diverse data types, including DEM, satellite imagery, and land cover datasets. You’ll gain experience creating cloud-free composites, visualizing temporal changes, and generating animations for time-series data.\n", + "\n", + "\n", + "## Objectives\n", + "\n", + "By completing this lab, you will be able to:\n", + "\n", + "1. Access and visualize Digital Elevation Model (DEM) data for a specific region.\n", + "2. Generate cloud-free composites from Sentinel-2 or Landsat imagery for a specified year.\n", + "3. Visualize National Agricultural Imagery Program (NAIP) data for U.S. counties.\n", + "4. Display watershed boundaries using Earth Engine styling.\n", + "5. Visualize land cover changes over time using split-panel maps.\n", + "6. Create a time-lapse animation for land cover changes over time in a region of your choice.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 1: Visualizing DEM Data\n", + "\n", + "Find a DEM dataset in the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) and clip it to a specific area (e.g., your country, state, or city). Display it with an appropriate color palette. For example, the sample map below shows the DEM of the state of Colorado.\n", + "\n", + "![](https://i.imgur.com/OLeSt7n.png)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 2: Cloud-Free Composite with Sentinel-2 or Landsat\n", + "\n", + "Use Sentinel-2 or Landsat-9 data to create a cloud-free composite for a specific year in a region of your choice.\n", + "\n", + "Use [Sentinel-2](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED) or [Landsat-9 data](https://developers.google.com/earth-engine/datasets/catalog/landsat-9) data to create a cloud-free composite for a specific year in a region of your choice. Display the imagery on the map with a proper band combination. For example, the sample map below shows a cloud-free false-color composite of Sentinel-2 imagery of the year 2021 for the state of Colorado. \n", + "\n", + "![](https://i.imgur.com/xkxpkS1.png)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 3: Visualizing NAIP Imagery\n", + "\n", + "Use [NAIP](https://developers.google.com/earth-engine/datasets/catalog/USDA_NAIP_DOQQ) imagery to create a cloud-free imagery for a U.S. county of your choice. For example, the sample map below shows a cloud-free true-color composite of NAIP imagery for Knox County, Tennessee. Keep in mind that there might be some counties with the same name in different states, so make sure to select the correct county for the selected state.\n", + "\n", + "![](https://i.imgur.com/iZSGqGS.png)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 4: Visualizing Watershed Boundaries\n", + "\n", + "Visualize the [USGS Watershed Boundary Dataset](https://developers.google.com/earth-engine/datasets/catalog/USGS_WBD_2017_HUC04) with outline color only, no fill color.\n", + "\n", + "![](https://i.imgur.com/PLlNFq3.png)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 5: Visualizing Land Cover Change\n", + "\n", + "Use the [USGS National Land Cover Database](https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2019_REL_NLCD) and [US Census States](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States) to create a split-panel map for visualizing land cover change (2001-2019) for a US state of your choice. Make sure you add the NLCD legend to the map.\n", + "\n", + "![](https://i.imgur.com/Au7Q5Ln.png)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 6: Creating a Landsat Timelapse Animation\n", + "\n", + "Generate a timelapse animation using Landsat data to show changes over time for a selected region.\n", + "\n", + "![Spain](https://github.com/user-attachments/assets/f12839c0-1c30-404d-b0ab-0fa12ce12d24)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "geo", + "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.12.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/book/labs/lab_09.md b/book/labs/lab_09.md new file mode 100644 index 0000000..1c14f05 --- /dev/null +++ b/book/labs/lab_09.md @@ -0,0 +1,96 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.16.4 +kernelspec: + display_name: geo + language: python + name: python3 +--- + +# Lab 9 + +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/giswqs/geog-312/blob/main/book/labs/lab_09.ipynb) + +## Overview + +This lab introduces Google Earth Engine (GEE) for accessing and analyzing geospatial data in Python. You will explore diverse data types, including DEM, satellite imagery, and land cover datasets. You’ll gain experience creating cloud-free composites, visualizing temporal changes, and generating animations for time-series data. + + +## Objectives + +By completing this lab, you will be able to: + +1. Access and visualize Digital Elevation Model (DEM) data for a specific region. +2. Generate cloud-free composites from Sentinel-2 or Landsat imagery for a specified year. +3. Visualize National Agricultural Imagery Program (NAIP) data for U.S. counties. +4. Display watershed boundaries using Earth Engine styling. +5. Visualize land cover changes over time using split-panel maps. +6. Create a time-lapse animation for land cover changes over time in a region of your choice. + ++++ + +## Exercise 1: Visualizing DEM Data + +Find a DEM dataset in the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets) and clip it to a specific area (e.g., your country, state, or city). Display it with an appropriate color palette. For example, the sample map below shows the DEM of the state of Colorado. + +![](https://i.imgur.com/OLeSt7n.png) + +```{code-cell} ipython3 + +``` + +## Exercise 2: Cloud-Free Composite with Sentinel-2 or Landsat + +Use Sentinel-2 or Landsat-9 data to create a cloud-free composite for a specific year in a region of your choice. + +Use [Sentinel-2](https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR_HARMONIZED) or [Landsat-9 data](https://developers.google.com/earth-engine/datasets/catalog/landsat-9) data to create a cloud-free composite for a specific year in a region of your choice. Display the imagery on the map with a proper band combination. For example, the sample map below shows a cloud-free false-color composite of Sentinel-2 imagery of the year 2021 for the state of Colorado. + +![](https://i.imgur.com/xkxpkS1.png) + +```{code-cell} ipython3 + +``` + +## Exercise 3: Visualizing NAIP Imagery + +Use [NAIP](https://developers.google.com/earth-engine/datasets/catalog/USDA_NAIP_DOQQ) imagery to create a cloud-free imagery for a U.S. county of your choice. For example, the sample map below shows a cloud-free true-color composite of NAIP imagery for Knox County, Tennessee. Keep in mind that there might be some counties with the same name in different states, so make sure to select the correct county for the selected state. + +![](https://i.imgur.com/iZSGqGS.png) + +```{code-cell} ipython3 + +``` + +## Exercise 4: Visualizing Watershed Boundaries + +Visualize the [USGS Watershed Boundary Dataset](https://developers.google.com/earth-engine/datasets/catalog/USGS_WBD_2017_HUC04) with outline color only, no fill color. + +![](https://i.imgur.com/PLlNFq3.png) + +```{code-cell} ipython3 + +``` + +## Exercise 5: Visualizing Land Cover Change + +Use the [USGS National Land Cover Database](https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD_RELEASES_2019_REL_NLCD) and [US Census States](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2018_States) to create a split-panel map for visualizing land cover change (2001-2019) for a US state of your choice. Make sure you add the NLCD legend to the map. + +![](https://i.imgur.com/Au7Q5Ln.png) + +```{code-cell} ipython3 + +``` + +## Exercise 6: Creating a Landsat Timelapse Animation + +Generate a timelapse animation using Landsat data to show changes over time for a selected region. + +![Spain](https://github.com/user-attachments/assets/f12839c0-1c30-404d-b0ab-0fa12ce12d24) + +```{code-cell} ipython3 + +```