【问题标题】:How to get points (latitude and longitude) between two point (Point A and Point B) in PostGIS?如何在 PostGIS 中的两点(A 点和 B 点)之间获取点(纬度和经度)?
【发布时间】:2021-10-29 21:35:09
【问题描述】:

A 正在使用 PostGIS (OSM),但我没有解决方案如何获取两点(A 点和 B 点)之间位置(纬度和经度)的点。我知道 ST_Distance 函数,但是这个函数不返回带有位置的点,这个函数只计算点之间的距离。如何获得位置积分?

【问题讨论】:

    标签: java sql postgresql postgis openstreetmap


    【解决方案1】:

    假设您要检索的点是道路上的位置(线串),您可以在两个点之间分割线串,然后选择重叠或靠近它的点。

    考虑这些点和线串,分别存储在表pointsline中:

    您可以使用函数ST_LineLocatePoint 来获取在线中给定点的确切位置,并且使用这些位置,您可以使用ST_LineSubstring 将线串切割 成一个子集。使用此子集,您可以检查哪些点相交或靠近它。以下示例检索沿线位于 POINT(-4.71 54.12)POINT(-4.53 54.21) 之间的点 - 第二个和上一个最后一个点:

    SELECT points.geom
    FROM line
    JOIN points ON 
      ST_Intersects(
        points.geom,
        ST_LineSubstring(
         line.geom,
         ST_LineLocatePoint(line.geom,'SRID=4326;POINT(-4.71 54.12)'::geometry),
         ST_LineLocatePoint(line.geom,'SRID=4326;POINT(-4.53 54.21)'::geometry)))
    

    演示:db<>fiddle

    【讨论】:

    • 此代码与我的表不工作。我有这些表:planet_osm_line、planet_osm_point、planet_osm_polygon、planet_osm_roads、spatial_ref_sys。我在 sql 代码中重命名了表名,但该代码仍然不起作用,错误:SQL 错误 [XX000]:错误:LWGEOM_line_locate_point:对混合 SRID 几何图形的操作(LineString,3857)!=(Point,4326)
    • 从 planet_osm_line 选择 ST_AsText(planet_osm_point.way) 在 ST_Intersects (planet_osm_point.way, ST_LineSubstring(planet_osm_line.way, ST_LineLocatePoint(planet_osm_line.way,'SRID=4326;POINT(41.574449 60.6003)'): :geometry), ST_LineLocatePoint(planet_osm_line.way,'SRID=4326;POINT(41.554493 60.599424)'::geometry)));
    • @TakhirAtamuratov 它不起作用,因为您在处理时混合了不同的 SRS(4326 和 3857)坚持其中之一。
    • 我应该使用什么 SRID 来获得正确的位置点?随着SRID = 4326我得到例外,SRID = 3857我得到下一个参数,我想他们是不是位置点(7381341.7930422 4662469.03295133)POINT(7381380.59901669 4662627.87924187)POINT(7381380.59901669 4662627.87924187)POINT(7380389.79988888 4661831.66459254)POINT(7378260.3025578 4656745.9033563)要点(7379854.14163114 4660894.71678399) POINT(7380301.38994929 4661624.78510236) POINT(7383469.35341414 4670214.98696365)
    • @TakhirAtamuratov 您必须将它们转换为 4326。看看ST_Transform
    猜你喜欢
    • 2019-11-05
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2015-11-13
    相关资源
    最近更新 更多