[GRASS-user] r.neighbors with a custom mode calculation?
Don MacQueen
macq at llnl.gov
Mon Mar 15 10:30:20 EDT 2010
Glynn, Wolf,
Sorry to take so long to respond -- both of your solutions are just
what I needed.
Thank you very much.
-Don
At 3:00 AM +0000 3/9/10, Glynn Clements wrote:
>Don MacQueen wrote:
>
>> I'm pretty new to GRASS, and would appreciate some
>>help/guidance/suggestions:
>>
>> I have been smoothing a raster with r.neighbor, as in this example:
>>
>> r.neighbors input=alandcov at PERMANENT output=alandcov_smooth
>> method=mode size=45 {title=Smoothed}
>>
>> The raster values are integers representing qualitative categories.
>>
>> I'd like to modify the smoothing to exclude a particular value.
>> Specifically, if a cell (is that the right term?) has a particular
>> value, say 11, then I want to exclude it, as follows:
>>
>> - if the center of the neighborhood = 11, leave it unchanged (do
>> not calculate the mode, just return 11)
>> - if the center is not 11, calculate the mode, but exclude any
>> points in the neighborhood whose value = 11 (that is, take the mode
>> only of points not equal to 11)
>>
>> The real goal is to preserve boundaries between 11 and not 11. This
>> is a land cover raster; 11 represents water, and I would like the
>> smoothing to not change water to land or vice versa.
>>
>> It seems like it might be possible to do it by creating a mask,
>> smoothing the masked raster, and then putting the 11's back in maybe
>> using r.mapcalc, but the details are a bit tough for me to put
>> together, as a GRASS newbie.
>
>r.mapcalc 'elevens = if(alandcov == 11,11,null()) ; others =
>if(alandcov == 11,null(),alandcov)'
>r.neighbors input=others output=alandcov_tmp method=mode size=45
>r.mapcalc 'alandcov_smooth = if(not(isnull(elevens)),elevens,alandcov_tmp)'
>g.remove rast=elevens,others,alandcov_tmp
>
>--
>Glynn Clements <glynn at gclements.plus.com>
At 8:08 AM +0200 3/9/10, Wolf Bergenheim wrote:
>On Tue, Mar 9, 2010 at 02:30, Don MacQueen <macq at llnl.gov> wrote:
>> The real goal is to preserve boundaries between 11 and not 11. This is a
>> land cover raster; 11 represents water, and I would like the smoothing to
>> not change water to land or vice versa.
>>
>> It seems like it might be possible to do it by creating a mask, smoothing
>> the masked raster, and then putting the 11's back in maybe using r.mapcalc,
>> but the details are a bit tough for me to put together, as a GRASS newbie.
>
>To create the mask you can use
>r.mapcalc 'MASK=if(landcov==11,1,null())
>
>Then after you are done with whatever work you want to do, you can do
>this to put the water back like this
>r.mapcalc 'final=if(isnull(result)),11,result)'
>
>Hope this helps,
>Wolf
>
>--
><8 )---- Wolf Bergenheim ----( 3>
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
--------------------------------------
More information about the grass-user
mailing list