Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an NDVI


A Normalized Difference Vegetation Index (NDVI) is one of the oldest remote sensing algorithms used to detect green vegetation in an area of interest, using the red and near-infrared bands of an image. The chlorophyll in plants absorbs visible light, including the red band, while the cell structures of plants reflect near-infrared light. The NDVI formula provides a ratio of near-infrared light to the total incoming radiation, which serves as an indicator of vegetation density. This recipe will use Python to control the QGIS raster calculator in order to create an NDVI using a multispectral image of a farm field.

Getting ready

Download the image from https://geospatialpython.googlecode.com/svn/farm-field.tif and place it in your qgis_data to a directory named rasters.

How to do it...

We will load the raster as a QGIS raster layer, perform the NDVI algorithm, and finally apply a color ramp to the raster so that we can easily visualize the green vegetation in the image. To do this...