[STATSGRASS] "Neighbourhood modifier" from r.mapcalc in R?
Rainer M Krug
Rainer+grass at krugs.de
Wed Oct 17 03:49:17 EDT 2007
Thanks - I'll look into your suggestions later this week.
Rainer
Roger Bivand wrote:
> On Tue, 16 Oct 2007, Rainer M Krug wrote:
>
>> 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.
>
> As designed, the SpatialGridDataFrame objects are intended to have the
> same regions in the g.region sense. They do have grid slots, and you
> could shift the whole grid by changing the cellcentre.offset slot in the
> GridTopology object in the grid slot, and update the bbox. This would
> give grids that are offset in relation to each other, but to get the
> values across all offset grids, you'd need to back the original
> SpatialGrid out to SpatialPoints, and use the overlay() method for
> SpatialPoints and SpatialGridDataFrame objects.
>
> An alternative that would need coding is to look inside the "[" method
> for SpatialGridDataFrame objects (which you refer to above) and see how
> one might write a relative reference function which would not subset on
> the i and j arguments, but shift by row and column.
>
> Probably the first alternative involves less work.
>
> Roger
>
>>
>> Rainer
>>
>> _______________________________________________
>> statsgrass mailing list
>> statsgrass at grass.itc.it
>> http://grass.itc.it/mailman/listinfo/statsgrass
>>
>>
>
More information about the grass-stats
mailing list