[R] How to read tif format file?

Michael Sumner mdsumner at gmail.com
Mon Oct 20 05:50:28 CEST 2014


What's wrong is that readGDAL tries to allocate all the memory
required and build an object to essentially replace the file, and your
machine cannot provide sufficient resources for that. GDAL.open
provides an open connnection to the file that can be queried in
different ways to read parts of the file as necessary.

You can provide low level arguments to readGDAL to subset/subsample:
"offset", "region.dim", and "output.dim". See ?readGDAL.

But, there are facilities in the raster package to open the file with
GDAL.open and read on demand. Try this:

library(raster)
raster("a.tif")

If your .tif has more than one band, you'll have to use
raster::brick() or raster::stack(), which will read only the first
band by default.

Cheers, Mike.

On Mon, Oct 20, 2014 at 1:29 PM, PO SU <rhelpmaillist at 163.com> wrote:
>
> Dear expeRts,
>    I want to read a  a.tif file into  R.
>  When i  try this:
> readGDAL("a.tif"), i get the following error:
>
>
> a.tif has GDAL driver GTiff
> and has 7200 rows and 7200 columns
>
> error: can't allocate 395.5 mb vector
> but i can GDAL.open("a.tif") it.
> SO what's wrong with readGDAL?
>
>
>
>
>
> --
>
> PO SU
> mail: desolator88 at 163.com
> Majored in Statistics from SJTU
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-help mailing list