Before starting, make sure you understand these terms. They appear throughout all code blocks in this course.
| Term | Full Name | What it means in simple words |
|---|---|---|
| DEM | Digital Elevation Model | A 3D representation of a terrain's surface. |
| SRTM | Shuttle Radar Topography Mission | An international research effort to obtain digital elevation models on a near-global scale. |
| Floodplain | Floodplain | A flat area of land near a river or stream that is subject to flooding. |
| Threshold | Threshold | A level or value above which something is true or will take place. |
| Aspect | Aspect | The compass direction that a slope faces. |
| Flow Accumulation | Flow Accumulation | The number of cells that flow into each cell in a raster. |
| Flow Direction | Flow Direction | The direction of flow out of each cell in a raster. |
| Google Earth Engine | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| Remote Sensing | Remote Sensing | Acquiring information about an object or area from a distance, typically from aircraft or satellites. |
| Hydrology | Hydrology | The study of the movement, distribution, and quality of water on Earth. |
| Topography | Topography | The arrangement of the natural and artificial physical features of an area. |
| DeepSeek | DeepSeek | Large Language Model for code generation, used for automating geospatial tasks. |
| NDWI | Normalized Difference Water Index | A remote sensing index used to delineate open water features and enhance their presence in remotely sensed imagery. |
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.
USGS/SRTMGL1_003You need two browser tabs open side by side throughout this course.
Course21_River Floodplain Mapping with SRTM and DeepSeek
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.
Paste the following code into your GEE code editor and click Run. Read the beginner notes below to understand what each line does.
// 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');
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// 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');
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 the floodplain as a GeoTIFF
Export.image.toDrive({
image: refinedFloodplain,
description: 'Floodplain_Rif_Morocco',
folder: 'GEE_Exports',
scale: 30,
region: roi,
maxPixels: 1e9
});
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.
To get the best results from DeepSeek for GEE tasks, always include these elements in your prompts:
| Element | Example |
|---|---|
| Exact dataset ID | USGS/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" |