Skip to content

spTransform / SpatialPixelsDataFrame

2 messages · twah at gmx.ch, Roger Bivand

#
Hello

I would like to reproject a SpatialPixelsDataFrame, changing the CRS. I 
am trying to use the command "spTransform" from the package "sp". 
Unfortunately, the command results in a SpatialPointsDataFrame, which is 
not desired. My SpatialPixelsDataFrame has proj4string

+init=epsg:21781 +proj=somerc +lat_0=46.95240555555556
+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel 
+towgs84=674.4,15.1,405.3,0,0,0,0
+units=m +no_defs

The command which results in a SpatialPointsDataFrame is:

SPDF2<-spTransform(SPDF1,CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 
+towgs84=0,0,0"))

An object transformation through

SPDF3<-as(SPDF2,"SpatialPixelsDataFrame")

results in an error, possibly since in the underlying problem the SPDF2 
is a subset for a particular layer, so it is not a full grid.

Can someone help?

Thanks.
#
On Thu, 21 Apr 2016, twah at gmx.ch wrote:

            
You cannot in general project grids, because the spacings between cell 
centre points will no longer be fixed. You can convert to a raster object 
and *warp* that grid to a new grid in the new projection with regularly 
spaced points, but with output cell centre points that do not match the 
projected points. Often, interpolation is needed to decide which value 
should be assigned to the output grid cells.

Roger