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は、両方ともid2つの異なる道路の値です。ご覧のとおり、交差点は同じ2つの道路に対して2回計算されています。

この問題を解決する方法と、1つの交点のみが計算される提案はありますか?

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

交差点の1つだけを残します(最初の道路のIDが小さい交差点)

于 2013-02-16T11:19:43.090 に答える