Code & tools

NDVI Zonal Statistics

A vegetation image shows variation across a landscape, but comparing named areas also needs a table. I wrote this Google Earth Engine workflow to calculate NDVI from Sentinel 2 imagery and summarise it for city polygons. It connects the mapped pattern with a value that can be reviewed alongside other information about each city.

Source imagery
Sentinel 2
Summary
Mean NDVI by city polygon
Reduction scale
10 metres
Tools
Google Earth Engine, JavaScript, Sentinel 2, NDVI

From satellite images to city summaries

I select images for the chosen area and dates, calculate NDVI from the near infrared and red bands, B8 and B4, and combine the NDVI images into a median image. I clip the result to the area of interest and use reduceRegions to calculate a mean for each city at a 10 metre reduction scale.

The script displays the vegetation index image and exports the polygon summaries to Google Drive. Those outputs let a reader inspect both the variation within an area and the average assigned to it.

What the values represent

NDVI describes the contrast between near infrared and red reflectance. It can help examine vegetation patterns, but a city average combines different land covers and conceals variation within the boundary. It is not a direct measure of tree canopy area or a diagnosis of vegetation health.

The published script sorts images by reported cloud percentage but does not remove cloudy images or mask cloudy pixels. Sorting does not clean the median composite. I would add cloud filtering and masking, inspect the resulting image and keep the seasonal window consistent before using the values for comparisons between places or dates.

Data and references

Get in touch

I’m looking for GIS opportunities across Canada. You can reach me by email or on LinkedIn.