I have a big latitude longitude information from the UTM-zone 33 north.
I tried the following commands to convert this geographical information to UTM coordinates (my data set object is initially called S3km):
library(rgdal)
UTM33N<-"+proj=utm+zone=33+north"
UTM33N<-paste(UTM33N,"+ellps=WGS84",sep="")
UTM33N<-paste(UTM33N,"+datum=WGS84",sep="")
UTM33N<-paste(UTM33N,"+units=m+no_defs",sep="")
coord.UTM33N<-project(as.matrix(S3km[,c("Longitude","Latitude")]),UTM33N)
I got the following error message:
Error in project(as.matrix(S3km[,c("Longitude","Latitude")]),UTM33N):
no arguments in initialization list.
Does anyone know what is the problem? I have the newest R-version downloaded (i.e. R 2.15.2) and rgdal
-package is also freshly downloaded.
There seem to be at least a couple of problems with your code:
As Lucas points out, PROJ4 strings need spaces between the arguments, so use sep = " "
(paste()
's default) rather than sep = ""
.
In addition, functions in the sp and rgdal packages expect proj4strings to be wrapped in calls to the CRS()
utility function.
Here's a working example that you should be able to adapt to your situation:
library(rgdal)
## Create an example SpatialPoints object
pts <- SpatialPoints(cbind(-120:-121, 39:40),
proj4string = CRS("+proj=longlat +datum=NAD27"))
## Construct a proper proj4string
UTM11N <- "+proj=utm +zone=11 +datum=NAD83 +units=m +no_defs"
UTM11N <- paste(UTM11N, "+ellps=GRS80 +towgs84=0,0,0")
UTM11N <- CRS(UTM11N)
## Project your points
ptsUTM <- spTransform(pts, UTM11N)
## Check that it worked
ptsUTM
# SpatialPoints:
# coords.x1 coords.x2
# [1,] 240111.6 4321052
# [2,] 158420.9 4435418
# Coordinate Reference System (CRS) arguments: +proj=utm +zone=11
# +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0