2

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

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

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

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

4

1 回答 1

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较小的十字路口)

于 2013-02-16T11:19:43.090 回答