ST_Contains — 如果B的点都不在A的外部,并且A和B至少有一个内点相同,则返回TRUE。
boolean ST_Contains(
geometry geomA, geometry geomB)
;
如果几何图形B完全在几何图形A中,则返回TRUE。当且仅当B的点不在A的外部且B的内部至少有一个点在A的内部时,A包含B。
这个定义的一个微妙之处在于,一个几何图形在其边界内不包含任何东西。因此,面和线可以 不 包含位于其边界内的线和点。有关更多详细信息,请参阅 OGC封面的精妙之处,包含,内 。( ST_Covers 谓词提供了更具包容性的关系。)但是,几何体确实包含其自身。(相比之下,在 ST_ContainsProperly 谓词几何体所做的 不 适当地控制自己。)
ST_CONTAINS是 ST_Within 。所以, ST_Contains(A,B) = ST_Within(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-与内(几何图形B、几何图形A)相同
This method implements the SQL/MM specification. SQL-MM 3:5.1.31
ST_Contains
退货 TRUE
在下列情况下:
![]()
| ![]()
|
![]()
| ![]()
|
这个 ST_Contains
谓词返回 FALSE
在下列情况下:
![]()
| ![]()
|
-- A circle within a circle SELECT ST_Contains(smallc, bigc) As smallcontainsbig, ST_Contains(bigc,smallc) As bigcontainssmall, ST_Contains(bigc, ST_Union(smallc, bigc)) as bigcontainsunion, ST_Equals(bigc, ST_Union(smallc, bigc)) as bigisunion, ST_Covers(bigc, ST_ExteriorRing(bigc)) As bigcoversexterior, ST_Contains(bigc, ST_ExteriorRing(bigc)) As bigcontainsexterior FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, ST_Buffer(ST_GeomFromText('POINT(1 2)'), 20) As bigc) As foo; -- Result smallcontainsbig | bigcontainssmall | bigcontainsunion | bigisunion | bigcoversexterior | bigcontainsexterior ------------------+------------------+------------------+------------+-------------------+--------------------- f | t | t | t | t | f -- Example demonstrating difference between contains and contains properly SELECT ST_GeometryType(geomA) As geomtype, ST_Contains(geomA,geomA) AS acontainsa, ST_ContainsProperly(geomA, geomA) AS acontainspropa, ST_Contains(geomA, ST_Boundary(geomA)) As acontainsba, ST_ContainsProperly(geomA, ST_Boundary(geomA)) As acontainspropba FROM (VALUES ( ST_Buffer(ST_Point(1,1), 5,1) ), ( ST_MakeLine(ST_Point(1,1), ST_Point(-1,-1) ) ), ( ST_Point(1,1) ) ) As foo(geomA); geomtype | acontainsa | acontainspropa | acontainsba | acontainspropba --------------+------------+----------------+-------------+----------------- ST_Polygon | t | f | f | f ST_LineString | t | f | f | f ST_Point | t | t | f | f