Skip to content
Prev 6740 / 29559 Next

raster package: overlay changes geometry

Hi Agus,

This is probably caused by unexpected values in your input TIF file.
The Upper Left Y is lower then the Lower Left Y...

Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 1760.0)
Upper Right ( 2640.0,    0.0)
Lower Right ( 2640.0, 1760.0)

I do not know if this is "legal" (I sure hope not); but it would be
useful to have your input file (if you can send it off-list) to see
how to best catch this (and either deal with it correctly or give an
error).

I cannot reproduce this problem with other files
Here is an example that works fine:

library(raster)
fn1 <- system.file("pictures/Rlogo.jpg", package="rgdal")
b <- brick(fn1)
b <- readAll(b)
# create a three band TIF file as in your example
b2 <- writeRaster(b, filename='input.tif', filetype='GTiff', overwrite=TRUE)


fn2 <- 'input.tif'
r1 <- raster(fn2,band=1)
r2 <- raster(fn2,band=2)
r3 <- raster(fn2,band=3)
f <- function(x,y,z,coefs= t(matrix(1:3)))
coefs[1,1]*x+coefs[1,2]*y+coefs[1,3]*z
o <- overlay(r1,r2,r3,fun=f,filename="test.tif", filetype='GTiff',
overwrite=TRUE, progress='tcltk')

extent(b)
extent(b2)
extent(r1)
extent(o)

GDALinfo(fn1)
GDALinfo(fn2)
GDALinfo('test.tif')

# By the way, this would be more efficient

b <- brick(fn1)
overlay(b,fun=f,filename="test.tif", filetype='GTiff', overwrite=TRUE)

Robert
On Tue, Oct 27, 2009 at 3:44 AM, Agustin Lobo <alobolistas at gmail.com> wrote: