Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zonal Statistics QGIS [closed]

Is there any open source alternative for Zonal Statistics tool (ArcGIS Spatial Analyst)? What is the best tool (which I can use in script) dor counting statistics of raster files?

like image 943
Mateusz Kędzior Avatar asked Apr 27 '11 10:04

Mateusz Kędzior


People also ask

How do you get zonal stats in Qgis?

Input your raster layer in the Raster layer parameter as well as your vector layer in the Vector layer containing zones parameter. Next, in the Statistics to calculate parameter, select the stats you want to generate (this will vary in accordance to your project).

How do you use zonal statistics?

Zonal Statistics uses groupings to calculate statistics for specified zones. For example, it can calculate the mean, median, sum, minimum, maximum, or range in each zone. The zonal extent could include anything from country boundaries, watershed catchment areas, or property parcels as a vector or raster dataset.

What is count in zonal statistics?

What you are looking for is COUNT, which is the frequency of the cells that you processed through Zonal Statistics. Sum, on the other hand, is the sum of cell values covered by your polygon. Overly simplistically, say, your cell values are 2,1,3,4,4 in this case COUNT is 5 and SUM is 14.


1 Answers

You can do this with GRASS using various methods. Which one is most suitable will depend on your data and the required output. Note that you can use GRASS also from within QGIS using the GRASS toolbox or Sextante toolbox.

Let's assume you have:

  • a vector map, e.g., vector_zones with the zones defined in the column myzones in the attribute table.
  • a raster layer 'values' for which you want to calculate your zonal statistics

r.statistics

To use r.statistics, you first need to convert the vector map to a raster layer, which you can do with v.to.rast. Next, use r.statistics to calculate the zonal statistics.

v.to.rast input=vector_zones output=zones column=myzones
r.statistics base=zones cover=values out=outputmap method=average

This will give you a new layer with the selected zonal statistic, which could be average, mode, median, variance, etc. (see the man page link above).

r.univar

The r.univar function also works on raster layers.

v.to.rast input=vector_zones output=zones column=myzones    
r.univar map=values zones=zones output=output.file fs=;

The output is a table with the zonal statistics.

v.rast.stats

This does not require you to convert the vector layer to a raster layer (this is done internally). The function calculates basic univariate statistics per vector category (cat) from the raster map.

v.rast.stats vector=vector_zones layer=1 raster=values column_prefix=val

The results are uploaded to the vector map attribute table.

like image 156
Paulo Avatar answered Sep 28 '22 14:09

Paulo