2013-02-16 33 views
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 

但它輸出每個交點的重複值,因爲它計算每條路的交點。 EG:

70;71;POINT_OF_INTERSECTION 

71;70;POINT_OF_INTERSECTION 

7071是兩個截然不同的道路都id值。正如你所看到的,交叉點已經爲相同的兩條道路計算了兩次。

任何建議如何我可以解決這個問題,只有一個交點將被計算?

回答

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)

+0

它的工作原理! :) 非常感謝 – 2013-02-16 11:32:45