简体   繁体   English

经纬度到UTM坐标

[英]Latitude and Longitude to UTM coordinates

I have a big latitude longitude information from the UTM-zone 33 north. 我从北UTM区33获得了很大的纬度经度信息。

I tried the following commands to convert this geographical information to UTM coordinates (my data set object is initially called S3km): 我尝试使用以下命令将此地理信息转换为UTM坐标(我的数据集对象最初称为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 (ie R 2.15.2) and rgdal -package is also freshly downloaded. 我已经下载了最新的R版本(即R 2.15.2),并且也刚下载了rgdal

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 = "" . 正如Lucas指出的那样, PROJ4字符串的参数之间需要有空格,因此请使用sep = " "paste()的默认值),而不要使用sep = ""

  • In addition, functions in the sp and rgdal packages expect proj4strings to be wrapped in calls to the CRS() utility function. 此外, sprgdal软件包中的函数希望proj4strings可以包装在对CRS()实用程序函数的调用中。

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 

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 (ie, 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. 如rgdal中所指定,投影信息必须遵守PROJ.4文档(即+ =与参数之间不能有空格。例如:“ + proj = lcc + lat_1 = 48 + lat_2 = 33 + lon_0 = -100 “将粘贴函数参数更改为sep =“可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM