0
votes

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.

2
What language / library are you using? Please add the relevant tag to your question.assylias

2 Answers

3
votes

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

The projection information you are using seems incorrectly formatted. This may result in the function not recognizing the arguments in the projection string. As specified in rgdal, the projection information must adhere to PROJ.4 documentation (i.e., no spaces between += and a space separating arguments. For instance: "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100" Changing your paste function argument to sep=" " may fix this.