Returns the part of geometry A that does not intersect geometry B.
Syntax
geometry ST_Difference(geometry geomA, geometry geomB)Parameters
| Parameter | Description |
|---|---|
geomA | The source geometry. The result is always a portion of this geometry. |
geomB | The geometry to subtract from geomA. |
Usage notes
Input order matters.
ST_Difference(A, B)always returns a portion of A.If
geomAis completely contained withingeomB, the function returns an empty geometry.GeometryCollectioninputs are not supported.For 3D geometries, the function computes the difference using X and Y coordinates only. Z coordinate values in the result are preserved from the input geometries (z coordinates are not deleted).
Examples
The following example returns the segment of the first line that does not overlap with the second line:
SELECT ST_AsText(
ST_Difference(
'LINESTRING(0 0,0 2)'::geometry,
'LINESTRING(0 1,0 3)'::geometry
)
);Result:
st_astext
---------------------
LINESTRING(0 0,0 1)
(1 row)该文章对您有帮助吗?