r.combine

Jim Westervelt westerve at zorro.cecer.army.mil
Tue Feb 23 13:26:40 EST 1993


Bill Albert writes:

#I want to overlay two maps where each cell reatins its value where there
#is no intersection with the other map. Where there is an intersection
#a new value is created. The "OR" operator doesn't work for this. The
#"OVER" operator seems to be restricted to four colors. Also, what about
#finding what the values were for each cell that intersected?

Being a great fan of r.mapcalc (especially for people new to GRASS) I'd
suggest the following approach:

r.mapcalc 'intersection = if(map1 && map2, 20, map1 + map2)'

The result will be a map called "intersection" where 20 (you can use an
appropriate number here) represents intersections.  At non-intersections,
either the value in map1 or map2 will be retained, otherwise a 0 will be
recorded.

r.coin and r.stats can be used to find what the original values were.

r.cross may do all everything you need in one step:
  r.cross map1,map2 out=map3
r.cross creates an output raster map layer representing all
unique combinations of category values in the raster input
layers.  The original information is captured in the cell map's category
information which is not readily available for further analysis.

If the original values are chosen carefully, the maps can be combined in
a manner which allows all of the original information to be maintained in
the new map (this is the internal approach of r.combine). e.g., say
map1 contains one category (1) and map2 also contains one category. They
can be combined using the value 1 to represent the single category in 
map1 and 2 for the category in map2.  The following r.mapcalc request
creates map3 which maintains the original data:
  r.mapcalc 'map3=if(map1,1,0) + if(map2,2,0)'
map3 will have the following potential category values:
  0 - no data in either map1 or map2  (binary: 000)
  1 - data in map1 only               (binary: 001)
  2 - data in map3 only               (binary: 010)
  3 - data in map1 and map2           (binary: 011)
It is easy to extend this to the capture of more information.

Jim Westervelt - Foundation for the Propagation of Mapcalc Users



More information about the grass-user mailing list