spTransform changes the class
The general idea is that for changing the projection of a raster you provide the input RasterLayer and a Raster object with the spatial parameters (projection, extent, resolution) to which it should be transformed. For the latter, you can use the RasterLayer that you want to project the input data to (I call it 'x'). prjgrd <- projectRaster(eugrd025, x, method='bilinear') Note that it should *not* be necessary to resample after projection because projecting a raster already implies resampling. Robert
On Thu, Jul 1, 2010 at 8:48 AM, Michael Sumner <mdsumner at gmail.com> wrote:
Ah, sorry that was completely wrong. I think this is right, but still untested: raster.eugrd025 <- raster(eugrd025) pr <- projectExtent(raster.eugrd025, projection(eugrd025EFDC_SPDF)) eugrd025EFDC <- projectRaster(raster.eugrd025, pr) On Fri, Jul 2, 2010 at 1:46 AM, Michael Sumner <mdsumner at gmail.com> wrote:
spTransform cannot reproject a grid - this will (usually) requires destructive resampling of the data to a completely new grid. There are functions in the raster package to do this: projectRaster. I think this would work, but there may be important details that you will need to investigate: raster.eugrd025 <- raster(eugrd025) eugrd025EFDC <- projectRaster(raster.eugrd025, CRSobj=CRS(projection(eugrd025EFDC_SPDF))) On Fri, Jul 2, 2010 at 1:40 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
Hi! I use spTransform to reproject:
class(eugrd025)
[1] "SpatialGrid" attr(,"package") [1] "sp"
projection(eugrd025)
[1] "+proj=longlat +ellps=WGS84"
eugrd025EFDC <- spTransform(eugrd025, CRSobj=CRS(projection(eugrd025EFDC_SPDF)))
projection(eugrd025EFDC)
[1] "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs" This is good, but:
class(eugrd025EFDC)
[1] "SpatialPoints" attr(,"package") [1] "sp" Why is the class changed to SpatialPoints? I need a grid object for
eugrd025EFDCr <- raster(eugrd025EFDC) Br025 <- resample(Br,eugrd025EFDCr)
don't I? I also have the problem that the CRS of eugrd025EFDCr is not conserved:
projection(Br)
[1] "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs"
projection(eugrd025EFDC)
[1] "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs"
projection(eugrd025EFDCr)
[1] "NA" which I fix with
projection(eugrd025EFDCr) <- CRS(projection(eugrd025EFDC))
and repeat
Br025 <- resample(Br,eugrd025EFDCr)
Anyway, I get a much coarser raster than I want:
dim(Br025)
[1] 10 10 ?1 because
dim(eugrd025EFDCr)
[1] 10 10 ?1 While it should be 180x100:
summary(eugrd025EFDC)
Object of class SpatialPoints Coordinates: ? ? ? min ? ? max s1 2498538 6561151 s2 1327858 4313263 Is projected: TRUE proj4string : [+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs] Number of points: 18000
dim(Br025)
[1] 10 10 ?1
summary(eugrd025)
Object of class SpatialGrid Coordinates: ? ? ? ? ? ? ?min ? ?max coords.x1 -10.125 34.875 coords.x2 ?34.875 59.875 Is projected: FALSE proj4string : [+proj=longlat +ellps=WGS84] Number of points: 2 Grid attributes: ?cellcentre.offset cellsize cells.dim 1 ? ? ? ? ? ? ? -10 ? ? 0.25 ? ? ? 180 2 ? ? ? ? ? ? ? ?35 ? ? 0.25 ? ? ? 100 Is eugrd025EFDCr wrong because class(eugrd025EFDC) has been changed from SpatialGrid to SpatialPoints? Agus
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo