Skip to content

spTransform, gridded

3 messages · Patrick Giraudoux, Edzer Pebesma, Roger Bivand

#
Dear Listers,

I am trying to convert a Gtiff object  from a coordinate system to 
another... I have tried the following:

# read the Gtiff file (European Lambert azimuthal equal area)
fcE<-readGDAL("fclambert.tif")
proj4string(fcE) # CRS OK

# read a shapefile to get the projection system (Lambert II etendu - a 
French projection Lambert
# conformal conic based on NTF)
fccoms<-readOGR("U:/Documents and Settings/giraudoux/Mes documents/Map 
tools/Shapefiles checked prj","FC_communes")
proj4string(fccoms) # CRS OK

# transform
fcLIIe<-spTransform(fcE, CRS(proj4string(fccoms))) # looks OK

# try writing
writeGDAL(fcLIIe,"fcLIIe.tif")
Error: gridded(dataset) is not TRUE

# try to promote to a grid...
gridded(fcLIIe)<-TRUE
suggested tolerance minimum: 0.5Error in points2grid(points, tolerance) 
: dimension 1 : coordinate intervals are not constant

I  suspect that  pixel centers may have been distorted with the 
transformation but may naively I wonder if there is a way to turn this 
problem eg increasing the tolerance...

Any hint appreciated...

Patrick
#
Patrick,

the problem is that if you reproject points on a grid, the result is not 
on a grid anymore, so I think it is correct that spTransform does return 
a SpatialPointsDataFrame rather than a SpatialGridDataFrame. You would 
have to shift points to centers on the new grid. The creator functions 
SpatialPixels() or SpatialPixelsDataFrame have a tolerance, which may be 
used to define to which extent you allow points to be off the points on 
a true grid. I would use that instead of gridded(x)=TRUE.

Note that you do move points, then.
--
Edzer
Patrick Giraudoux wrote:

            
#
On Sat, 24 Mar 2007, Patrick Giraudoux wrote:

            
This is warping, so in general the output will not be a regular grid. If 
you need a grid, try interpolating to an empty grid in the target 
projection (IDW in gstat ought to be OK if the resolutions are similar, 
with a small number of neighbours). My guess is that fcLIIe is a 
SpatialPoints* object, not on a regular grid.

You could use gdalwarp externally to do this, if you prefer.

Roger