名称

ST_SymDifference — 计算表示几何图形 A 和 B 不相交部分的几何图形。

大纲

geometry ST_SymDifference(geometry geomA, geometry geomB, float8 gridSize = -1);

描述

返回表示几何图形 A 和 B 不相交部分的几何图形。 这相当于ST_Union(A,B) - ST_Intersection(A,B)。 之所以称为对称差,是因为 ST_SymDifference(A,B) = ST_SymDifference(B,A)

If the optional gridSize parameter is given (GEOS-3.9.0 or higher required), all result vertices are guaranteed to fall on a snap-rounded grid of the specified size. Note that operations performed on a grid may contain small artifacts produced during grid alignment, see ST_ReducePrecision.

它是通过GEOS模块实现的

增强:3.1.0 接受 gridSize 参数。

需要 GEOS >= 3.9.0 才能使用 gridSize 参数

此方法实现了 SQL 1.1 的 OGC 简单功能规范。 s2.1.1.3

该方法实现了SQL/MM规范。 SQL-MM 3: 5.1.21

该函数支持 3d 并且不会丢失 z-index。 但是,结果仅使用 XY 计算。 结果 Z 值被复制、平均或插值。

示例

This example shows a 2D-safe symmetric difference of two LineStrings.

Code
SELECT ST_SymDifference('LINESTRING(50 100,50 200)',
        'LINESTRING(50 50,50 150)'
    );
栅格输出
MULTILINESTRING((50 150,50 200),(50 50,50 100))
Figure
Geometry figure for visual-st-symdifference-01

In 3D, this example does not produce the expected result.

Code
SELECT ST_SymDifference('LINESTRING(1 2 1,1 4 2)',
    'LINESTRING(1 1 3,1 3 4)');
栅格输出
MULTILINESTRING((1 3 4,1 4 2),(1 1 3,1 2 1))
Figure
Geometry figure for visual-st-symdifference-02