Hi Helena,<br><br>I have come to the same problem and solved it with ugly and very specific shell scripts. There is most certainly a better way within GRASS and no doubt you can code it much better in Shell, but anyway, this may get you going somehow.<br>
<br>Code snippet:<br><br>MAP=$1<br><br>g.region rast=$MAP<br>max_cats=9<br>file=true_percentages.txt<br>rm $file<br><br>tot=$(r.univar $MAP | grep &quot;^n: &quot; | awk &#39;{print $2}&#39;)<br>r.stats -cn $MAP &gt; stats.txt<br>
<br>cats=1<br>while [ $cats -le $max_cats ]; do<br><br>    ncat=&quot;`head -$cats stats.txt | tail -1 | awk &#39;{print $2}&#39;`&quot;<br>    cat=&quot;`head -$cats stats.txt | tail -1 | awk &#39;{print $1}&#39;`&quot;      <br>
    perc=&quot;`echo $tot $ncat | awk &#39;{printf(&quot;%.5f&quot;, $2 / $1 * 100);}&#39;`&quot;<br><br>    echo $cat $perc &gt;&gt; $file    <br><br>    cats=&quot;$(expr $cats + 1)&quot;<br><br>done<br><br>I wanted everything in text files, so I generated these stats.txt and true_percentages.txt. The idea of the script is to use the actual cell count given by r.stats -cn and divide it by the total count given by r.univar.<br>
<br>Note that this script is very specific and only work for categories that are incremented by 1. In my case, they go from 1 to 9.<br><br>How brave I am to publicize such an ugly script, huh? :) The result sums up to 1 at least. Just give the name of the categorical map as input.<br>
<br>Hope it helps somehow.<br><br>Marcello.<br><br><br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 9:36 AM, Helena Herrera <span dir="ltr">&lt;<a href="mailto:helenaherrera1980@gmail.com">helenaherrera1980@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Greetings<br><br>I want to calculte % of surface in a raster map for each Integer class value. The thing is that I&#39;m, using r.stats but the sum % values is always much more (104 or 102 or 105). Is there any other (more precised) method to calculate this ?<br>

THanks<br><font color="#888888">Helena<br>
</font><br>_______________________________________________<br>
grass-user mailing list<br>
<a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
<br></blockquote></div><br>