[R-sig-Geo] spTransform changes the class

Michael Sumner mdsumner at gmail.com
Thu Jul 1 17:48:37 CEST 2010


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
>>
>



More information about the R-sig-Geo mailing list