[R-sig-Geo] reading tiff with jump?

Agustin Lobo Agustin.Lobo at ija.csic.es
Tue Aug 5 23:32:49 CEST 2008


Thanks to your input,
this is what I'm doing and I think it's ok:

require(rgdal)
fname <- 
"/media/SWISNIFE1/GEODATABOLIVIAmini/geotif/p233_r070_ETM_20010825.tif"
GDALinfo(fname=fname)

output of GDALinfo:
rows        3736
columns     5108
bands       6
ll.x        694431
ll.y        8410014
res.x       28.5
res.y       28.5
oblique.x   0
oblique.y   0
driver      GTiff
projection  +proj=utm +zone=19 +south +ellps=WGS84 +datum=WGS84 +units=m 
+no_defs
file 
/media/SWISNIFE1/GEODATABOLIVIAmini/geotif/p233_r070_ETM_20010825.tif

I go on with reading band 4 with subsampling:

ima <- readGDAL(fname=fname, offset=c(0,0),band=4,output.dim=c(373,510))
str(ima)
image(ima)
imamat <- t(as.matrix(ima)) #put Northernmost line as first row
imamat[imamat==0]<-NA

Then use the following to plot the matrix with correct orientation:

mirot <- function(x) t(x[nrow(x):1,])
x11()
image(mirot(imamat))

Regards,

Agus

Ashton Shortridge wrote:
> On Tuesday 05 August 2008, Roger Bivand wrote:
>> On Tue, 5 Aug 2008, Agustin Lobo wrote:
>>> Hi!
>>>
>>> is it possible to read a tiff file with readGDAL but just keeping
>>> one pixel every p columns and q lines? That is,
>>> a systematic sampling at reading. This is good to save memory
>>> and still be able of displaying and performing
>>> statistics. As images are large,
>>> reading in the entire image and then sampling is not
>>> an alternative.
>>> If this is not contemplated in the readGDAL function,
>>> is there any way to just read in one line, perform
>>> the sampling and then go on with the next line?
>>>
>>> I think I did this with binary images few years
>>> ago, but using tiff would be much better for
>>> practical reasons.
>> Look at the offset=, band= and region.dim= arguments to readGDAL() - you
>> could capture the GDALinfo() output to set the frame if need be. It may be
>> more efficient to use GDAL.open()/GDAL.close() and getRasterData() at a
>> lower level if you are taking many samples - loop over different values of
>> offset= with region.dim=c(1,1). Note that offset= may be from the NW
>> corner, not the SW corner, and that the arguments are (often) ordered
>> (y, x).
>>
>> Roger
> 
> I'll just add to that: opening raster files is fairly expensive, so if you are 
> sampling many locations over many tiffs you will see great speed improvements 
> if you order your sampling by tiff to minimize the opens.
> 
> Yours,
> 
> Ashton
> 

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster




More information about the R-sig-Geo mailing list