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.

in QGIS I have 1 raster-layer (elevation) and 1 vector-layer (administrative units).

Now I would like to be able to query one of the administrative units and see the mean and min/max of the elevation within its area.

Which QGIS tool can do that?

THX, stn

share|improve this question

3 Answers 3

Yes, this is called Zonal Statistics. You can run it with Zonal Statistics plugin, this is the core plugin, so it doesn't need to be installed separately, simply turn it on. Note that there is not that many statistics available.

Zonal Statistics plugin

Resulting calculation

share|improve this answer
    
Found no zonalstats in the plugin-installer after I activated all repositories and then activated "show experimental" and there it was. Checking now. This is the resulting csv: KREIS_NR,object_count,area 1,1,12857000.0 2,1,27166000.0 3,1,43793000.0 4,1,18994000.0 51,1,337919000.0 53,1,297239000.0 I did expect the sum of "channel 1" of the raster-file. What did I do wrong? THX, stn –  stn Apr 1 '12 at 23:37
    
Sorry, meant to say this: "Found no zonalstats in the plugin-installer but after I activated ..." –  stn Apr 2 '12 at 0:30
2  
It looks like Zonal Statistics is not available in 1.7.4. I'd recommend to update to latest trunk version of QGIS. If you are on Windows, use OSGeo4W installer and install qgis-dev package. –  Maxim Dubinin Apr 2 '12 at 3:34
1  
Note there are two versions of the plugin with similar names but very diff functionality. One just counts features, the version in the Trunk of QGIS does data analysis on the raster values. –  Willy Apr 2 '12 at 11:20

although this is not exact answer for you as it does not use QGIS, I still think it could be valueable for you.

Some time ago I had to compare outputs from different modeling softwares so I had plenty of grids (=rasters, mostly in ascii or SAGA format) and add their min/max/averages to the shapefile polygons.

I used SAGA GIS (opensource like QGIS) tool Grid Statistics for Polygons:

enter image description here

Which added all the statistical data calculated from the raster file to the shapefile. It should be also able to add data from multiple rasters, but then there is a problem with the DBF limitation as it cuts the names of the columns containing the raster name and the statistical parameter. So you should use short names for the rasters or later edit the column names in QGIS to better represent which data is it.

share|improve this answer
    
That is exactly how it works. It took me some time to get used to YAGT (=yet another GIS-Tool :-) but in the end the effort payed off. Saga-Gis is really good with its modules. –  stn Apr 12 '12 at 18:03

This is a great question. I can think of a semi-automatic way to do this and it's not as elegant. Hope someone else can give a better answer.

Here is goes

  • Covert the raster to vector using Raster - Conversion - Polygonize. Check the 'Field Name', so you have a field with value of elevation. Call this layer raster_polygon
  • Intersect the vector layer with raster_polygon using Vector - Geoprocessing - Intersect. Call the new layer intersect_join.
  • Assume your vector layer has unique value field called ID. The intersect_join layer will have attributes for both ID and Elevation. Export this as a CSV.
  • Open the CSV in a spreadsheet program and find min/max elevation for each ID. Use built in Max() or Min() functions. Goal is to create another CSV file with following fields ID, min_elev, max_elev. For example.

ID, min_elev, max_elev

0, 500, 1000

1, 200, 250

....

100, 100, 1000

  • Open this CSV file in QGIS as a vector layer and join with original vector layer using 'Joins' in properties menu. Use the unique field ID in both the vector layer and your CSV layer to perform the table join.

Voila! Now when you query any polygon in the vector layer you will see min_elev and max_elev attributes.

share|improve this answer
    
This should work, thank you. Still testing. Generating the intersects takes forever (306.000 Polygons), export to excel takes forever, so I still haven't got the result ... –  stn Apr 2 '12 at 0:24
    
Actually, stn, this will not get the results you may be expecting. Unless "Polygonize" produces one polygon per cell--which would be incredibly inefficient, as perhaps you are discovering--it will downweight all multi-celled polygons, producing incorrect means. –  whuber Apr 3 '12 at 6:36
    
Yes, I noticed the problem with the multi-cell polygons too. That can be solved be adding geometries and then using the polygon-areas as a weight-factor. Problem is: calculating the geometries takes as long as generating the intersects, meaning forever :-) But it works. –  stn Apr 12 '12 at 17:59

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.