GEE Tutorials

Google Earth Engine Tutorial: Download NDWI Images from Landsat 8

Credit: Youtube Channel “Terra Spatial, Tutorial on downloading Normalized Difference Water Index images for water body mapping and monitoring.”

You can see all the tutorials from here: Techgeo Academy.

Google Earth Engine Tutorial: Download NDWI Images from Landsat 8 using Google Earth Engine

Google Earth Engine (GEE) is a powerful platform for analyzing and visualizing geospatial data. This tutorial will guide you through the process of downloading Normalized Difference Water Index (NDWI) images from Landsat 8 data using GEE. The NDWI is calculated using the green and near-infrared (NIR) bands to highlight water bodies.

Step 1: Initialize Google Earth Engine

Before you begin, you need to have a GEE account. Sign in to the Google Earth Engine Code Editor. Then, initialize the GEE API by running the following code:


// Initialize Earth Engine
ee.Authenticate();
// Load the Earth Engine library
var ee = require('@google-cloud/earthengine');
ee.Initialize();

Step 2: Load Landsat 8 Data

Landsat 8 data is accessible via the LANDSAT/LC08/C02/T1_L2 dataset. Load the relevant data for your study area and time range:


// Load Landsat 8 surface reflectance data
var dataset = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2023-01-01', '2023-12-31')
.filter(ee.Filter.lt('CLOUD_COVER', 10))
.filter(ee.Filter.geometry(ee.Geometry.Rectangle([your_longitude_min, your_latitude_min, your_longitude_max, your_latitude_max])));

Step 3: Calculate NDWI

The NDWI formula is: (Green Band – NIR Band) / (Green Band + NIR Band). For Landsat 8, use bands 3 (Green) and 4 (NIR):


// Compute NDWI
var ndwi = dataset.map(function(image) {
return image
.select(['SR_B3', 'SR_B4'])
.reduce(ee.Reducer.multiNormalize())
.rename('NDWI');
});

Step 4: Visualize and Export NDWI Image

Select a specific image from the collection, visualize it, and export it as a GeoTIFF file:


// Select the first image in the collection
var image = ndwi.first();
// Visualize the NDWI
Map.addLayer(image, {min: -1, max: 1, palette: ['blue', 'white', 'green']}, 'NDWI');
// Export the image
Export.image.toDrive({
image: image,
description: 'NDWI_Landsat8',
folder: 'GEE_Exports',
fileNamePrefix: 'NDWI',
region: image.geometry(),
scale: 30,
fileFormat: 'GeoTIFF',
maxPixels: 1e10
});

Step 5: Download the Exported File

After the export task completes, you will find the file in your Google Drive under the specified folder. You can download it to your local machine for further analysis.

FAQ

How do I choose the correct bands for NDWI?

The NDWI formula typically uses the green (band 3) and near-infrared (band 4) bands in Landsat 8. Adjust the band indices if you are using other sensors or datasets.

Why is atmospheric correction important for NDWI?

Atmospheric correction ensures accurate surface reflectance values, which are critical for reliable water index calculations. Landsat 8 Surface Reflectance (SR) data already includes this correction.

What if I want to automate this process for multiple dates?

You can modify the code to iterate over the image collection, calculate NDWI for each image, and export them in a loop. Use dataset.toList or dataset.evaluate to manage batch exports.

How can I handle large datasets when exporting?

Set the maxPixels parameter appropriately, and consider reducing the spatial resolution or trimming the region of interest to fit within GEE’s processing limits.

Can I use this method for other satellites or indexes?

Yes, adapt the band selection and formula for other satellites (e.g., Sentinel-2) or indexes (e.g., NDVI, NDVI2). Ensure the dataset supports surface reflectance or top-of-atmosphere data as needed.

What if I encounter an error during export?

Check the Tasks tab in the Code Editor for details. Common issues include incorrect geometry, over-allocated pixels, or missing authentication. Verify your parameters and ensure your GEE account is properly set up.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *