This project demonstrates the use of Google Earth Engine (GEE) for extracting water surfaces by computing the Normalized Difference Water Index (NDWI) from Sentinel-2 imagery.
NDWI is an effective spectral index for mapping open water bodies, distinguishing them from surrounding vegetation and built-up areas.
Sentinel-2 surface reflectance data (COPERNICUS/S2_SR
) was filtered by region of interest (ROI), time period,
and cloud cover.
var roi = Roi;
var sentinel_Wet = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2022-06-01','2022-10-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
.filterBounds(roi);
The NDWI is calculated using the green band (B3) and the near-infrared band (B8) of Sentinel-2:
NDWI = (Green - NIR) / (Green + NIR)
var ndwi = sentinel_Wet.median().normalizedDifference(['B3', 'B8']).rename('NDWI');
Map.addLayer(ndwi, {min:-1, max:1, palette:['brown','white','blue']}, 'NDWI');
The NDWI values in Sentinel-2 typically range from -1 to 1. Water bodies usually have higher values, while vegetation and built-up areas are negative.
-0.1
was applied after testing multiple thresholds.
This value captured water surfaces effectively in the study area.
var water = ndwi.gt(-0.1);
Map.addLayer(water.updateMask(water), {palette:['blue']}, 'Water Mask');
The binary raster water mask was converted into polygons using reduceToVectors
. This makes
the results more versatile for GIS tasks such as area calculation or overlay with boundaries.
// Convert water mask raster to vector polygons
var vectors_wet = water.addBands(water).reduceToVectors({
geometry: roi,
scale: 12,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'Wet zone',
reducer: ee.Reducer.mean()
});
Map.addLayer(vectors_wet, {color: 'cyan'}, 'Water Vectors');
This workflow demonstrates how NDWI can be applied for water surface mapping in Google Earth Engine. The process involves:
The resulting vectors can be exported and used in further spatial analysis, environmental monitoring, or hydrological studies.
⬅ Back to Portfolio