[R-sig-Geo] Coercing multiband readGDAL objects to a matrix/vector...
Jonathan Greenberg
greenberg at ucdavis.edu
Fri Jan 23 20:00:30 CET 2009
Michael:
Thank you for your prompt reply -- if I wanted to extract multiple
bands in a single call, how would I do that? I suppose I could do it
with a for-next loop, but it seems there is probably some simple way of
doing this:
as.matrix(x[1:3]) (doesn't work, but the idea is I want bands 1-3 in this matrix).
--j
Michael Sumner wrote:
> Hello,
>
> You can use either as.imageSpatialGridDataFrame(x[1]) or as.matrix(x[1]),
> where "x" is a SpatialGridDataFrame or SpatialPixelsDataFrame.
>
> The "1" index assumes you want the first band, replace as appropriate.
>
> The first gives you a list with x, y, z components in the convention
> expected by image(), so
> as.imageSpatialGridDataFrame(x[1])$z is the matrix.
>
> The second returns the matrix directly but in a different orientation.
>
> HTH
>
> Regards, Mike.
>
>
> ==============Original message text===============
> On Fri, 23 Jan 2009 8:59:02 +1100 Jonathan Greenberg wrote:
>
> I was hoping I could get some info on how to coerce the type of object
> readGDAL produces, assuming its a multiband object, into an R matrix (I
> just want the raster values in the matrix)? Thanks!
>
> --j
>
>
More information about the R-sig-Geo
mailing list