跳转至
Apache Sedona 1.9.0 已正式发布,新增 Spark 4.1 支持、proj4sedona 坐标系转换、Bing Tile 函数等众多特性!

ST_Within

Introduction: Tests whether geography A is fully within geography B using S2 spherical boolean operations. Returns true when every point of A's interior lies in B's interior. By OGC convention, ST_Within(A, B) is equivalent to ST_Contains(B, A), and shares the same boundary semantics.

Boundary semantics on the sphere are inherited from S2's boolean operations and depend on each ring's vertex orientation: along an edge that is "owned" by B's boundary the test returns true, and along the opposite edge it returns false. Do not rely on a specific result for points that lie exactly on B's boundary; for predictable behavior, use a strict interior point or expand B slightly with ST_Buffer before testing.

ST_Within returning true ST_Within returning false

Format:

ST_Within (A: Geography, B: Geography)

Return type: Boolean

Since: v1.9.1

SQL Example — interior point:

SELECT ST_Within(
  ST_GeogFromWKT('POINT (0.5 0.5)', 4326),
  ST_GeogFromWKT('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', 4326)
);

Output:

true