On Wed, 6 Aug 2014, Remi Genevest wrote:

Hi,
I am facing a recurrent problem associated with spTransform() function from
rgdal package.
While I try to change the CRS of a SpatialGrid, I get the following error :

Error in spTransform(grd, CRS("+init=epsg:3857")) :
 load package rgdal for spTransform methods

Thanks for the example. You cannot use spTransform on SpatialGrid objects - this is known as warping, and does not return a regular grid in general. You can do:

grd<-spTransform(as(grd, "SpatialPoints"), CRS("+init=epsg:3857"))

but:

gridded(grd) <- TRUE
#suggested tolerance minimum: 0.223608
#Error in points2grid(points, tolerance, round) :
#  dimension 2 : coordinate intervals are not constant

Try warping instead.

Hope this clarifies,

Roger


Does anybody know how to solve it?

Here is my code :

library(rgdal)
# create the SpatialGrid
cc<-c(10,20)
cs<-c(0.1,0.1)
cd<-c(200,200)
grd<-GridTopology(cellcentre.offset=cc,cellsize=cs,cells.dim=cd)
grd<-SpatialGrid(grd)
# set the CRS :
proj4string(grd)<-CRS("+proj=longlat +datum=WGS84")
# transform the CRS :
grd<-spTransform(grd,CRS("+init=epsg:3857"))
Error in spTransform(grd, CRS("+init=epsg:3857")) :
 load package rgdal for spTransform methods

###################################################### R info session
sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
LC_MONETARY=en_GB.UTF-8
[6] LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C
LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods
base

other attached packages:
[1] rgdal_0.8-16    raster_2.2-31   hexbin_1.26.3   lattice_0.20-29
sp_1.0-15

loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.4     ggplot2_1.0.0    gtable_0.1.2
MASS_7.3-33      munsell_0.4.2    plyr_1.8.1       proto_0.3-10
Rcpp_0.11.2
[10] reshape2_1.4     scales_0.2.4     stringr_0.6.2    tools_3.1.1



--
View this message in context: 
http://r-sig-geo.2731867.n2.nabble.com/spTransform-error-load-package-rgdal-for-spTransform-methods-tp7586877.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: roger.biv...@nhh.no

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to