PostGIS提供了若干拓扑关系函数,本文介绍如下函数:
1. ST_LineCrossingDirection #线之间的交叉方向
2. ST_Disjoint #不相交
3. ST_Equals #相等
ST_LineCrossingDirection-线之间的交叉方向
- 定义
integer ST_LineCrossingDirection(geometry linestringA, geometry linestringB);
- 说明
给定2个折线,返回一个介于-3和3之间的数字,表示什么样的交叉行为。0表示不交叉。
整数常量定义如下:
0: 线不交叉
-1:左交叉线
1:右交叉线
-2:多交叉线左端
2:多交叉线右端
-3:多交叉线第一个左端相同
3:多交叉线第一个右端相同
- 注意
- 此函数只支持LINESTRING。
- 示例
SELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (
SELECT
ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
ST_GeomFromText('LINESTRING(171 154,20 140,71 74,161 53)') As line2
) As foo;
l1_cross_l2 | l2_cross_l1
-------------+-------------
3 | -3
SELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (
SELECT
ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
ST_GeomFromText('LINESTRING (171 154, 20 140, 71 74, 2.99 90.16)') As line2
) As foo;
l1_cross_l2 | l2_cross_l1
-------------+-------------
2 | -2
SELECT
ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (
SELECT
ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
ST_GeomFromText('LINESTRING (20 140, 71 74, 161 53)') As line2
) As foo;
l1_cross_l2 | l2_cross_l1
-------------+-------------
-1 | 1
SELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (SELECT
ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
ST_GeomFromText('LINESTRING(2.99 90.16,71 74,20 140,171 154)') As line2
) As foo;
l1_cross_l2 | l2_cross_l1
-------------+-------------
-2 | 2
ST_Disjoint-不相交
- 定义
boolean ST_Disjoint( geometry A , geometry B );
- 说明
重叠,接触,在所有的几何对象不在空间上不相交。如果上述任何一个返回true,则几何体在空间上不相交。不相交表示空间相交为假。 - 注意
- 此函数不使用空间索引
- 示例
SELECT ST_Disjoint('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry);
st_disjoint
---------------
t
(1 row)
SELECT ST_Disjoint('POINT(0 0)'::geometry, 'LINESTRING ( 0 0, 0 2 )'::geometry);
st_disjoint
---------------
f
(1 row)
ST_Equals-相等
- 定义
boolean ST_Equals(geometry A, geometry B);
- 说明
如果给定的几何“空间相等”,则返回TRUE。 将此答案用于比“ =”更好的答案。 注意,在空间上相等意味着我们意味ST_Within(A,B)= true
和ST_Within(B,A)= true
,也意味着点的顺序可以不同,但表示相同的几何结构。 要验证点的顺序是否一致,请使用ST_OrderingEquals
(必须注意,ST_OrderingEquals
比仅验证点的顺序相同要严格一些)。。 - 注意
- 如果任一几何均无效,则该函数将返回false,除非它们是二进制相等的。
- 示例
SELECT ST_Equals(ST_GeomFromText('LINESTRING(0 0, 10 10)'),
ST_GeomFromText('LINESTRING(0 0, 5 5, 10 10)'));
st_equals
-----------
t
(1 row)
SELECT ST_Equals(ST_Reverse(ST_GeomFromText('LINESTRING(0 0, 10 10)')),
ST_GeomFromText('LINESTRING(0 0, 5 5, 10 10)'));
st_equals
-----------
t
(1 row)