【问题标题】:R - Problems with converting UTM coordinates with the rgdal packageR - 使用 rgdal 包转换 UTM 坐标的问题
【发布时间】:2017-06-11 18:01:10
【问题描述】:

我的任务是将大量 UTM 坐标(33 区)转换为经纬度 (WGS84) 坐标。这些位置应该位于挪威边境附近。我尝试使用 rgdal 包转换 R 中的坐标

#extracting some examples from data set

lat <- c(7790281, 7726438, 7266202, 7259480, 7271802)
long <- c(1053817, 1054025, 451754, 475228, 462235)
df <- data.frame(lat, long)

#converting from UTM33 to WGS84

library(rgdal)
tmp <- data.frame(coords.x = df$lat, coords.y = df$long)
coordinates(tmp) <-c("coords.x","coords.y")
proj4string(tmp) <- CRS("+proj=utm +zone=33 ellps=WGS84") #UTM zone 33
CRS.new <- CRS("+init=epsg:4326") # WGS84
coords <- spTransform(tmp,CRS.new)

#making a dataframe out of coordinates
coords <- data.frame(lat=coords@coords[,1], long=coords@coords[,2])

这会产生

       lat     long
1 69.19936 5.840162
2 68.92219 5.857922
3 66.55129 2.585804
4 66.52160 2.721701
5 66.58242 2.644578

但是,当使用在线转换工具 (http://www.rcn.montana.edu/resources/converter.aspx) 转换坐标时,我得到以下不同的结果

  lat.corr long.corr
1 69.63112  29.37223
2 69.07562  29.00514
3 65.51455  13.95675
4 65.45688  14.46554
5 65.56618  14.18178

在同一张地图中绘制两个数据集时,可以清楚地看到用 rgdal 转换的点放错了位置。

Map

如果我试图了解问题所在,但经过数小时的考虑和研究,我仍然无法找到它。非常有义务帮助找出问题所在!

编辑:它可能与跨越 UTM 区域边界的东坐标有关。会不会是 rgdal 有问题?

【问题讨论】:

    标签: r coordinates gis coordinate-transformation rgdal


    【解决方案1】:

    我猜你把纬度和经度混合在了

    tmp <- data.frame(coords.x = df$lat, coords.y = df$long)
    

    应该是:

    tmp <- data.frame(coords.x = df$lon, coords.y = df$lat)
    

    你会得到:

    > (coords <- data.frame(lon=coords@coords[,1], lat=coords@coords[,2]))
       lon     lat
    1 29.37172 69.63114
    2 29.00472 69.07564
    3 13.95675 65.51455
    4 14.46554 65.45688
    5 14.18178 65.56618
    

    【讨论】:

    • 我怎么这么瞎!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-08-06
    • 2023-04-03
    • 2019-06-04
    • 2021-07-18
    • 2021-06-04
    • 2012-07-23
    • 1970-01-01
    • 2015-07-13
    相关资源
    最近更新 更多