<div dir="ltr">I was trying with nested loops and it seems not to be working. Now I tried again (more carefully i have to say) and it worked! Thanks to everybody!</div><br><div class="gmail_quote"><div dir="ltr">Il giorno mer 31 ott 2018 alle ore 21:55 Micha Silver <<a href="mailto:tsvibar@gmail.com">tsvibar@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 10/31/18 11:59 AM, Alessandro Sebastiani wrote:<br>
> Dear all, i was able to compute zonal statistics for multiple areas <br>
> using this script. I used<br>
> > import grass.script as gscript<br>
> > v_list = gscript.read_command("g.list" , type = <br>
> "vect").strip().split("\n")<br>
> # i have 5 vectors in my list<br>
> > method = ("sum" , "average")<br>
> > for v in v_list:<br>
>  >    gscript.run_command("v.rast.stats", map_=v, raster = "LC1", <br>
> column_prefix = "LC1", method = methods)<br>
><br>
> Now i have like 4 rasters that i would like to use as input to compute <br>
> my statistics. Is there a way to loop this process for rasters and <br>
> vector at the same time? i tried creating a list for rasters and using <br>
> the name list as raster input but it seems not to work! cheers, Alessandro<br>
<br>
<br>
What exactly did you try? There should not be any problem to do nested <br>
loops. i.e.:<br>
<br>
<br>
import grass.script as gscript<br>
<br>
v_list = gscript.read_command("g.list" , type = "vect").strip().split("\n")<br>
# i have 5 vectors in my list<br>
r_list = gscript.read_command("g.list" , type = "rast", <br>
pattern="LC*").strip().split("\n")<br>
method = ("sum" , "average")<br>
for v in v_list:<br>
     for r in r_list:<br>
         gscript.run_command("v.rast.stats",<br>
             map_=v, raster = r, column_prefix = r, method = methods)<br>
<br>
<br>
><br>
> Il giorno mar 30 ott 2018 alle ore 11:52 Alessandro Sebastiani <br>
> <<a href="mailto:alessandro.sebastiani@uniroma1.it" target="_blank">alessandro.sebastiani@uniroma1.it</a> <br>
> <mailto:<a href="mailto:alessandro.sebastiani@uniroma1.it" target="_blank">alessandro.sebastiani@uniroma1.it</a>>> ha scritto:<br>
><br>
>     Thanks a lot for your help!<br>
><br>
>     Il giorno mar 30 ott 2018 alle ore 11:49 Nikos Alexandris<br>
>     <<a href="mailto:nik@nikosalexandris.net" target="_blank">nik@nikosalexandris.net</a> <mailto:<a href="mailto:nik@nikosalexandris.net" target="_blank">nik@nikosalexandris.net</a>>> ha scritto:<br>
><br>
>         * Alessandro Sebastiani <<a href="mailto:alessandro.sebastiani@uniroma1.it" target="_blank">alessandro.sebastiani@uniroma1.it</a><br>
>         <mailto:<a href="mailto:alessandro.sebastiani@uniroma1.it" target="_blank">alessandro.sebastiani@uniroma1.it</a>>> [2018-10-29<br>
>         21:32:51 +0100]:<br>
><br>
>         >thank you all for your suggestions.<br>
>         >Dear Nikos, I have some 0-1 rasters that represents<br>
>         presence-absence of<br>
>         >different land covers. Each raster's resolution is 10x10m,<br>
>         thus i want to<br>
>         >compute the sum in order to obtain the surface covered by<br>
>         each land cover<br>
>         >within my buffers. As regards to the buffer, i want to use<br>
>         the 0-100,<br>
>         >0-200, 0-300, 0-400 and 0-500 for computing stats. I can do<br>
>         it separately<br>
>         >with the module v.rast.stats. I just don't know how to loop<br>
>         it in a python<br>
>         >script<br>
><br>
>         Dear Alessandro,<br>
><br>
>         I don't have time to write back as I would like. Instead, I<br>
>         will send<br>
>         you off-list some unpublished script.  With a bit of reading,<br>
>         there, you<br>
>         might identify some ideas that will eventually help in what<br>
>         you are<br>
>         doing.<br>
><br>
>         Kind regards, Nikos<br>
><br>
><br>
> _______________________________________________<br>
> grass-user mailing list<br>
> <a href="mailto:grass-user@lists.osgeo.org" target="_blank">grass-user@lists.osgeo.org</a><br>
> <a href="https://lists.osgeo.org/mailman/listinfo/grass-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
<br>
-- <br>
Micha Silver<br>
Ben Gurion Univ.<br>
Sde Boker, Remote Sensing Lab<br>
cell: +972-523-665918<br>
<br>
</blockquote></div>