Returns the part of geometry A that does not intersect with geometry B.
Syntax
geometry ST_Difference(geometry geomA, geometry geomB);Parameters
| Parameter | Description |
|---|---|
geomA | The first geometry object. |
geomB | The second geometry object. |
Usage notes
If
geomAis completely contained withingeomB, the function returns an empty geometry.The order of the input geometry objects affects the output.
ST_Difference(A, B)andST_Difference(B, A)produce different results.GeometryCollectionobjects are not supported.For 3D geometries, the function processes only the X and Y coordinates but preserves the original Z coordinates in the output.
Example
SELECT ST_AsText(ST_Difference('LINESTRING(0 0,0 2)'::geometry,'LINESTRING(0 1,0 3)'::geometry));
st_astext
---------------------
LINESTRING(0 0,0 1)
(1 row)该文章对您有帮助吗?