Some further python specific tips that might help.


To get a list of rasters that match some pattern (say you have many rasters like "band1", "band2",...), then run v.rast.stats on each of them in a loop to get zonal stats in the vector "buffers":


# This must be run from within a grass session

import grass.script as gscript

rast_list = gscript.read_command("g.list", type = "rast", pattern = "band*").strip().split("\n")

# Loop thru the rasters, run v.rast.stats, and specify the column prefix using the raster name.

methods = ("minimum", "maximum", "average", "sum")  # add whatever stats you need

for r in rast_list:

    gscript.run_command("v.rast.stats",

        map_ = "buffers", raster=r, column_prefix=r,  method=methods)



Be aware that if you have many rasters, you'll end up with many,many columns in the "buffers" vector



On 10/29/18 9:54 PM, Stefan Blumentrath wrote:

Hi Alessandro,

 

You could try v.rast.bufferstats [1], if you do not have hundrets of thousands of points….

 

If the buffers don`t overlap, you could use v.rast.stats [2] from the upcoming GRASS 7.6 release, that will allow multiple raster input…

 

Otherwise have a look at the general introduction to GRASS and Python [3].

 

Cheers

Stefan

 

1: https://grass.osgeo.org/grass74/manuals/addons/v.rast.bufferstats.html

2: https://grass.osgeo.org/grass76/manuals/v.rast.stats.html

3: https://grasswiki.osgeo.org/wiki/GRASS_and_Python

 

 

From: grass-user <grass-user-boun...@lists.osgeo.org> On Behalf Of Alessandro Sebastiani
Sent: mandag 29. oktober 2018 16:06
To: grass-user@lists.osgeo.org
Subject: [GRASS-user] zonal statistics for multiple areas

 

Hello to everybody,

I hope my question is appropriate for this mail list. I have created 5 different buffer layers (d=100,200,300,400,500 m) from a point vector. Now i want to compute some zonal statistics using different rasters as input. I know how to do that separately, but i was wondering how could i automate this procedure using a python script. I know python's basics, but i was not able to do so following guidelines that i found on the internet, e.g GRASS tutorial. Thank you in advance, A


_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user
-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to