[GRASS-user] How to initialize raster maps.
gorini at gmail.com
Fri Dec 9 07:12:10 EST 2011
> > But there is no way to avoid r.mapcalc, is there?
> I doubt you'd get very much faster or more efficient even by
> writing your own C module. (it would probably only take you a
> minute to create a r.zero module out of the doc/raster/r.example
> code; just change "return x;" to "return 0;" and compile.
Well, out of curiosity, I made the changes to r.example and compiled it. I
then made a small script that initializes a map with the dimensions of one
of my maps ( 677 x 1114) inside a loop using the three approaches mentioned
in this thread:
1 - r.mapcalc "initialized_map=if(base_map>999999,1,0)" # my very smart
2 - r.mapcalc initialized_map=0 # Moritz method
3 - r.example input=initialized_map output=zero_map # Hamish idea
Since I initialize rasters 374 times in my original script, I made the loop
in this way.
1 - 49 seconds
2 - 19 seconds
3 - 58 seconds
- Thanks Moritz for the tip, it will save me at least 30 seconds from now
- Thanks Hamish, because I never knew r.example existed and it was fun to
test the different approaches. But, no, r.example should stay just as
that.... an example :)
Thanks to all.
> tip: to avoid all your scripts breaking when you want to use
> grass7, always add a space around the '=' in r.mapcalc.
> r.mapcalc "initialized_map = 0"
I will keep it in mind from now on. Tks.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the grass-user