<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="direction: ltr;">
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body style="direction: ltr;" bidimailui-charset-is-forced="true"
    bidimailui-detected-decoding-type="latin-charset" bgcolor="#ffffff"
    text="#000000">
    <p style="margin-bottom: 0cm; margin-top: 0pt;">On 18/10/2010 16:07,
      Sylvain Maillard wrote:<br>
    </p>
    <blockquote
      cite="mid:AANLkTikmQT=eENYqb-8hcCLTvaJ0xk6YqyZP5YvyH2a7@mail.gmail.com"
      type="cite">hello,<br>
      <br>
      something strange, i was quite sure to have send a response but it
      seems something goes wrong ...<br>
      <br>
      I wrote a little script that use r.mode:<br>
      - convert the vector with polygon to raster<br>
      - loop for each polygon<br>
    </blockquote>
    Don't think this is necessary. Once the vector is rasterized, the
    values in the output raster will represent the mode, calculated from
    the cover map, for each area. Then just convert the output raster
    back to a vector with the '-v' flag to r.to.vect and it should
    contain the mode as it's cat value for each polygon. <br>
    <br>
    <blockquote
      cite="mid:AANLkTikmQT=eENYqb-8hcCLTvaJ0xk6YqyZP5YvyH2a7@mail.gmail.com"
      type="cite">
      - get the mode and update the specified column in the vector file
      <br>
      <br>
      it process only one polygon at a time and is quite slow, but do
      the job ;)<br>
      <br>
      cheers,<br>
      Sylvain<br>
      <br>
      [code]<br>
      #!/bin/bash<br>
      <br>
      # vector with polygon<br>
      vect=Parcellaire<br>
      # name of the column to store the mode <br>
      col=new2000<br>
      # name of your data_map raster<br>
      cover=classif<br>
      # name for the tmp raster to compute the polygon<br>
      base=parcelles<br>
      <br>
      g.region rast=${cover}<br>
      v.to.rast input=${vect} output=${base} use=cat<br>
      <br>
      for cat in `r.stats ${base} | grep -v "*"`<br>
      do<br>
      <br>
      cat_u=$(($cat - 1))<br>
      cat_o=$(($cat + 1))<br>
      <br>
      g.copy rast=${base},${base}.${cat}<br>
      r.null map=${base}.${cat} setnull=0-${cat_u},${cat_o}-11000<br>
      g.copy rast=${base}.${cat},MASK<br>
      r.mapcalc "${cover}.${cat}=${cover}"<br>
      r.mode base=${base}.${cat} cover=${cover}.${cat}
      output=${base}.${cat}.reclass --o --v<br>
      class=$(echo `r.stats ${base}.${cat}.reclass | grep -v "*"`);<br>
      v.db.update map=${vect} column=${col} value=${class}
      where="cat=${cat}"<br>
      g.remove
      rast=MASK,${base}.${cat}.reclass,${base}.${cat},${cover}.${cat}<br>
      <br>
      done<br>
      [/code]<br>
      <br>
      <br>
      This mail was received via Mail-SeCure System.<br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
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="http://lists.osgeo.org/mailman/listinfo/grass-user">http://lists.osgeo.org/mailman/listinfo/grass-user</a>

This mail was received via Mail-SeCure System.


</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="62">-- 
Micha Silver
<a class="moz-txt-link-freetext" href="http://www.surfaces.co.il/">http://www.surfaces.co.il/</a>
Arava Development Co.  +972-52-3665918
</pre>
  </body>
</html>