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

Counting the unique values in a raster


Remotely-sensed images are not just pictures; they are data. The value of the pixels has meaning that can be automatically analyzed by a computer. The ability to run statistical algorithms on a dataset is key to remote sensing. This recipe counts the number of unique combinations of pixels across multiple bands. A use case for this recipe will be to assess the results of image classification, which is a recipe that we'll cover later in this chapter. This recipe is in contrast to the typical histogram function, which totals the unique values and the frequency of each value per band.

Getting ready

We will use the SatImage raster available at https://geospatialpython.googlecode.com/files/SatImage.zip.

Place this raster in your /qgis_data/rasters directory.

How to do it...

This algorithm relies completely on the numpy module, which is included with PyQGIS. Numpy can be accessed through the GDAL package's gdalnumeric module. To do this, we need to perform the...