[GRASS-user] Get non-NULL cells over multiple rasters

Moritz Lennert mlennert at club.worldonline.be
Thu Mar 1 09:18:24 EST 2012


Johannes Radinger wrote:
> Hi,
>
> -------- Original-Nachricht --------
>    
>> Datum: Thu, 01 Mar 2012 13:18:30 +0100
>> Von: Moritz Lennert<mlennert at club.worldonline.be>
>> An: Johannes Radinger<JRadinger at gmx.at>
>> CC: GRASS user list<grass-user at lists.osgeo.org>
>> Betreff: Re: [GRASS-user] Get non-NULL cells over multiple rasters
>>      
>    
>> Johannes Radinger wrote:
>>      
>>> Hi,
>>>
>>> I have a bunch of raster maps (~50 are named crast_* and 50 are named
>>> rast_*). Is there a simple way (eg. using regular expressions) to
>>> process them with the mapcalculator to get one resulting map which
>>> shows only those cells (value 1) which are non-NULL cell in ALL maps?
>>> Like I'd like the cells which all rasters have commonly populated.
>>> Maybe there is a simple way to do this in the mapcalculator (or any
>>> other modul) resp. in a python script?? Suggestions are mostly
>>> welcome. Thanks,
>>>        
>> r.series with the -n flag ? From the man page:
>>
>> "With -n flag, any cell for which any of the corresponding input cells
>> are NULL is automatically set to NULL (NULL propagation). The aggregate
>> function is not called, so all methods behave this way with respect to
>> the -n flag."
>>
>> See the man page for examples of how to use r.series in conjunction with
>> g.mlist to work with a series of maps.
>>      
>
> Thank you very  much, r.series is the right tool for my task. I tried to
> use it in combination with g.mlist but somehow I don't manage it. I tried different methods e.g.:
>
> 1) in the GRASS command console I typed:
> r.series -n input="'g.mlist pattern='rast_*|crast_*' sep=,'" output=Treene_tmp_mask method=count
>    

Are you talking about the wxGUI command console, or the terminal ?

In the terminal the whole g.mlist part has to be in backticks (`) which 
means "replace everything which is within the backticks with the results 
of that command". I imagine that this does not work in the GUI command 
console.

In the terminal your command should be:

r.series -n input=`g.mlist pattern="rast_*|crast_*" sep=,` output=Treene_tmp_mask method=count


> 2) and I tried it in a python script with:
> 	grass.run_command("r.series",
> 			input = "'g.mlist pattern='rast_*|crast_*|Treene_raster' sep=,'",
> 			overwrite=True,
> 			flags = "n",
> 			output = "Treene_tmp_mask",
> 			method = "count")
>    


If you want to work in a python script, you have to first run 
read_command(g.mlist), put the result in a comma-seperated string which 
you then feed into r.series. There are possibly other ways that I don't 
know about...

Moritz


More information about the grass-user mailing list