【问题标题】:Converting UTM coordinates to Lat/Long in R在 R 中将 UTM 坐标转换为纬度/经度
【发布时间】:2021-07-18 07:47:52
【问题描述】:

我正在尝试使用 R 将 UTM 坐标(东和北)转换为纬度/经度。我的数据示例如下:

dx dy
-17.551 17.062
-4.947 2.336
-17.265 3.956
-12.157 -2.043

这是我的代码:

    library(dplyr)
    library(ggmap)
    library(maps)
    library(rgdal)
    library(ggplot2)
    
    east<-as.numeric(ddata$dy)
    north<-as.numeric(ddata$dx)
    utm <- SpatialPoints(cbind(east,north), 
                 proj4string=CRS("+proj=utm +zone=59 +datume=WGS84 "))
    spTransform(utm, CRS("+proj=longlat +datum=WGS84"))

但是,我没有得到正确的纬度/经度值,因为数据是从新西兰收集的,所以纬度、经度值必须来自这个位置。如何更正此代码以生成正确的 lat 和 long 值?

这是我的数据的链接: https://drive.google.com/file/d/1X8pPFxV8ZBl1gAWOeYASG0BsnryovpyE/view?usp=sharing

我们将非常感谢您在这方面的任何帮助。

【问题讨论】:

  • 欢迎来到 Stack Overflow。请在问题中粘贴示例数据;使用dput(ddata)dput(head(ddata)) 使问题变得可重现,以便验证答案。 minimal reproducible example 提供有用的指导。
  • ddata 中有多少行?可能是 0 吗?
  • 能否在问题中包含您正在使用的软件包?
  • 您能否提供您收集数据的参考资料?是否定义了东向和北向?检查你的分配,通常经度等于 x 轴,即east &lt;- as.numeric(ddata$dx)
  • 数据中的变量是否有元数据?即对变量代表什么的解释。刚刚检查了 UTM 的定义,似乎南半球的纬度是用正值定义的,所以先前关于负纬度值的评论被撤回。你知道原始数据集中的x y 变量代表什么吗?

标签: r data-conversion utm


【解决方案1】:

这可能会有所帮助...

数据是问题中提供的链接的前 6 行和前 6 列。 使用x 变量作为经度,使用y 作为纬度。 在互联网上搜索显示新西兰的 crs 为 2193:新西兰横轴墨卡托,它至少将坐标放在新西兰。但你需要确认这一点。 坐标似乎彼此非常接近,因此所有点都在绘制的比例上重叠 - 我没有对此进行过实验。

https://www.linz.govt.nz/data/geodetic-system/datums-projections-and-heights/projections/new-zealand-transverse-mercator-2000


library(sf)
library(tmap)

df_sf <- st_as_sf(x = df,                         
                  coords = c("x", "y"),
                  crs =     2193)

data("World")
nz <-  World[World$name == "New Zealand", ]

tm_shape(nz, projection = "wgs84") +
  tm_polygons()+
  tm_grid()+
  tm_shape(df_sf, projection = "wgs84")+
  tm_dots("id", size = 0.5)

将UTM x、y坐标转换为经纬度

library(proj4)

# Find the projection proj4 description of the coordinate reference system (espg 2193)
#  I've used information from this link:
# https://spatialreference.org/ref/epsg/nzgd2000-new-zealand-transverse-mercator-2000/proj4/

proj4 <- "+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs "

# From the source data extract the x, y coordinates of the UTM
x_y <- df[, 1:2]

# Transform the data
lon_lat <- project(x_y, proj4, inverse = TRUE)

# convert to a data frame
data.frame(lon = lon_lat$x, lat = lon_lat$y)

#>        lon       lat
#> 1 132.3681 -71.33355
#> 2 132.3685 -71.33371
#> 3 132.3686 -71.33375
#> 4 132.3690 -71.33391
#> 5 132.3692 -71.33402
#> 6 132.3689 -71.33392

数据

df <- structure(list(id = 423:428, x = c(1455320.99774103, 1455303.44574159, 
                                         1455298.49781114, 1455281.23215399, 1455269.07477818, 1455280.83403596
), y = c(5131693.29609067, 5131710.35870728, 5131712.69526321, 
         5131716.65168218, 5131714.60800342, 5131734.86699543), date = c("2019-03-12 00:02:00", 
                                                                         "2019-03-12 00:04:49", "2019-03-12 00:07:37", "2019-03-12 00:10:24", 
                                                                         "2019-03-12 00:13:19", "2019-03-12 00:16:06"), dx = c(-17.5519994448405, 
                                                                                                                               -4.94793045334518, -17.2656571443658, -12.1573758164886, 11.7592577852774, 
                                                                                                                               16.6252572031226), dy = c(17.0626166081056, 2.33655592985451, 
                                                                                                                                                         3.95641897153109, -2.04367875494063, 20.2589920070022, -29.7507258579135
                                                                                                                               )), class = "data.frame", row.names = c(NA, 6L))

reprex package (v2.0.0) 于 2021 年 4 月 28 日创建

【讨论】:

  • 谢谢。我们如何提取经纬度值?
  • 好的。我们如何使用此脚本提取纬度和经度值?
  • 啊我明白了;添加了额外的代码来将经度和纬度提取到单独的数据框中。
猜你喜欢
  • 2015-07-13
  • 2011-02-11
  • 1970-01-01
  • 2016-07-30
  • 2020-12-02
  • 2021-07-31
  • 2013-02-14
  • 1970-01-01
  • 2015-08-06
相关资源
最近更新 更多