经纬度到UTM坐标
我从北方的UTM区33获得了很大的纬度经度信息.
I have a big latitude longitude information from the UTM-zone 33 north.
我尝试了以下命令将此地理信息转换为UTM坐标(我的数据集对象最初称为S3km):
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)
我收到以下错误消息:
Error in project(as.matrix(S3km[,c("Longitude","Latitude")]),UTM33N):
no arguments in initialization list.
有人知道是什么问题吗?我已经下载了最新的R版本(即R 2.15.2),并且rgdal
-package也是最新下载的.
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:
-
正如Lucas指出的那样, PROJ4 字符串在参数之间需要空格,因此请使用
sep = " "
(默认为paste()
)而不是sep = ""
.
As Lucas points out, PROJ4 strings need spaces between the arguments, so use
sep = " "
(paste()
's default) rather thansep = ""
.
此外, sp 和 rgdal 软件包中的函数希望proj4strings可以包装在对CRS()
实用程序函数的调用中.
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