【问题标题】:Projection of a GPS point on a polyline consisting of other GPS pointsGPS 点在由其他 GPS 点组成的折线上的投影
【发布时间】:2020-08-04 18:37:28
【问题描述】:

我想问是否有一种相当不错的方法可以将 GPS 点“投影”到由其他 GPS 点组成的折线。这个“投影”的结果应该是投影点在折线上的坐标。

我正在寻找类似的东西(我需要红色“X”点的 GPS 坐标):

提前感谢您的帮助

【问题讨论】:

    标签: r sf


    【解决方案1】:

    我建议您在函数sf::st_nearest_points() 上构建您的解决方案 - 它以线串的形式返回两个几何对象之间的最短路径。

    它将接受一个点和一条线作为参数。该函数需要投影其参数(因此没有纬度/经度 - 但很容易将结果重新投影回 WGS84)。

    由于函数返回线串,因此必须将sf::st_cast() 指向几何类型以获取线的开始和结束。

    由于您的示例不容易重现,因此我将在布拉格地理编码地址和伏尔塔瓦河上最近点的一个有点复杂的示例中演示该方法。河流作为一条线和地理编码功能来自 RCzechia 包,与您的问题完全无关。

    您需要的是投影坐标参考系中的一条线和一个点。

    library(sf)
    library(dplyr)
    library(RCzechia) # Czech spatial objects to have some data to work with...
    
    # an address in Prague
    free_point <- RCzechia::geocode("pplk. Sochora 4, Praha 7") %>% 
      filter(typ == "AdresniMisto") %>% 
      st_transform(5514) #↨a local projected CRS
    
    
    # a piece of river (to have a linestring)
    vltava <- RCzechia::reky() %>% 
      filter(NAZEV == "Vltava") %>% 
      st_transform(5514) %>%  #↨a local projected CRS
      st_intersection(sf::st_buffer(free_point, 2500)) %>% # a buffer of 2500 meters around point
      st_geometry() %>% 
      st_union() %>% 
      st_line_merge()
    
    # the interesting part starts here!!!
    
    # a line from address to the closest point on the river
    closest_line <- st_nearest_points(st_geometry(vltava),
                                      st_geometry(free_point)) 
    
    # start of the line - this is what I seek :)
    closest_point <- st_cast(closest_line, to = "POINT")[1]
    
    # report results
    plot(st_geometry(vltava))
    plot(free_point, pch = 4, col = "red", add = T)
    plot(closest_point, pch = 4, col = "blue", add = T)
    

    【讨论】:

    • 感谢您的反应,我有一个数据框,其中包含折线的 GPS 点和一个我想在这条线上投影的 GPS 点 - 想从这一点找到折线上最近的点。但我想我找到了使用 dist2Line 函数的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多