【问题标题】:Distance between sequential points postgres顺序点之间的距离 postgres
【发布时间】:2015-11-11 10:26:05
【问题描述】:

我的表如下

1;"2015-10-02";"POINT(lat,lon) as geometry"
2;"2015-10-03";"POINT(lat,lon) as geometry"
3;"2015-10-04";"POINT(lat,lon) as geometry"

如何找到两个连续点之间的距离?

所以我有 id=1 和 id=2 它们之间的距离 = 99m(距离会在 [1,2],[2,3],[3,4] 等之间找到

那么如果距离

我还没有走太远

这给了我距离,但我不知道如何获得下一行的几何图形

SELECT st_distance_sphere(t.latlon,next.latlon) from test as t where id=1

然后我尝试将距离作为附加列读取,但可以找出正确的查询

UPDATE test SET dist=ST_Distance(test.latlon, next.geom) 
FROM (SELECT latlon FROM test WHERE id = test.id + 1) into b;

1;"2015-10-02";"POINT(lat,lon) as geometry";distance between 1 and 2
2;"2015-10-03";"POINT(lat,lon) as geometry";distance between 2 and 3
3;"2015-10-04";"POINT(lat,lon) as geometry";distance between 3 and 4

【问题讨论】:

    标签: postgresql postgis


    【解决方案1】:

    要获取当前点和下一个点之间的距离,您可以像这样使用window function lead

    select
            test.*,
            st_distance(latlon, lead(latlon, 1, latlon) over(order by id)) as distance
        from test;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 2014-11-29
      • 2020-04-27
      • 2019-01-23
      • 2012-07-17
      • 2020-02-14
      • 1970-01-01
      相关资源
      最近更新 更多