[GRASS-user] Multiple labels and r.series

Glynn Clements glynn at gclements.plus.com
Wed Nov 12 00:04:54 EST 2008


John C. Tull wrote:

> >> I am creating a raster map that essentially summarizes the
> >> intersection of a series of labeled rasters that each have
> >> values of either 1 or null (presence/absence data). I am
> >> using r.series like this to perform the summation across the
> >> rasters that are all named with a prefix of presence_:
> >>
> >> r.series input="`g.mlist rast
> >> pattern='presence_*' sep=,`"
> >> output=presence_sum method=sum --o
> >>
> >> Can anyone think of a way to achieve this summation of
> >> intersections in a way that will also allow for each cell to
> >> have a label that concatenates all labels for the respective
> >> raster maps that are present at that cell? E.g., let's
> >> say three of the rasters are present at a particular cell,
> >> and the labels for those rasters are 'raster1',
> >> 'raster4', and 'raster7'. I would like the
> >> final map to have a label of 'raster1, raster4,
> >> raster7'.
> >>
> >> Any and all suggestions are greatly appreciated.
> >
> >
> > the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
> > before running the sum.  So you then get a sum like 13, which would  
> > mean
> > the 8+2+1 maps were all present, or if the sum was 5 you'd know the  
> > 1+4
> > maps were present for that cell, and not others.
> >
> >
> > see also r.bitpattern and r.mapcalc bitwise operators.  (sorry I don't
> > know the proper name/wikipedia link for this technique, I'm not a  
> > computer
> > scientist)
> 
> I follow your logic here. I am still hopeful that someone will have  
> some sort of script or r.mapcalc magic to generate concatenated labels.
> 
> As I'm not a computer scientist either, I fear I would spend more time  
> trying to decipher the bitwise values and meanings than would be  
> practical. That is a good suggestion, nonetheless. I should have added  
> that I am using about 96 raster layers.

The main problem here is that labels are associated with categories,
not with individual cells.

r.cross will take a set of input maps, and generate a unique category
(and concatenated label) for each unique combination of categories. 
Howver, it won't handle 96 maps (it is currently limited to 10 maps in
6.3.0, increased to 30 maps in 6.4 and 7.0).

My first suggestion is to try using r.cross on batches of 10 maps at a
time, then use r.cross again on the 10 intermediate results. This may
fail if the total number of combinations is large, or if any cell has
too many labels (there may be a limit on the length of a label), and
will probably be quite slow (possibly unacceptably so).

Ultimately, it may not even be possible to generate such a map, given
the 32-bit limit for category numbers. You could theoretically have up
to to 2^96 distinct categories, although in practice you would be
limited by the size of the map. But you could end up with each cell
having a distinct combination of labels.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list