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 "^n: " | awk '{print $2}')<br>r.stats -cn $MAP > stats.txt<br>
<br>cats=1<br>while [ $cats -le $max_cats ]; do<br><br> ncat="`head -$cats stats.txt | tail -1 | awk '{print $2}'`"<br> cat="`head -$cats stats.txt | tail -1 | awk '{print $1}'`" <br>
perc="`echo $tot $ncat | awk '{printf("%.5f", $2 / $1 * 100);}'`"<br><br> echo $cat $perc >> $file <br><br> cats="$(expr $cats + 1)"<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"><<a href="mailto:helenaherrera1980@gmail.com">helenaherrera1980@gmail.com</a>></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'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>