Name

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

Synopsis

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)

如果可选的 gridSize 参数,则将输入捕捉到给定大小的栅格,并在该栅格上计算结果顶点。(需要GEOS-3.9.0或更高版本)

由GEOS模块执行

增强:3.1.0接受GRIDSIZE参数-需要GEOS > =3.9.0

This method implements the OGC Simple Features Implementation Specification for SQL 1.1. s2.1.1.3

This method implements the SQL/MM specification. SQL-MM 3:5.1.21

This function supports 3d and will not drop the z-index. 但是,结果仅使用XY计算。结果Z值被复制、平均或内插。

示例

原始线串显示在一起

两条线串的对称差

--Safe for 2d - symmetric difference of 2 linestrings
SELECT ST_AsText(
    ST_SymDifference(
        ST_GeomFromText('LINESTRING(50 100, 50 200)'),
        ST_GeomFromText('LINESTRING(50 50, 50 150)')
    )
);

st_astext
---------
MULTILINESTRING((50 150,50 200),(50 50,50 100))
--When used in 3d doesn't quite do the right thing
SELECT ST_AsEWKT(ST_SymDifference(ST_GeomFromEWKT('LINESTRING(1 2 1, 1 4 2)'),
    ST_GeomFromEWKT('LINESTRING(1 1 3, 1 3 4)')))

st_astext
------------
MULTILINESTRING((1 3 2.75,1 4 2),(1 1 3,1 2 2.25))
        

另请参阅

ST_Difference, ST_Intersection, ST_Union