【问题标题】:Convert North and East coordinates to longitude and latitude in R将北和东坐标转换为R中的经度和纬度
【发布时间】:2016-10-09 12:57:54
【问题描述】:

不确定所有地理术语,但我正在寻找一种在 R 中从如下坐标转换的方法:

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

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

48.434722, 7.776667

【问题讨论】:

    标签: r geolocation coordinates latitude-longitude sp


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多