ST_Within — 测试 A 的每个点是否都位于 B 中,并且它们的内部是否有一个共同点
boolean ST_Within(geometry A, geometry B);
如果几何对象 A 完全包含在几何对象 B 内部(即 A 的所有点都在 B 的内部或边界上),并且 A 和 B 的内部至少有一个公共点,则返回 TRUE。等价地,A 在 B 中,当且仅当 A 的所有点都位于 B 的内部(包括边界),且 A 和 B 的内部至少有一个点重叠。
为了使此函数有意义,源几何图形必须具有相同的坐标投影,并具有相同的 SRID。
用数学术语来说: ST_Within(A, B) ⇔ (A ⋂ B = A) ∧ (Int(A) ⋂ Int(B) ≠ ∅)
内部关系是自反的:每个几何体都在其自身之内。 该关系是反对称的:如果 ST_Within(A,B) = true 且 ST_Within(B,A) = true,则两个几何图形在拓扑上必须相等 (ST_Equals(A,B) = true)。
ST_Within 与 ST_Contains 相反。 因此,ST_Within(A,B) = ST_Contains(B,A)。
|
|
|
因为内部必须有一个公共点,所以定义的一个微妙之处在于,完全位于多边形或线的边界内的线和点不在几何内部。 有关更多详细信息,请参阅 OGC覆盖、包含、内部的微妙之处。 ST_CoveredBy 谓词提供了更具包容性的关系。 |
|
|
|
此功能自动包括利用几何上可用的任何空间索引的边界框比较。 要避免使用索引,请使用函数 |
它是通过GEOS模块实现的
增强:对于 2.3.0 几何图形,PIP 短路(仅限于多边形和点的快速判断)已得到增强,以支持由更少点组成的多点。 以前的版本仅支持面和点组合。
增强:3.0.0 启用了对 GEOMETRYCOLLECTION 的支持
|
|
|
请勿将此函数用于无效的几何图形。 你会得到意想不到的结果。 |
注意:这是返回布尔值而不是整数的“允许”版本。
此方法实现了 SQL 1.1 的 OGC 简单功能规范。 s2.1.1.2 // s2.1.13.3 - a.Relate(b, 'T*F**F***')
该方法实现了SQL/MM规范。 SQL-MM 3: 5.1.30
This example defines two concentric circles once in a CTE so the same inputs can be rendered and then reused in related predicate checks.
WITH circles AS (
SELECT ST_Buffer(center, 20) AS smallc,
ST_Buffer(center, 40) AS bigc
FROM (SELECT 'POINT(50 50)'::geometry AS center) AS p
)
SELECT smallc AS small_circle,
bigc AS big_circle
FROM circles;
POLYGON((70 50,69.616 46.098,68.478 42.346,66.629 38.889,64.142 35.858,61.111 33.371,57.654 31.522,53.902 30.384,50 30,46.098 30.384,42.346 31.522,38.889 33.371,35.858 35.858,33.371 38.889,31.522 42.346,30.384 46.098,30 50,30.384 53.902,31.522 57.654,33.371 61.111,35.858 64.142,38.889 66.629,42.346 68.478,46.098 69.616,50 70,53.902 69.616,57.654 68.478,61.111 66.629,64.142 64.142,66.629 61.111,68.478 57.654,69.616 53.902,70 50)) | POLYGON((90 50,89.231 42.196,86.955 34.693,83.259 27.777,78.284 21.716,72.223 16.741,65.307 13.045,57.804 10.769,50 10,42.196 10.769,34.693 13.045,27.777 16.741,21.716 21.716,16.741 27.777,13.045 34.693,10.769 42.196,10 50,10.769 57.804,13.045 65.307,16.741 72.223,21.716 78.284,27.777 83.259,34.693 86.955,42.196 89.231,50 90,57.804 89.231,65.307 86.955,72.223 83.259,78.284 78.284,83.259 72.223,86.955 65.307,89.231 57.804,90 50))
Using the same circles, ST_Within is reflexive on each circle, false from the larger circle into the smaller one, and true for ST_Union only when the union does not extend beyond the larger circle.
WITH circles AS (
SELECT ST_Buffer(center, 20) AS smallc,
ST_Buffer(center, 40) AS bigc
FROM (SELECT 'POINT(50 50)'::geometry AS center) AS p
)
SELECT
ST_Within(smallc, smallc) AS smallinsmall,
ST_Within(smallc, bigc) AS smallinbig,
ST_Within(bigc, smallc) AS biginsmall,
ST_Within(ST_Union(smallc, bigc), bigc) AS unioninbig,
ST_Within(bigc, ST_Union(smallc, bigc)) AS biginunion,
ST_Equals(bigc, ST_Union(smallc, bigc)) AS bigisunion
FROM circles;
t | t | f | t | t | t