【问题标题】:spatial data query空间数据查询
【发布时间】:2013-02-01 07:09:12
【问题描述】:

我有以下查询,它与表进行自连接并输出线之间的所有交点。

insert into road_intersection
select nextval('road_intersection_id_seq'), a.road_id, b.road_id, st_intersection(a.road, b.road), st_centroid(st_intersection(a.road, b.road))
from polygon_road a, polygon_road b
where st_intersects(a.road, b.road) AND a.road_id!=b.road_id

但它会为每个交叉点输出重复值,因为它会计算每条道路的交叉点。例如:

70;71;POINT_OF_INTERSECTION

71;70;POINT_OF_INTERSECTION

70 AND 71 都是 id 两条不同道路的值。如您所见,对于相同的两条道路,交叉点已计算了两次。

有什么建议可以解决这个问题并且只计算一个交点吗?

【问题讨论】:

    标签: sql postgresql geospatial postgis spatial-query


    【解决方案1】:

    尝试类似:

    select nextval('road_intersection_id_seq'), 
           a.road_id, 
           b.road_id, 
           st_intersection(a.road, b.road), 
           st_centroid(st_intersection(a.road, b.road))
    from polygon_road a, polygon_road b
    where st_intersects(a.road, b.road) 
      --AND a.road_id!=b.road_id --not needed any more
    
      AND a.road_id < b.road_id
    

    它将只留下一个交叉口(第一条道路的 id 较小的交叉口)

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 2011-07-27
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 2012-05-03
      相关资源
      最近更新 更多