将北坐标和东坐标转换为R中的经度和纬度

时间:2016-06-09 03:40:50

标签: r geolocation coordinates latitude-longitude sp

不确定所有地理术语,但我在R中寻找一种方法来转换这样的坐标:

48° 26′ 5″ N, 7° 46′ 36″ E

经度和纬度。从geohack我知道这些坐标的答案是......

48.434722, 7.776667

1 个答案:

答案 0 :(得分:5)

char2dms(字符到度,分,秒)可以帮助你

library(sp)

as.numeric(char2dms("48° 26' 5\"N", chd = "°", chm = "'", chs='"'))
# [1] 48.43472

as.numeric(char2dms("7° 46' 36\"E", chd = "°", chm = "'", chs='"'))
# [1] 7.776667

参数chd,chm和chs分别确定识别度,分和秒的字符。 R中必须使用\字符(称为转义字符)来表示"是字符串的一部分。

您可以使用strsplit将初始字符串分隔为纬度和经度。

pos <- "48° 26' 5\"N , 7° 46'  36\" E"
pos <- unlist(strsplit(pos, ","))
as.numeric(char2dms(pos, chd = "°", chm = "'", chs='"'))  
# [1] 48.434722  7.776667
相关问题