[R-sig-Geo] spTransform changes the class
Agustin Lobo
alobolistas at gmail.com
Thu Jul 1 17:40:18 CEST 2010
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
More information about the R-sig-Geo
mailing list