How to read tif format file?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to read tif format file?

PO SU

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: [hidden email]
Majored in Statistics from SJTU
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to read tif format file?

Michael Sumner-2
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 <[hidden email]> 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: [hidden email]
> Majored in Statistics from SJTU
> ______________________________________________
> [hidden email] 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: [hidden email]

______________________________________________
[hidden email] 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.