[R-sig-Geo] projection() and proj4string()

Agustin Lobo alobolistas at gmail.com
Sat May 29 09:29:30 CEST 2010


Why do I have to use proj4string() instead of projection() in this example?

> class(Montseny20090409sh)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"

> projection(Montseny20090409sh)
[1] "+proj=utm +zone=31 +ellps=intl +units=m +no_defs"

> a<- SpatialPoints(coordinates(Montseny20090409sh))
> class(a)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"

> projection(a) <- projection(Montseny20090409sh)
Error in checkSlotAssignment(object, name, value) :
  "crs" is not a slot in class "SpatialPoints"
Calls: projection<- -> @<- -> slot<- -> checkSlotAssignment

> proj4string(a) <- projection(Montseny20090409sh)
> geogWGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
> aGW <- spTransform(a, geogWGS84)
> Montseny20090409sh2 <- Montseny20090409sh
> Montseny20090409sh2 at data <- cbind(Montseny20090409sh2 at data,coordinates(aGW))

Thanks for any clarification,

Agus



More information about the R-sig-Geo mailing list