I have population distribution data as a raster layer and exposure contours as vector (polygon) layers. What I'd like to do is use the vector layer to estimate the population indicated from the raster layer that fall underneath the polygon.

It seems like a pretty standard request to perform spatial query using data like this but I can't find any obvious solution. Which probably means I'm doing it wrong or I've missed a paragraph from "GIS101" so no one has needed to ask before.

Can someone shed some light on this? Perhaps the raster data needs to be flipped into vector data first? Is there an option for this already built in and I need to RTFM?

If it isn't straight forward, I am not too bad with Python so I'd be more than comfortable writing something that does this.

Thanks inn advance, Dan

  • 3
    Normally this is trivial: it's a "zonal sum" operation, which totals values within disjoint polygonal regions. But you have two problems. First, your exposure contours are surely nested--they overlap greatly. Second, many of the contour lines probably are not closed, and therefore do not adequately represent "polygons" at all. If you possibly can, you should obtain a raster representation of exposure (this was likely used to generate the contours in the first place). Comparing the two rasters will yield a highly detailed plot of total population exposed versus exposure threshold. – whuber Nov 13 '12 at 18:16

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.

  • Very useful advice. I'll be sure to take a look at these – Dan Nov 14 '12 at 14:50

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

For example like this:


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).

  • +1 for the often overlooked, but incredibly powerful spatial statistics tools in R. – Aaron Nov 13 '12 at 20:37
  • I am familiar with R so this is extremely useful. However, I was hoping to have this as part of my plugin as well so I guess this will be my short term fix. – Dan Nov 14 '12 at 14:51
  • 1
    I've added something to your problem post. Not sure if it will be exactly what you are after. But if you want I'm happy to collaborate with you in solving both of these. They seem common and in need of a solid documented solution. – Dan Nov 14 '12 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.