Practical Course 21

River Floodplain Mapping with SRTM and DeepSeek

Learn to delineate floodplains using elevation data and AI to understand flood risk zones.
North Morocco ~2 hours Master - Climate Change and GeoAI
Dataset: USGS/SRTMGL1_003 Shuttle Radar Topography Mission (SRTM) Digital Elevation Model

📖 Key Terms for Beginners

Before starting, make sure you understand these terms. They appear throughout all code blocks in this course.

TermFull NameWhat it means in simple words
DEMDigital Elevation ModelA 3D representation of a terrain's surface.
SRTMShuttle Radar Topography MissionAn international research effort to obtain digital elevation models on a near-global scale.
FloodplainFloodplainA flat area of land near a river or stream that is subject to flooding.
ThresholdThresholdA level or value above which something is true or will take place.
AspectAspectThe compass direction that a slope faces.
Flow AccumulationFlow AccumulationThe number of cells that flow into each cell in a raster.
Flow DirectionFlow DirectionThe direction of flow out of each cell in a raster.
Google Earth EngineGoogle Earth EngineA cloud-based platform for planetary-scale geospatial analysis.
Remote SensingRemote SensingAcquiring information about an object or area from a distance, typically from aircraft or satellites.
HydrologyHydrologyThe study of the movement, distribution, and quality of water on Earth.
TopographyTopographyThe arrangement of the natural and artificial physical features of an area.
DeepSeekDeepSeekLarge Language Model for code generation, used for automating geospatial tasks.
NDWINormalized Difference Water IndexA remote sensing index used to delineate open water features and enhance their presence in remotely sensed imagery.

Contents

  1. Introduction to Floodplain Mapping
  2. Introduction to SRTM DEM
  3. Accessing SRTM Data in GEE
  4. Terrain Analysis: Slope and Flow Accumulation
  5. Floodplain Delineation using Thresholding
  6. Refining Floodplains with NDWI
  7. Automating with DeepSeek
  8. Visualizing Results
  9. Accuracy Assessment
  10. Exporting Floodplain Maps
1
Introduction
10 min

Floodplain mapping is crucial for understanding and mitigating flood risks, particularly in areas prone to heavy rainfall and river overflow. This course will guide you through using SRTM DEM data within Google Earth Engine to delineate floodplains. We'll also explore how to use DeepSeek to automate parts of the process.

GEE Asset ID
USGS/SRTMGL1_003
Dataset Name
Shuttle Radar Topography Mission (SRTM) Digital Elevation Model
Study Area
North Morocco
AI Tool
DeepSeek (free, no API key needed)
🌍
What you will build: By the end of this course you will have a working GEE script that analyzes River Floodplain Mapping with SRTM and DeepSeek, computes statistics, visualizes results on an interactive map, and exports data to Google Drive.

2
Setup: GEE + DeepSeek
5 min

You need two browser tabs open side by side throughout this course.

1
Open chat.deepseek.com -- free account, no API key needed
2
Open code.earthengine.google.com in a second tab
3
Create a new GEE script named Course21_River Floodplain Mapping with SRTM and DeepSeek
💡
Workflow: Write a prompt in DeepSeek describing your task with exact dataset IDs and requirements. Copy the generated GEE JavaScript. Paste into GEE code editor. Click Run. Inspect results. Iterate.

3
Crafting the DeepSeek Prompt
15 min

The prompt is the core skill of this course. A good prompt includes the exact dataset ID, band names, study area coordinates, dates, preprocessing steps, and desired outputs.

📋 Main Prompt -- copy and paste this into DeepSeek
Write a Google Earth Engine JavaScript code to delineate floodplains in the Rif Mountains, Morocco, using the 'USGS/SRTMGL1_003' dataset. Calculate flow accumulation from the SRTM DEM. Apply a threshold to the flow accumulation to identify potential floodplains. Refine the floodplain by calculating the Normalized Difference Water Index (NDWI) using Sentinel-2 imagery (COPERNICUS/S2_SR) from 2023-01-01 to 2023-03-01. Use bands 'B3' and 'B8' for NDWI. Filter Sentinel-2 imagery by cloud cover less than 10%. Mask out areas with NDWI less than 0. Display the resulting floodplain as a red polygon. Add a legend to the map.
✨
After pasting the prompt: Wait 20-30 seconds for DeepSeek to generate the full GEE script. Copy the entire code block it produces. If the output is cut short, type "Continue the code" to get the rest.

4
Accessing and Preparing SRTM Data
10 min

Paste the following code into your GEE code editor and click Run. Read the beginner notes below to understand what each line does.

Accessing and Preparing SRTM Data
// Define the region of interest (Rif Mountains, Morocco)
var roi = ee.Geometry.Rectangle([-5.5, 34.5, -3.5, 35.5]);

// Access the SRTM DEM dataset
var dem = ee.Image('USGS/SRTMGL1_003').clip(roi);

// Calculate slope
var slope = ee.Terrain.slope(dem);

// Calculate flow direction
var flowDirection = ee.Terrain.flowDirection(dem);

// Calculate flow accumulation
var flowAccumulation = ee.Terrain.flowAccumulation(flowDirection).clip(roi);

//Display the DEM
Map.addLayer(dem, {min: 0, max: 2000, palette: ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'FFFFFF']}, 'DEM');
🔑
Beginner note: This code block first defines a region of interest (ROI) in the Rif Mountains of Morocco. It then accesses the SRTM DEM dataset and clips it to the ROI. `ee.Terrain.slope()` calculates the slope. `ee.Terrain.flowDirection()` calculates the flow direction for each cell. `ee.Terrain.flowAccumulation()` calculates the flow accumulation based on the flow direction. Finally, the DEM is added to the map for visualization with a specified color palette.

5
Delineating Floodplains and Refining with NDWI
10 min

Add this block after the previous code. It continues the analysis with additional processing and visualization.

Delineating Floodplains and Refining with NDWI
// Define a threshold for flow accumulation (adjust as needed)
var threshold = 1000;

// Create a floodplain mask based on the threshold
var floodplain = flowAccumulation.gt(threshold).selfMask();

// Load Sentinel-2 imagery and filter by date and cloud cover
var sentinel2 = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterDate('2023-01-01', '2023-03-01')
  .filterBounds(roi)
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10));

// Calculate NDWI
var ndwi = sentinel2.map(function(image) {
  return image.normalizedDifference(['B3', 'B8']);
}).median().clip(roi);

// Mask out areas with NDWI less than 0
var refinedFloodplain = floodplain.updateMask(ndwi.gt(0));

// Display the floodplain
Map.addLayer(refinedFloodplain, {palette: 'red'}, 'Floodplain');
🔑
Beginner note: This block sets a threshold for flow accumulation to identify potential floodplain areas. Areas where flow accumulation exceeds the threshold are considered part of the floodplain. Then, Sentinel-2 imagery is loaded and filtered. The Normalized Difference Water Index (NDWI) is calculated using the 'B3' (Green) and 'B8' (NIR) bands. The floodplain is then refined by masking out areas where the NDWI is less than 0, effectively removing areas that are unlikely to be waterlogged. Finally, the delineated floodplain is displayed on the map in red.

6
Export Results to Google Drive
5 min

Add this block at the end of your script to export the final map as a GeoTIFF to your Google Drive. After clicking Run, go to the Tasks tab in GEE and click Run next to each export task.

Export to Google Drive
// Export the floodplain as a GeoTIFF
Export.image.toDrive({
  image: refinedFloodplain,
  description: 'Floodplain_Rif_Morocco',
  folder: 'GEE_Exports',
  scale: 30,
  region: roi,
  maxPixels: 1e9
});
🔑
Beginner note -- Export.image.toDrive(): This function does not export immediately. It creates a task in the GEE Tasks tab that you must manually start by clicking Run. The file will appear in your Google Drive folder (GEE_Courses) as a GeoTIFF that you can open in QGIS or ArcGIS.

7
Exercises Using DeepSeek Prompts
Homework

Use DeepSeek to extend the script for each exercise below. Write a follow-up prompt describing what you want to add, then copy the generated code and paste it into your GEE script.

Adjusting Flow Accumulation Threshold

  1. Experiment with different flow accumulation threshold values (e.g., 500, 2000).
  2. Observe how the floodplain area changes with different thresholds.

Exploring Different Regions

  1. Change the region of interest to a different river basin in Morocco.
  2. Run the code and compare the floodplain delineation results.

Analyzing Different Time Periods

  1. Modify the date range for the Sentinel-2 imagery.
  2. Observe how the NDWI and refined floodplain change over time.

Using Different DEMs

  1. Explore other available DEM datasets in Google Earth Engine.
  2. Compare the floodplain delineation results using different DEMs.

8
Prompt Engineering Tips
Reference

To get the best results from DeepSeek for GEE tasks, always include these elements in your prompts:

ElementExample
Exact dataset IDUSGS/SRTMGL1_003
Band names"select band 'B4' for red, 'B8' for NIR"
Study area"rectangle [-6.5, 33.0, -1.5, 36.0] North Morocco"
Date range"filter from 2020-01-01 to 2023-12-31"
Output format"print area in hectares, add a legend, export to Drive"
Error fixing"The code gives error X. Please fix it."
Iteration"Add a time series chart for each year 2018-2023"
🧠
Best practice: Start with the main prompt, run the code, then send follow-up prompts to add features one at a time. This gives you cleaner, more reliable code than asking for everything at once.
Course 21 - River Floodplain Mapping with SRTM and DeepSeek | GeoAI for Climate Change | Dr. Ayoub Lahlouh | UM6P/CUS | 2025/2026