ST_LineCrossingDirection — Renvoie un nombre indiquant le comportement de croisement de deux LineStrings
integer ST_LineCrossingDirection(geometry linestringA, geometry linestringB);
En ayant 2 lignes en entrée, renvoie un nombre entier entre -3 et 3 indiquant le type de croisement qui existe entre elles. 0 indique qu'il n'y a pas de croisement. Cette fonction n'est prise en charge que pour les LINESTRINGs.
Le numéro de croisement a la signification suivante :
0 : LIGNE SANS CROISEMENT
-1 : LIGNE CROISÉE À GAUCHE
-1 : LIGNE CROISÉE À DROITE
-2 : LIGNE MULTICROISEMENT EXTRÉMITÉ GAUCHE
-2 : LIGNE MULTICROISEMENT EXTRÉMITÉ DROITE
-3 : LIGNE MULTICROISEMENT FIN IDENTIQUE AU PREMIER GAUCHE
-3 : LIGNE MULTICROISEMENT FIN IDENTIQUE AU PREMIER DROITE
Disponibilité : 1.4
Exemple: LIGNE CROISEE A GAUCHE et LIGNE CROISEE A DROITE
Bleu : Ligne A ; Vert : Ligne B
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
Exemple: LIGNE MULTICROISEMENT FIN IDENTIQUE AU PREMIER GAUCHE et LIGNE MULTICROISEMENT FIN IDENTIQUE AU PREMIER DROITE
Bleu : Ligne A ; Vert : Ligne B
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
Exemple: LIGNE MULTICROISEMENT EXTRÉMITÉ GAUCHE et LIGNE MULTICROISEMENT EXTRÉMITÉ DROITE
Bleu : Ligne A ; Vert : Ligne B
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
Exemple: Trouve toutes les rues qui se croisent
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;