Can I read only a portion of a raster? (With more code)
On 26/09/13 16:57, Michael Sumner wrote:
Use crop() once it's been "read":
r <- raster(system.file("external/test.grd", package="raster"))
my.ext <- extent(179000, 181000, 330000, 333000)
r <- crop(r, my.ext)
There's no "ext" argument to raster() for reading from a file. There
is that argument when you create a raster from scratch with no data,
as an alternative to xmin/ymin/xmax/ymax.
You can read a grid partially with rgdal, by either
1) using the index arguments to readGDAL (offset, region.dim) - but
you have to determine those index values yourself
2) using GDAL.open to create a handle to the file that can be indexed
with [,], but again you need to figure out the indexes
But, raster is pretty good at opening a file and not attempting to
read the whole thing. I would just try doing it as above with crop.
Cheers, Mike.
Thanks Mike. I was wrong thinking raster read the entire file. So my problem is baseless. I read about crop() too just after I sent my message, so that's the way to do it! Ben.