ST_Within — 如果A的点都不在B的外部,并且A和B至少有一个内点相同,则返回TRUE。
boolean
ST_Within
(
geometry
A
, geometry
B
)
;
如果几何图形A完全位于几何图形B内,则返回TRUE。要使此函数有意义,源几何图形必须具有相同的坐标投影,且具有相同的SRID。可以肯定的是,如果ST_in(A,B)为真,ST_in(B,A)为真,则认为这两个几何空间相等。
此定义的一个微妙之处在于,几何体的边界不在该几何体内。这意味着位于面或线边界内的线和点 不 在几何体内。有关更多详细信息,请参阅 OGC封面的精妙之处,包含,内 。( ST_CoveredBy 谓词提供了更具包容性的关系)。
ST_WITHING是的反方向
ST_Contains
。所以,
ST_Within(A,B) = ST_Contains(B,A)
。
![]() |
|
This function automatically includes a bounding box comparison
that makes use of any spatial indexes that are available on the geometries. 要避免使用索引,请使用函数
|
由GEOS模块执行
增强:2.3.0增强到PIP短路,几何体扩展到支持多点和少点。以前的版本仅支持多边形中的点。
![]() |
|
增强:已启用3.0.0支持
|
![]() |
|
请勿对无效的几何图形使用此函数。你会得到意想不到的结果。 |
注意:这是“允许的”版本,返回布尔值,而不是整数。
This method implements the
OGC Simple Features
Implementation Specification for SQL 1.1.
S2.1.1.2//s2.1.13.3-a.Relate(b,‘T*F**F*’)
This method implements the SQL/MM specification. SQL-MM 3:5.1.30
--a circle within a circle
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
(
SELECT ST_Buffer(ST_GeomFromText('POINT(50 50)'), 20) As smallc,
ST_Buffer(ST_GeomFromText('POINT(50 50)'), 40) As bigc) As foo;
--Result
smallinsmall | smallinbig | biginsmall | unioninbig | biginunion | bigisunion
--------------+------------+------------+------------+------------+------------
t | t | f | t | t | t
(1 row)