Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

2 Answers 2

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.

http://grass.fbk.eu/gdp/html_grass64/r.statistics.html

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 qgis.spatialthoughts.com/2012/01/… then you will need to import your data (ex: with modules v.in.ogr and r.in.gdal) 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 v.to.rast –  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 v.to.rast. But there is v.to.rast.constant and v.to.rast.attr 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 v.to.rast.attr, 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

 
discard

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.