Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a vector layer containing thousands of vector shapes/polygons and a raster layer with DTM. Every shape has its own OBJECTID in attribute table. I would like to get the altitude of every shape, weighted mean of the altitude would be the best. I suppose there should be used a script or something similar to count weighted mean of altitude of all pixels inside the polygon. I use Qgis 1.7.3.

Thanks in advance.

share|improve this question

Also, you can try Zonal Statistics plugin (it's a core plugin, so no need to install it separately).

share|improve this answer

I would do it using the r.statistics (zonal statistics) GRASS module through QGIS/GRASS plugin.

share|improve this answer
Thank you, r.statistics is possibly the module I was searching for. But because I am new to Qgis, I have problem with opening my raster layer in r.statistics. Any hints? – Hanz Feb 13 '12 at 17:53
GRASS works with his own vector/raster model, so to start you will need to create a "mapset", a container where you can import your data (both raster and vector) so it can be handled by GRASS tools. As a start on how to create a GRASS location yoy may want to have a look here… then you will need to import your data (ex: with modules and then you can use the imported data as input for GRASS tools. Speaking about r.statistics you will need both layers (base and cover) as raster, use – Giovanni Manghi Feb 13 '12 at 18:31
to transform your vector into a raster map – Giovanni Manghi Feb 13 '12 at 18:31
I converted my data to GRASS vector and raster layers and then tried to convert vector layer with But there is and only. So I created two new raster layers using both of them. But I wasn't able to find the altitude numbers after doing r.statistics. I tried to convert new r.statistics raster layer back to vector to search for altitude in attribute table, but it seems it's a wrong way. – Hanz Feb 14 '12 at 12:38
Hi, the right conversion tool is, so you can keep an id in the resulting raster. The results of r.statistics are a little tricky to see, because the tool saves the value not directly as pixels values, but it saves them in the pixels "labels", a sort of vector attribute. Too see then the raster labels values (as they are called in GRASS) you need to use the r.category tool. If it is not clear I can provide you a small tutorial. Let me know. – Giovanni Manghi Feb 14 '12 at 13:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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