문제

I have the following query which does a self join with a table and outputs all the points of intersections between lines.

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

BUT it outputs duplicate values for each point of intersection since it computes the point of intersection for each road. EG:

70;71;POINT_OF_INTERSECTION

71;70;POINT_OF_INTERSECTION

70 AND 71 are both id values of two distinct roads. As you can see the point of intersection has been computed twice for the same two roads.

Any suggestions how i can solve this issue and only one point of intersection would be computed?

도움이 되었습니까?

해결책

Try something like:

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

It will leave only one of the intersections (the one, where the first road has smaller id)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top