Google Earth Engine Tutorial: Generate Annual Water Body Maps
Credit: Youtube Channel “Terra Spatial, Tutorial on creating annual surface water body maps using JRC water classification data.”
You can see all the tutorials from here: Techgeo Academy.
In this tutorial, we will walk through the process of generating annual water body maps using Google Earth Engine (GEE). By leveraging the Global Surface Water dataset, we can analyze and visualize changes in water bodies over time. Below are the steps and code examples to achieve this.
Step 1: Access the Global Surface Water Dataset
GEE provides the JRC Global Surface Water dataset, which includes information on the presence and permanence of water bodies. We can access this dataset with the following code:
var gsw = ee.Image('JRC/GSW1.2/GlobalSurfaceWater');
Step 2: Extract Annual Water Presence Data
To create annual maps, we need to process the dataset to extract water presence information. This involves defining a date range and using the `clip` and `select` functions:
var startDate = '2000-01-01';
var endDate = '2020-12-31';
var waterPresence = gsw.select('water');
var annualWater = ee.ImageCollection.fromImages(
ee.List.sequence(2000, 2020).map(function(year) {
return waterPresence
.clip(geometry)
.set('system:time_start', ee.Date.fromYMD(ee.Number(year), 1, 1).millis());
})
);
Step 3: Visualize the Maps
After creating the annual water body images, we can add them to the map and customize the visualization:
Map.addLayer(annualWater, {
min: 0,
max: 1,
palette: ['white', 'blue']
}, 'Annual Water Bodies');
Step 4: Export the Maps (Optional)
To save or share your results, export the annual water maps as GeoTIFF or PNG files. Use the `Export.image` function with specific parameters:
Export.image.toDrive({
image: annualWater,
description: 'AnnualWaterMaps',
folder: 'GEE_Exports',
fileNamePrefix: 'water_body_',
region: geometry,
scale: 10,
maxPixels: 1e10
});
FAQ
- Why does my code not run?
Ensure you have defined a valid geometry (e.g., a specific region or country outline) and have access to the dataset. Also, check for JavaScript syntax errors. - Can I use this for other regions?
Yes, replace the `geometry` variable with a region of interest (e.g., using `geometry = ee.Geometry.Rectangle([x1, y1, x2, y2])` or loading a shapefile). - How accurate is the Global Surface Water dataset?
The dataset provides high accuracy for large water bodies but may have limitations for small or seasonal water bodies in certain regions. - Can I generate maps for a specific month?
The dataset includes annual summaries, but it’s possible to extract monthly data by modifying the `system:time_start` parameter and adjusting the output accordingly. - What if I need data beyond 2020?
The JRC dataset is current up to 2020. Consider using other datasets like MODIS or Sentinel-1 if you require more recent data.