<html style="direction: ltr;">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
  </head>
  <body bidimailui-charset-is-forced="true" style="direction: ltr;"
    bgcolor="#FFFFFF" text="#000000">
    <p>Some further python specific tips that might help.</p>
    <p><br>
    </p>
    <p>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":<br>
    </p>
    <p><br>
    </p>
    <p><font size="+1"><tt># This must be run from within a grass
          session</tt><tt><br>
        </tt></font></p>
    <p><font size="+1"><tt>import grass.script as gscript</tt></font></p>
    <p><font size="+1"><tt>rast_list = gscript.read_command("g.list",
          type = "rast", pattern = "band*").strip().split("\n")</tt></font></p>
    <p><font size="+1"><tt># Loop thru the rasters, run v.rast.stats,
          and specify the column prefix using the raster name.</tt></font></p>
    <p><font size="+1"><tt>methods = ("minimum", "maximum", "average",
          "sum")  # add whatever stats you need</tt><tt><br>
        </tt></font></p>
    <p><font size="+1"><tt>for r in rast_list:</tt><tt><br>
        </tt></font></p>
    <p><font size="+1"><tt>    gscript.run_command("v.rast.stats", </tt></font></p>
    <p><font size="+1"><tt>        map_ = "buffers", raster=r,
          column_prefix=r,  method=methods)</tt></font></p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p>Be aware that if you have many rasters, you'll end up with
      many,many columns in the "buffers" vector<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 10/29/18 9:54 PM, Stefan Blumentrath
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:DB7PR02MB45851D6A7FC247086682D01F9EF30@DB7PR02MB4585.eurprd02.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US">Hi
            Alessandro,<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">You could try v.rast.bufferstats [1], if you do
            not have hundrets of thousands of points….<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">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…<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">Otherwise have a look at the general
            introduction to GRASS and Python [3].<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">Cheers<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">Stefan<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">1: <a
href="https://grass.osgeo.org/grass74/manuals/addons/v.rast.bufferstats.html"
              moz-do-not-send="true">
https://grass.osgeo.org/grass74/manuals/addons/v.rast.bufferstats.html</a><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">2: <a
              href="https://grass.osgeo.org/grass76/manuals/v.rast.stats.html"
              moz-do-not-send="true">
              https://grass.osgeo.org/grass76/manuals/v.rast.stats.html</a><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB">3: <a
              href="https://grasswiki.osgeo.org/wiki/GRASS_and_Python"
              moz-do-not-send="true">
              https://grasswiki.osgeo.org/wiki/GRASS_and_Python</a><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="mso-fareast-language:EN-US"
            lang="EN-GB"><o:p> </o:p></span></p>
        <p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span
            lang="EN-US"> grass-user
            <a class="moz-txt-link-rfc2396E" href="mailto:grass-user-bounces@lists.osgeo.org"><grass-user-bounces@lists.osgeo.org></a>
            <b>On Behalf Of </b>Alessandro Sebastiani<br>
            <b>Sent:</b> mandag 29. oktober 2018 16:06<br>
            <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
            <b>Subject:</b> [GRASS-user] zonal statistics for multiple
            areas<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
        <div>
          <p class="MsoNormal">Hello to everybody,<o:p></o:p></p>
          <div>
            <p class="MsoNormal">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<o:p></o:p></p>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/grass-user">https://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
  </body>
</html>