[R-sig-Geo] map algebra with ascii grid
Edzer J. Pebesma
e.pebesma at geo.uu.nl
Tue Jul 17 08:50:31 CEST 2007
As Roger mentioned, we did try to make the Spatial*DataFrame objects
behave like a data.frame but indeed not with respect to applying direct
arithmetric on them. I do agree with Tim that if a is a single-band
SpatialGridDataFrame, then
a = a + 1
is more straightforward than
a$band1 = a$band1 + 1
although the latter does better reveal what's going on inside; the full
story is of course that
a at data$band1 = a at data$band1 + 1
which make things pretty unreadable. In addition, if b is a single-band
SpatialGridDataFrame only
a = a + b
could allow for checking that a and b are identical spatial grids, in
contrast to
a$band1 = a$band1 + b$band1
So, yes, I like it, and it will break where a or b contain mixed double
and factor variables, as it should.
The full map algebra, as I have been taught, includes besides
arithmetical and logical operation the full set of useful functions (for
both floats and factors) that take neighbouring cells into account,
where neighbourhood can be global, a regular window or defined by
another map (e.g. the land use category we're in). For an example of a
list of functions, see for instance the work of my Utrecht colleagues:
http://pcraster.geog.uu.nl/documentation/pcrman/r2850.htm
where e.g. distance calculation is called "spread" with a constant
friction map.
Now that would be nice to have in R.
--
Edzer
Tim Keitt wrote:
> Any algebraic operation supported by R can easily be applied to a GDAL
> image using rgdal -- size is virtually unlimited if you pull in data
> as raster lines or tiles. The approach is to create an output image
> and then use getRasterData and putRasterData to read chunks of data,
> operate on them, and then write back to disk. I can work up an example
> if anyone is interested.
>
> THK
>
> On 7/16/07, Denham Robert <Robert.Denham at nrw.qld.gov.au> wrote:
>
>> Philip,
>> this sounds like an interesting approach. Do you do anything in
>> particular to handle larger datasets? How large are your images?
>>
>> Robert Denham
>> Environmental Statistician
>> Remote Sensing Centre
>> Telephone 07 3896 9899
>> www.nrw.qld.gov.au
>>
>> Department of Natural Resources & Water
>> QScape Building, 80 Meiers Road, Indooroopilly Qld 4068
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Sun, 15 Jul 2007 07:40:12 -0600
>> From: Philip Riggs <priggs at cnr.colostate.edu>
>> Subject: [R-sig-Geo] map algebra with ascii grid
>> To: r-sig-geo at stat.math.ethz.ch
>> Message-ID: <3513F1E2-D6E1-4B2B-89E8-D0B00C2804B7 at cnr.colostate.edu>
>> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>>
>>
>>>> Dear R Users,
>>>>
>>>> could you please advise me on doing map algebra with spatial grids?
>>>> It's the first time I am using spatial objects in R. I have imported
>>>> an ascii grid file and wanted to round the values in it or sum with a
>>>>
>>>> value, but it gives an error message:
>>>>
>>>>
>>> I use Python with Numpy/GDAL python bindings all the time to do spatial
>>>
>> algebra and manipulate grids.
>>
>>> It has all the math functions, and in the case of categorical data you
>>>
>> can reassign values. Then I
>>
>>> use rpy to do any statistical analyses in R. You could also do your
>>>
>> manipulation in Python, then
>>
>>> save the grid in an appropriate format for import into R to do the
>>>
>> statistical analyses.
>>
>>
>>> Philip
>>>
>>
>>
>> ************************************************************************
>> The information in this email together with any attachments is
>> intended only for the person or entity to which it is addressed
>> and may contain confidential and/or privileged material.
>> Any form of review, disclosure, modification, distribution
>> and/or publication of this email message is prohibited, unless
>> as a necessary part of Departmental business.
>> If you have received this message in error, you are asked to
>> inform the sender as quickly as possible and delete this message
>> and any copies of this message from your computer and/or your
>> computer system network.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
>
>
More information about the R-sig-Geo
mailing list