跳转至
🎉 SedonaDB 0.4.0 已正式发布!🗺️ 新增 Python DataFrame API、R dplyr 接口、Geography 支持及 GPU 加速空间连接。阅读发布博客 →

ST_Intersection

Introduction: Return the intersection of A and B. Geometry inputs use planar overlay; Geography inputs use closed-set spherical overlay with geodesic edges.

ST_Intersection

Format:

ST_Intersection(A: Geometry, B: Geometry)

ST_Intersection(A: Geography, B: Geography)

Return type: Geometry or Geography, matching the input type

Since: v1.5.0 (Geometry), v1.9.1 (Geography)

Note

This note applies only to Geometry inputs. If you encounter a TopologyException with the message "found non-noded intersection", try enabling the OverlayNG algorithm by adding the following JVM flag:

-Djts.overlay=ng

The OverlayNG algorithm is more robust than the legacy overlay implementation in JTS and handles many edge cases that would otherwise cause errors.

Geometry example:

SELECT ST_Intersection(
    ST_GeomFromWKT("POLYGON((1 1, 8 1, 8 8, 1 8, 1 1))"),
    ST_GeomFromWKT("POLYGON((2 2, 9 2, 9 9, 2 9, 2 2))")
    )

Output:

POLYGON ((2 8, 8 8, 8 2, 2 2, 2 8))

For Geography inputs, boundary-only intersections are retained: crossing lines or touching polygon vertices can produce a Point, while shared polygon edges can produce a LineString. Polygon shells are normalized to an area of at most one hemisphere; a shell intended to represent more than half the sphere is interpreted as its complement. Results containing several dimensions are returned as a GeometryCollection.

The Geography result is two-dimensional and copies the first input's SRID without transforming either input or validating that their SRIDs match. An explicitly empty operand produces GEOMETRYCOLLECTION EMPTY. A disjoint result from two non-empty inputs preserves the lower input dimension.

Geography example:

SELECT ST_AsText(ST_Intersection(
    ST_GeogFromWKT('LINESTRING (0 -5, 0 5)', 4326),
    ST_GeogFromWKT('LINESTRING (-5 0, 5 0)', 4326)
));

Output:

POINT (0 0)