Spatial query of raster data using QGIS

If you are familiar with R, you could also solve this problem with your favourite R editor, which is easy as pie.

For example like this:

library(raster);library(rgdal)

ras <- raster(...)
pol <- readOGR(...)

extraction <- extract(ras,pol)
statistics <- lapply(extraction,table)
# Further analyze the data (mean, sum per polygon feature or sth. like that)

BTW: I am currently writing a new function for a qgis-plugin of mine, which could exactly do what you want. However, it could still take a bit until it is ready (in fact I first need to solve the following problem).


You could use the GRASS module v.rast.stats, which calculates univariate statistics from a raster map based on vector polygons and uploads the statistics to new attribute columns.

The v.rast.stats2 module is an optimised version that might be more suitable if you are working with large datasets.

Starspan is another option that allows one to do spatial analysis of raster data using vector features.