[R-sig-Geo] 'xyValues' from 'raster' package slow

Karl Ove Hufthammer karl at huftis.org
Tue Dec 1 13:11:28 CET 2009


Dear list members

I'm using the 'raster' package to load a rather large (~2 GB) file of 
bathymetry data. To extract elevation/depth data for various positions, 
I use the 'xyValues' function.

However, it turns that this operations is extremely slow for extracting 
a even moderately large number of values. Here is in essence my code:

r = raster("file.ers")
x = seq(0, 20, length = 100)
y = seq(55, 70, length = 100)
xy = expand.grid(x, y)
z = xyValues(r, xy)

Am I doing something wrong here? Using 'readBin' or 'readBinFragments' 
on the same file, to extract the same values, takes almost no time. But 
then I have to calculate the indices, positions &c. myself, which is 
tedious and easy get wrong (having to take into account half-pixel 
shifts and other details). 

Using Rprof indicates that a lot of 'self.time' is taken up by 'gc' (and 
'=='), which does sound a bit strange.

-- 
Karl Ove Hufthammer



More information about the R-sig-Geo mailing list