Skip to content
Prev 19390 / 29559 Next

Can I read only a portion of a raster? (With more code)

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.




On Thu, Sep 26, 2013 at 4:35 PM, Ben Harrison
<harb at student.unimelb.edu.au> wrote: