[GRASSLIST:4678] Re: Outputing values of neighboring cells in a DIFFERENT layer

Gordon Keith gordon.keith at csiro.au
Mon Oct 7 18:39:48 EDT 2002


On Tue, 8 Oct 2002 02:11, Jason Horn wrote:
> I'm looking for a little advice.  I need to output some cell values
> by examining two raster layers.  I need to know the values of
> neighboring cells (very much like what r.neighbors does).  However,
> rather that getting the values of the neighboring cells in the same
> layer, I need the values of the neighboring cells of the
> corresponding cell in a DIFFERENT layer.
>
> For example: I have two layers A and B.  I'm interested in cell (10,
> 10) in layer A.  I'd like to output the values of the neighboring
> pixels from the corresponding cell (10, 10) in layer B.  I want to do
> this for every cell that is part of a particular phenomenon in layer
> A.
>
> r.neighbors is close, but not quite it.  I need the ability to get
> the values of neighboring cells from OTHER layers.  Does anyone have
> any ideas?

My thoughts:

if you just want the corresponding cell then:
r.mapcalc C='if(A=x,B,null())'

but you don't so you could do:
r.mapcalc C='if(A=x || A[-1,-1]=x || A[0,-1]=x || A[1,-1]=x || A[-1,0]=x 
|| A[1,0]=x || A[-1,1]=x || A[0,1]=x || A[1,1]=x, B,null())'
if you only wanted the immediate neighbour, but that's messy.

If you want anything with a distance (eg  5m) of the particular values:
r.mapcalc x='if(A=x,1,null())'
r.buffer in=x out=x5 distance=5
r.mapcalc C=if(isnull(x5),null,B)

I don't think this solves the problem you've stated, but it might give 
you some ideas.

Hope this helps
Gordon

-- 

Gordon Keith
Programmer/Data Analyst
Marine Acoustics
CSIRO Marine Research
http://www.marine.csiro.au

"The next generation of interesting software will be done on Macintosh, 
not the IBM PC." 
- Bill Gates, talking to Business Week, 1984



More information about the grass-user mailing list