[STATSGRASS] "Neighbourhood modifier" from r.mapcalc in R?

Rainer M Krug Rainer+grass at krugs.de
Wed Oct 17 03:51:10 EDT 2007


Hi

Thanks for pointing out shift.im() and the matrix notation - I was 
thinking along the same lines and will look into it again later this week

Rainer


Agustin Lobo wrote:
> Have you tried shift.im() from spat.stats to create the two
> shifted rasters first and then operate with them?
> Or perhaps extracting the matrix from the sp object and doing
> the same in matrix notation. For example, if INPUT1 is a matrix,
> then
> INPUT1NW <- cbind(INPUT1[,-(1:2)],NA*INPUT1[,1:2])
> INPUT1NW <- rbind(INPUT1NW[-(1:2),],NA*INPUT1NW[1:2,])
> and an equivalent for the SE shift (INPUT1SE)
> 
> Then
> OUTPUT <- INPUT1NW*INPUT2 + INPUT1SE*INPUT2
> 
> and make an sp object with OUTPUT
> 
> Agus
> 
> 
> 
> Rainer M Krug escribió:
>> Hi
>>
>> I want to do some map calculations which involve binominal distributed 
>> random numbers which I can not obtain in r.mapcalc. Therefore I import 
>> the raster via readRAST6() into R and I want to do the calculations 
>> there. But I am stuck...
>>
>> In r.mapcalc I use somthing like
>>
>> OUTPUT=INPUT1[-2,-2]*INPUT2+INPUT1[+2,+2]*INPUT2
>>
>> How can I translate this into R?
>>
>> rA <- readRAST6("INPUT1")
>> rB <- readRAST6("INPUT2")
>> but now?
>>
>> rA$A gives me all cell values,
>> rA[1:2,1:2]$A gives me the cell values from columns and row 1 and 2,
>>
>> But I have no idea where I should put the offset in.
>>
>> Rainer
>>
>> _______________________________________________
>> statsgrass mailing list
>> statsgrass at grass.itc.it
>> http://grass.itc.it/mailman/listinfo/statsgrass
>>
> 




More information about the grass-stats mailing list