[GRASS-user] r.update

Anna Petrášová kratochanna at gmail.com
Wed Jan 1 12:50:31 PST 2014


Hi Dave,


On Wed, Jan 1, 2014 at 3:10 PM, Dave Roberts <dvrbts at ecology.msu.montana.edu
> wrote:

> Friends,
>
>     After some alternative approaches to a simple problem of compositing
> rasters (see previous posts, esp. compositing rasters @9:32)
> I developed a very crude function to update rasters
>
> r.update target mask x y
>
> updates raster target by substituting y everywhere that raster mask has x.
>  A more GRASS-like syntax would be
>
> r.update target=string mask=string current=integer replace=integer
>

I'm not sure if I don't miss anything but why don't you use r.mapcalc
expression like this:

new = if(mask == x, y, target)

and then

g.rename new,target --overwrite

Anna


> 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.
>
> r.update.sh just below.
>
> r.out.ascii inp=$1 out=$1.asc null=-1
> r.out.ascii inp=$2 out=$2.asc null=-1
> g.remove rast=$1
> r_update $1.asc $2.asc $3 $4
> r.in.ascii  inp=tmp.file out=$1 nv=-1
> rm $1.asc
> rm $2.asc
> rm tmp.file
>
> 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.
>
> The FORTRAN code for r_update is at
>
> ecology.msu.montana.edu/GRASS/r_update.f90
>
> 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.
>
>     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.
>
> Dave
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> David W. Roberts                                     office 406-994-4548
> Professor and Head                                      FAX 406-994-3190
> Department of Ecology                         email droberts at montana.edu
> Montana State University
> Bozeman, MT 59717-3460
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20140101/369b50df/attachment.html>


More information about the grass-user mailing list