Calculating Spectral Indices - NDVI and NDWI with Sentinel-2 in GEE

Remote sensing is a powerful tool in environmental monitoring and analysis. With the advent of platforms like Google Earth Engine (GEE), accessing and analyzing satellite data has become more accessible than ever. In this blog, we'll dive into how to calculate two vital spectral indices - the Normalized Difference Vegetation Index (NDVI) and the Normalized Difference Water Index (NDWI) - using Sentinel-2 data in GEE. We'll explain each part of the code to provide a clear understanding of the process.




GEE Code : https://code.earthengine.google.com/bc3e90b905aebbe2fd2d807289ef8fe3

Setting the Region of Interest (ROI)



Here, we define our region of interest (ROI) as Perambalur. This area is specified using a FeatureCollection from Earth Engine's assets.

Visualization Parameters



These are visualization parameters for NDVI and NDWI, respectively. They define the opacity, bands to use, min/max values for the color stretch, and the color palette for visualization on the map.

Cloud Masking Function



This function masks clouds in Sentinel-2 images. It uses the QA60 band to identify and mask out clouds and cirrus.

Loading and Preprocessing the Data


This block loads the Sentinel-2 Surface Reflectance Harmonized data. It filters the images by the ROI, date, and cloud cover, applies the cloud mask, and then computes the median image. This approach reduces the impact of clouds and atmospheric variability.

Visualization on the Map



This line adds the processed Sentinel-2 image to the map with the specified visualization parameters, allowing us to see the true-color representation of the area.

Calculating NDVI



NDVI is calculated using the formula (NIR - RED) / (NIR + RED). NIR and RED bands are selected from the dataset, and the calculation is performed pixel-wise.

Adding NDVI Layer to the Map


The calculated NDVI layer is added to the map with the predefined visualization parameters.

Calculating NDWI



NDWI is calculated using the formula (Green - NIR) / (Green + NIR). The green and NIR bands are selected for this computation.

Adding NDWI Layer to the Map


Similar to NDVI, the NDWI layer is added to the map for visualization.

Exporting the Data



Finally, this code exports the processed image to Google Drive in GeoTIFF format. It includes various parameters like the description, folder, region, scale, and others to control the export.

Conclusion

The ability to calculate indices like NDVI and NDWI using platforms like Google Earth Engine opens up vast opportunities for environmental monitoring and research. NDVI is widely used for assessing vegetation health, while NDWI is crucial for water body analysis. By mastering these techniques, researchers and enthusiasts can contribute significantly to the understanding and conservation of our environment.

Comments