【问题标题】:Looping origin and destination coordinates in R在R中循环起点和终点坐标
【发布时间】:2014-12-02 20:12:46
【问题描述】:

我希望使用library(geosphere) 提供的distCosine 函数计算一组经度和纬度之间的大圆距离

结构如下

distCosine(c(Longo,Lato),c(Longd,Latd))

对于每一行,前两行的示例如下所示

      Longo     Lato    Longd     Latd
1 -2.098389 57.14816 4.965820 52.34876
2 -2.098389 57.14816 5.723877 58.96700

第一行的值应该是 700303.8

如何循环函数以计算第二行?

理想情况下,除此之外还有一种方法可以输出这些距离值

【问题讨论】:

    标签: r loops coordinates


    【解决方案1】:

    你可以试试

    distCosine(as.matrix(df[,1:2]), as.matrix(df[,3:4]))
    #[1] 700303.9 502835.0
    

    这似乎也有效,但 ?distCosine 不清楚

    distCosine(df[,1:2], df[,3:4])
    #[1] 700303.9 502835.0
    

    来自?distCosine

    distCosine(p1, p2, r=6378137)

    p1:点的经度/纬度。可以是两个向量 数字,一个 2 列的矩阵(第一个是经度, 第二个是纬度)或 SpatialPoints* 对象

    p2:同上

    数据

    df <- structure(list(Longo = c(-2.098389, -2.098389), Lato = c(57.14816, 
    57.14816), Longd = c(4.96582, 5.723877), Latd = c(52.34876, 58.967
    )), .Names = c("Longo", "Lato", "Longd", "Latd"), class = "data.frame", row.names = 
     c("1", "2"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多