[R-sig-Geo] Array indices for very large multi-band images

guido.lemoine at jrc.ec.europa.eu guido.lemoine at jrc.ec.europa.eu
Fri Apr 9 12:05:05 CEST 2010


Dears,

I just joined the list, so please bear with me if my problem
has been dealt with already. I did an extensive google search,
making sure r-gis-geo was included, so am sort of sure my
problem is relevant.

I have a (very) large 3 band ENVI file (32431 x 47262, 4.5 Gb,
i.e. too big for normal GeoTIFF). I would like to generate
statistics for 200 by 200 sized cells (including cross-correlation
between bands).
I am using the rgdal package, trying to use the array indexing
syntax of R, running into trouble when trying to subset all
3 bands at the same time.

Using array index syntax is useful, because it produces a
SpatialGridDataFrame, which makes further processing easier.

Here's my trial script:

require(rgdal)
x<-GDAL.open("verylarge3channelENVIimage")
r <- getRasterData(x, offset = c(14000, 14000), region.dim = c(200, 200))
str(r)
# This works, but produces a simple integer array
int [1:200, 1:200, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
# I'd rather do this
sub0 <- x[14000:14199, 14000:14199,]  # ... but doesn't work
Error in x[14000:14199, 14000:14199, ] :
  argument is missing, with no default
# this then?
sub1 <- x[14000:14199, 14000:14199,1:3] # no, running into memory trouble
Error: cannot allocate vector of size 2.3 Gb
# per band works:
sub2 <- x[14000:14199, 14000:14199,1]  # produces a nice spatial object.
summary(sub2)
Object of class SpatialGridDataFrame
...

Is there a way to get all 3 bands with array index syntax, preferably
as a SpatialGridDataFrame with band1, band2, band3.

Any help greatly appreciated,

GL



More information about the R-sig-Geo mailing list