我想选择分隔图层中线段的节点。我想只选择它们与两条线相交的节点,而不是当它们遇到两条以上的线时(例如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加入,并且看起来效果不如ST_touches,但如果你知道如何使它们工作或任何其他方法,那将非常感激!
感谢您的帮助!
答案 0 :(得分: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移动到最终查询,它会表现得更好,但我想让它变得简单。
答案 1 :(得分: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);
对于所有节点,将'= 2'替换为'&gt; 1'