[R-sig-Geo] doubt with readGDAL
"José M. Blanco Moreno"
jmblanco at ub.edu
Sun Oct 4 20:12:44 CEST 2009
Dear R-users community,
I have been trying to figure out on my own, but no way...
I am trying to read and decimate a geotiff:
library(maptools)
library(spatial)
library(sp)
library(rgdal)
download.file(url='http://srtm.geog.kcl.ac.uk/portal/srtm41/srtm_data_arcascii/srtm_37_04.zip',destfile='srtm_37_04.zip')
shell('unzip -o srtm_37_04.zip')
cata <-
readGDAL('srtm_37_04.tif',offset=c(2900,0),region.dim=c(2600,5000),output.dim=c(260,500))
cata2 <- cata
cata2 at data$band1 <- ifelse(is.na(cata2 at data$band1),-1,cata2 at data$band1)
cata2 at data$band1 <-
c(50,100,250,500,1000,1500,2000,3000)[cut(cata at data$band1,c(0,50,100,250,500,1000,1500,2000,3000))]
image(cata2,col=gray(seq(.9,0.6,length=9)))
contour(cata2,add=T,levels=c(0,50,100,250,500,1000,1500,2000,3000),col=gray(.7),drawlabels=F)
axis(1)
axis(2)
But the coordinates don't come out: they are translated in the y-axis *a
lot*; bbox(cata) returns:
min max
x -4.166183e-04 5.000417
y -1.577894e+01 -10.778109
While in the non-decimated version they are:
min max
x -0.0004166183 4.16625
y 40.4170835754 42.58375
Could anyone indicate a workaround to preserve the coordinates of the grid?
Thank you for any information on this issue (which I suppose is
generated by my own incompetence).
José M.
sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32
locale:
LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanish_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_0.6-8 spatial_7.2-47 maptools_0.7-25 sp_0.9-37
foreign_0.8-36
loaded via a namespace (and not attached):
[1] grid_2.8.1 lattice_0.17-25
--
---------------------------------------
José M. Blanco-Moreno
Dept. de Biologia Vegetal (Botànica)
Facultat de Biologia
Universitat de Barcelona
Av. Diagonal 645
08028 Barcelona
SPAIN
---------------------------------------
http://www.ub.edu/agroecologia/
phone: (+34) 934 039 863
fax: (+34) 934 112 842
More information about the R-sig-Geo
mailing list