Google Earth Engine Tutorial: Beginners Guide 5 NDVI Analysis with Landsat 8
Credit: Youtube Channel “Terra Spatial, Tutorial on calculating and analyzing Normalized Difference Vegetation Index using Landsat 8 data for vegetation monitoring.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine Tutorial: Beginners Guide 5 NDVI Analysis with Landsat 8
Welcome to this comprehensive tutorial on performing NDVI analysis using Landsat 8 data in Google Earth Engine. This guide will walk you through the entire process from loading data to visualizing results.
What is NDVI?
The Normalized Difference Vegetation Index (NDVI) is one of the most commonly used indices for vegetation analysis. It uses the red and near-infrared spectral bands to quantify vegetation health and density.
Getting Started with Google Earth Engine
Before we begin, ensure you have a Google account and access to Google Earth Engine Code Editor at code.earthengine.google.com.
Loading Landsat 8 Data
First, we need to load the Landsat 8 Surface Reflectance collection:
// Load Landsat 8 Surface Reflectance collection
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2020-01-01', '2020-12-31')
.filterBounds(geometry)
.filter(ee.Filter.lt('CLOUD_COVER', 20));
Selecting the Best Image
We’ll use the median composite approach to reduce cloud cover effects:
// Create a median composite
var image = collection.median();
// Select the required bands (Red and NIR)
var red = image.select('SR_B4');
var nir = image.select('SR_B5');
Calculating NDVI
The NDVI formula is: (NIR – Red) / (NIR + Red)
// Calculate NDVI
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
// Alternative method using normalizedDifference
var ndviAlt = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI');
Visualizing Results
Let’s set up visualization parameters for our NDVI results:
// Define visualization parameters
var ndviParams = {
min: -1,
max: 1,
palette: ['blue', 'white', 'green']
};
// Add the NDVI layer to the map
Map.addLayer(ndvi, ndviParams, 'NDVI');
// Center the map
Map.centerObject(geometry, 10);
Creating Statistics
We can calculate basic statistics for our NDVI results:
// Calculate NDVI statistics
var stats = ndvi.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geometry,
scale: 30,
maxPixels: 1e9
});
print('Mean NDVI:', stats.get('NDVI'));
Advanced Analysis: Time Series
For more comprehensive analysis, let’s create a time series chart:
// Create time series chart
var chart = ui.Chart.image.series({
imageCollection: collection.select('SR_B5', 'SR_B4'),
region: geometry,
reducer: ee.Reducer.mean(),
scale: 30,
xProperty: 'system:time_start'
}).setOptions({title: 'Landsat 8 NDVI Time Series'});
print(chart);
Exporting Results
Finally, let’s export our NDVI results:
// Export the result to Google Drive
Export.image.toDrive({
image: ndvi,
description: 'NDVI_Landsat8',
folder: 'GEE_Export',
region: geometry,
scale: 30,
maxPixels: 1e13
});
Complete Script Summary
Here’s the complete working script:
// Define your area of interest
var geometry = ee.Geometry.Rectangle([-122.5, 37.5, -122.0, 38.0]);
// Load Landsat 8 collection
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2020-06-01', '2020-09-30')
.filterBounds(geometry)
.filter(ee.Filter.lt('CLOUD_COVER', 20));
// Create median composite
var image = collection.median();
// Calculate NDVI
var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI');
// Visualization parameters
var ndviParams = {
min: -1,
max: 1,
palette: ['blue', 'white', 'green']
};
// Add layers to map
Map.addLayer(image, {bands: ['SR_B4', 'SR_B3', 'SR_B2'], min: 0, max: 0.3}, 'RGB');
Map.addLayer(ndvi, ndviParams, 'NDVI');
Map.centerObject(geometry, 10);
// Print statistics
var stats = ndvi.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geometry,
scale: 30,
maxPixels: 1e9
});
print('Mean NDVI:', stats.get('NDVI'));
Tips for Success
- Always filter by cloud cover to get better quality images
- Use median composites to reduce noise and cloud effects
- Consider the temporal resolution of Landsat 8 (16 days)
- Choose appropriate scale values for your analysis area
- Test different visualization palettes to best represent your data
Frequently Asked Questions
What is the best time period for NDVI analysis?
For most regions, summer months (June-September in Northern Hemisphere) provide the best vegetation coverage. However, the optimal period depends on your local growing season and vegetation patterns.
How do I handle cloud cover in Landsat 8 images?
You can filter by the CLOUD_COVER property, use median composites to reduce cloud impact, or use cloud masking functions available in Earth Engine to remove cloud-covered pixels.
What’s the difference between Landsat 8 Collection 1 and Collection 2?
Collection 2 provides improved calibration, geometric accuracy, and surface reflectance processing. Always prefer Collection 2 (C02) over Collection 1 for better data quality.
Why are my NDVI values outside the -1 to 1 range?
This usually indicates issues with data preprocessing. Ensure you’re using surface reflectance data and that your calculations are properly normalized. Check for data gaps or processing artifacts.
Can I use other satellite data for NDVI analysis?
Yes, you can use Sentinel-2, MODIS, or other multispectral sensors. Each has different band specifications, so you’ll need to adjust the band selections accordingly.
How do I improve the visualization quality of my NDVI map?
Experiment with different color palettes, adjust the min/max values to focus on the range of interest, and consider applying histogram equalization or other enhancement techniques.
What scale should I use for my analysis?
Landsat 8 has a native resolution of 30 meters. Use this scale for most land cover analyses. For regional studies, you can aggregate to coarser resolutions, but avoid using scales finer than 30 meters to prevent false precision.
How do I validate my NDVI results?
Ground truth data from field measurements or higher-resolution imagery is ideal. You can also compare with other vegetation indices or use cross-validation with different time periods.