2013-04-23 50 views
0

我想要选择分离线路层的节点。我只想选择两条线相交的节点,而不是当它们与两条以上的线相交(例如,T交叉点或四路相交等)。选择节点分隔线段

这是我能给的最好的照片(我没有声望张贴照片)。左边的---第一条线和右边的--x - x - x线。 O是我想要选择的中间节点。

-------------------------------------- 0 - x --- x - x --- x --- x --- x - x - x - x - x - x - x - x

我不想选择多于两条线接触节点。

到目前为止,我已经尝试此查询

CREATE TABLE contacts_st_touching_faults as 
SELECT ST_Intersection(a.the_geom, b.the_geom), Count(Distinct a.gid) = 2 
FROM final_layer as a, final_layer as b 
WHERE ST_Touches(a.the_geom, b.the_geom) 
AND a.gid != b.gid 
GROUP BY ST_Intersection(a.the_geom, b.the_geom) 

当我运行此查询它给我交点有两个以上的线相交(T交叉点和4路交叉口)。

我也尝试在ST_intersects中进行subing,并且似乎不像ST_touches那样工作,但是如果您知道如何使它们工作或使用其他方法,那将非常感谢!

感谢您的帮助!

回答

0

这应该工作:

WITH contacts AS(
SELECT a.gid AS gid1,b.gid AS gid2, ST_Intersection(a.the_geom, b.the_geom) AS intersection 
FROM final_layer as a, final_layer as b 
WHERE ST_Touches(a.the_geom, b.the_geom) 
AND a.gid<b.gid 
) 
SELECT * 
FROM contacts c1 
LEFT JOIN contacts c2 
    ON ((c1.gid1=c2.gid1 AND c1.gid2<>c2.gid2) OR (c1.gid1=c2.gid2 AND c1.gid1<>c1.gid2)) 
    AND c1.intersection=c2.intersection 
WHERE c2.gid1 IS NULL; 

如果ST_Intersection移动到最后的查询,但我想让它简单它会表现得更好。

+0

真棒感谢使其简单!我甚至可以理解发生了什么事!查询运行没有错误,但是,我仍然没有选择。查询对我有意义,所以我不知道为什么它没有选择。你是否也意味着AND a.gid <> b.gid - 防止重复?谢谢! – Cindy 2013-04-24 15:54:41

+1

不,我的意思是a.gid 2013-04-24 16:04:55

+0

好的,谢谢!这是有道理的 – Cindy 2013-04-24 16:18:30

0

这将列出拖曳线相交的节点。

 

    SELECT array_agg(gid) AS gids, count(gid) AS count, geom 
    FROM 
     -- lists all vertices (points) from lines 
     (SELECT gid, (ST_DumpPoints(geom)).geom AS geom 
     FROM lines_layer) AS p 
    GROUP BY p.geom 
    HAVING count(gid) = 2 
    ORDER BY count(gid); 

对于所有节点,以 '> 1' 替换 '= 2'