将纬度和经度点转换为UTM [英] Converting latitude and longitude points to UTM
问题描述
我找到了一个有关如何执行此操作的简单示例,但我无法使其正常工作。我对R相当陌生
I found a fairly simple example of how to do this but I cant get it to work for me. I'm pretty new to R
library(rgdal)
xy <- cbind(c(118, 119), c(10, 50))
project(xy, "+proj=utm +zone=51 ellps=WGS84")
[,1] [,2]
[1,] -48636.65 1109577
[2,] 213372.05 5546301
但这是示例编号。我有成千上万的坐标必须转换,我无法弄清楚如何将它们从表中转换为脚本
But this is with example numbers. I have thousands of coordinates I have to transform and I cant figure out how to get them from my table to into this script
我的数据集包含3列,ID,X ,和Y。如何使用此等式转换它们?我已经坚持了好几个星期
My data set has 3 columns, ID, X, and Y. How can I transform them using this equation? I've been stuck on this for weeks
推荐答案
为确保在与坐标关联的每一步都有适当的投影元数据,我建议尽快将点转换为 SpatialPointsDataFrame
对象。
To ensure that appropriate projection metadata are at every step associated with the coordinates, I'd suggest converting the points to a SpatialPointsDataFrame
object as soon as possible.
有关如何将简单data.frame或矩阵转换为的更多信息,请参见? SpatialPointsDataFrame-class
> SpatialPointsDataFrame 对象。
See ?"SpatialPointsDataFrame-class"
for more on how to convert simple data.frames or matrices to SpatialPointsDataFrame objects.
library(sp)
library(rgdal)
xy <- data.frame(ID = 1:2, X = c(118, 119), Y = c(10, 50))
coordinates(xy) <- c("X", "Y")
proj4string(xy) <- CRS("+proj=longlat +datum=WGS84") ## for example
res <- spTransform(xy, CRS("+proj=utm +zone=51 ellps=WGS84"))
res
# coordinates ID
# 1 (-48636.65, 1109577) 1
# 2 (213372, 5546301) 2
## For a SpatialPoints object rather than a SpatialPointsDataFrame, just do:
as(res, "SpatialPoints")
# SpatialPoints:
# x y
# [1,] -48636.65 1109577
# [2,] 213372.05 5546301
# Coordinate Reference System (CRS) arguments: +proj=utm +zone=51
# +ellps=WGS84
这篇关于将纬度和经度点转换为UTM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!