I'm new to this and haven't been able to figure out how to do this on my own.

I have two files: a raster image of land use data and a vector-based shapefile of my territories.

The raster image has values like so: 11 = water, 21 = developed - open, 22 = developed - low, 23 = developed - medium, 41 = forest, 71 = grassland, 82 = cultivated crop, etc. Overall, I've got about 30 distinct values. The resolution of this image is pretty big (1m squares, I think) and the filesize is about 16 gigs.

I was to add a set of columns to my shapefile, one new column for each of the possible land use values. The column names would be like so: value_11, value_21, vaule_22, value_23, etc. Then I'd like to sum up the number of pixels in each shape that correspond to each value. So, if there are 1200 pixels that have a value of 11, then column value_11 would have 1200 in it.

I've used qgis to get the vector and raster files to load at the same time and they're georeffed correctly. It displays beautifully.

I'm not sure if I'm making this clear, but I'd like a count for every combination of each vector-based polygon and the unique values from the raster image within that polygon. If I need to do this in multiple passes, that's fine.

Using qgis, I was able to get average/median/mode/min/max of raster values within each polygon, but that's useless to me. I need the count of each distinct land use value. Eventually, I want to load the final shapefile into SQL Server 2008 and be able to write queries against it. I'd like to take a series of points, find out which polygon they are in, and determine how many water, developed, forest, etc. pixels are in that polygon.

Regarding software, I've played with several free/open source programs (such as QGIS, SAGA, etc), but I just don't know enough about what I'm trying to do to get anything to work. I can download whatever I might need, but I don't have a budget, so if ARCGIS or something expensive is the only way to do this, then I'm out of luck. Once I get the shapefile created, I can get it back into SQLServer and I can write the queries there to do what I want. I just need to get build the shapefile with the land use data added to it.


5 Answers 5


For GRASS GIS Zonal statistics, see http://grasswiki.osgeo.org/wiki/Zonal_statistics

It looks as if you want to use "v.vect.stats": count points in areas, calculate statistics from point attributes (needs GRASS 7).


If the raster cell value does indeed contain land use data then you are able to sample the value to a Vector layer with GRASS.

I haven't used this method but it should work something like:

First modify your vector table structure to suit your purpose in QGIS Use the GRASS plugin, create mapset for your area Load the data into Grass (v.in.ogr.qgis, r.in.gdal.qgis) Sample the raster cells using v.sample into you vector table columns Export vector to shapefile (v.out.ogr)


I think you are looking for a way that similar to Arcmap's Zonal Statistics function.

Not sure if you were familiar with Postgis or not. But Postgis dose support the Zonal Statistics function. Based on the documentation I found from Postgis' website:

"ST_SummaryStats — Returns summary stats consisting of count,sum,mean,stddev,min,max for a given raster band of a raster or raster coverage. Band 1 is assumed is no band is specified."

There is an example on that page about "Summarize pixels that intersect buildings of interest" maybe helpful to you.

In terms to your budget, I would say Postgis and PostgreSQL database is completely free, so all you need is to invest some time on it.

Hope it is a useful option for solving your problem.


If you are using GRASS 6, r.statistics is what you want. If you rasterize your shapefile (with unique id's for each polygon) you can include it as the 'base' layer, with your land use raster as the 'cover' layer. GRASS zonal statistics will not work for what you want.

If you are using GRASS 7, r.report should work -- see the example in the docs.


RastCats is a free software tool that I wrote that does exactly what you describe. There is a video here https://www.youtube.com/watch?v=OlWAI36iO8I&t=16s (currently over 2500 views). You can download the software for Windows here: https://github.com/gakrakow/rastcats/releases. It does not require any external software or licences. It is set up to use data from Georgia, USA, but it is fairly easy to set up to use with any land cover data set. I wrote this program several years ago because, even though it seems to be a rather simple procedure, I could not find any other software that easily did this sort of thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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