<div dir="ltr">Hi Dave,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 1, 2014 at 3:10 PM, Dave Roberts <span dir="ltr"><<a href="mailto:dvrbts@ecology.msu.montana.edu" target="_blank">dvrbts@ecology.msu.montana.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Friends,<br>
<br>
    After some alternative approaches to a simple problem of compositing rasters (see previous posts, esp. compositing rasters @9:32)<br>
I developed a very crude function to update rasters<br>
<br>
r.update target mask x y<br>
<br>
updates raster target by substituting y everywhere that raster mask has x.  A more GRASS-like syntax would be<br>
<br>
r.update target=string mask=string current=integer replace=integer<br></blockquote><div><br></div><div>I'm not sure if I don't miss anything but why don't you use r.mapcalc expression like this:</div><div><br>

</div><div>new = if(mask == x, y, target)</div><div><br></div><div>and then</div><div><br></div><div>g.rename new,target --overwrite</div><div><br></div><div>Anna</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>
but my bash skills are pretty limited and I elected (for the time being) not to parse the arguments that way.  The current function relies on a short bash script and a FORTRAN executable.  The crude part is exporting both the target an mask rasters as ascii exports, creating a new ascii file, and doing an r.in.ascii to bring the updated raster back in.  It only works (at present) for integer rasters, but it's intended for thematic maps, so that seems OK.<br>


<br>
<a href="http://r.update.sh" target="_blank">r.update.sh</a> just below.<br>
<br>
r.out.ascii inp=$1 out=$1.asc null=-1<br>
r.out.ascii inp=$2 out=$2.asc null=-1<br>
g.remove rast=$1<br>
r_update $1.asc $2.asc $3 $4<br>
r.in.ascii  inp=tmp.file out=$1 nv=-1<br>
rm $1.asc<br>
rm $2.asc<br>
rm tmp.file<br>
<br>
You have to "alias r_update 'sh r_update.sh'" or name the script r.update and chmod +x r.update to make it run as shown.<br>
<br>
The FORTRAN code for r_update is at<br>
<br>
<a href="http://ecology.msu.montana.edu/GRASS/r_update.f90" target="_blank">ecology.msu.montana.edu/GRASS/<u></u>r_update.f90</a><br>
<br>
The code compiles with gfortran.  The executable must be in your path, or you can modify the bash script with a full path to it.<br>
<br>
    It is my sincere hope that someone with GRASS chops will write a function for g.extension that uses the API and avoids all this ascii input and output, but this serves as a demo and useful (if clumsy) approach in the meantime.<span class="HOEnZb"><font color="#888888"><br>


<br>
Dave<br>
-- <br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<u></u>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<u></u>~~~~~~~~~~~~<br>
David W. Roberts                                     office <a href="tel:406-994-4548" value="+14069944548" target="_blank">406-994-4548</a><br>
Professor and Head                                      FAX <a href="tel:406-994-3190" value="+14069943190" target="_blank">406-994-3190</a><br>
Department of Ecology                         email <a href="mailto:droberts@montana.edu" target="_blank">droberts@montana.edu</a><br>
Montana State University<br>
Bozeman, MT 59717-3460<br>
______________________________<u></u>_________________<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="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/grass-user</a><br>
</font></span></blockquote></div><br></div></div>