[GRASS-dev] More efficient to use r.mapcalc or r.patch in a loop for creating mosaics?

Cedric Shock cedricgrass at shockfamily.net
Thu May 11 14:23:23 EDT 2006


Eric,

> I'm writing a script to mosaic an arbitrary number of rasters together. So
> far, the script works fine, using the following mapcalc statement in a
> 'for' loop:
>
> r.mapcalc "$OUTPUT=if(isnull(Map_A), Map_B, Map_A)"
>
> I should note that I'm reading the map names in through an array which was
> populated in a previous step. My question is: Is there an advantage in
> using r.mapcalc over using r.patch for this work? At 1m resolution rasters,
> and about 60+ of them, this could take a long time.
>

r.patch is more specialized and easier to use. It includes only one speed 
optimization (besides being written for the job): it stops patching a row 
once the whole row has been filled. This only really helps if your tiles 
exactly cover the current region and are in row-major order, and even then it 
only cuts the running time in half. The running time of r.patch goes like 
columns (of current region) * rows * number of patches. I think one could get 
r.mapcalc or r.patch to run in columns * rows * log (patches) with some 
clever manipulation of the region and how the patching is done. It should 
really run like columns * rows * (average patch pixels per pixel).

Speaking of regions, both r.patch and r.mapcalc will generate an output map 
that covers the current region at the current resolution, so both the bounds 
of the region and the resolution must be correct before running these 
programs.

--Cedric




More information about the grass-dev mailing list