我找到了一个相当简单的例子来说明如何做到这一点,但我无法让它为我工作。我对 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
但这是示例数字。我有数千个坐标必须转换,但我不知道如何将它们从我的表中获取到这个脚本中
我的数据集有 3 列,ID、X 和 Y。如何使用此等式转换它们?我已经坚持了几个星期
最佳答案
为了确保在与坐标相关的每一步都有适当的投影元数据,我建议将点转换为 SpatialPointsDataFrame
尽快提出反对意见。
见 ?"SpatialPointsDataFrame-class"
有关如何将简单的 data.frames 或矩阵转换为 的更多信息空间点数据帧 对象。
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
关于r - 将纬度和经度点转换为 UTM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18639967/