ST_LineCrossingDirection — 返回一个数字,指示两个 LineString 的交叉行为
integer ST_LineCrossingDirection(
geometry linestringA, geometry linestringB)
;
给定两条线串,返回一个介于 -3 和 3 之间的整数,表示它们之间存在的交叉行为类型。0 表示没有交叉。此函数仅支持 LINESTRING
。
交叉数字具有以下含义:
0:线不交叉
-1:线交叉向左
1:线交叉向右
-2:线多重交叉末端向左
2:线多重交叉末端向右
-3:线多重交叉末端相同首个向左
3:线多重交叉末端相同首个向右
可用性:1.4
示例:线交叉向左和线交叉向右
SELECT ST_LineCrossingDirection(lineA, lineB) As A_cross_B, ST_LineCrossingDirection(lineB, lineA) As B_cross_A FROM (SELECT ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As lineA, ST_GeomFromText('LINESTRING (20 140, 71 74, 161 53)') As lineB ) As foo; A_cross_B | B_cross_A -----------+----------- -1 | 1
示例:线多重交叉末端相同首个向左和线多重交叉末端相同首个向右
SELECT ST_LineCrossingDirection(lineA, lineB) As A_cross_B, ST_LineCrossingDirection(lineB, lineA) As B_cross_A FROM (SELECT ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As lineA, ST_GeomFromText('LINESTRING(171 154,20 140,71 74,161 53)') As lineB ) As foo; A_cross_B | B_cross_A -----------+----------- 3 | -3
示例:线多重交叉末端向左和线多重交叉末端向右
SELECT ST_LineCrossingDirection(lineA, lineB) As A_cross_B, ST_LineCrossingDirection(lineB, lineA) As B_cross_A FROM (SELECT ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As lineA, ST_GeomFromText('LINESTRING(5 90, 71 74, 20 140, 171 154)') As lineB ) As foo; A_cross_B | B_cross_A -----------+----------- -2 | 2
示例:查找所有交叉的街道
SELECT s1.gid, s2.gid, ST_LineCrossingDirection(s1.geom, s2.geom) FROM streets s1 CROSS JOIN streets s2 ON (s1.gid != s2.gid AND s1.geom && s2.geom ) WHERE ST_LineCrossingDirection(s1.geom, s2.geom) > 0;