Name

ST_ContainsProperly — 如果B与A的内部相交,但不与边界或外部相交,则返回TRUE。

Synopsis

boolean ST_ContainsProperly(geometry geomA, geometry geomB);

描述

如果B与A的内部相交,但不与边界或外部相交,则返回TRUE。

A没有适当地包含它自己,但它确实包含它自己。

其他几何体的每个点都是该几何体内部的一个点。两个几何的DE-9IM交集矩阵与中使用的[T**FF*FF*]匹配 ST_Relate

此谓词的一个示例用例是计算一组几何图形与一个大型多边形几何图形的交集。由于交集是一个相当慢的操作,因此使用ContainsProperly过滤掉完全位于区域内的测试几何图形可能会更有效。在这些情况下,交点是已知的先验精确的原始测试几何图形。

[Note]

This function automatically includes a bounding box comparison that makes use of any spatial indexes that are available on the geometries. 要避免使用索引,请使用函数 _ST_ContainsProperly

[Note]

这个谓词的优点是 ST_ContainsST_Intersects 它可以更有效地计算,而不需要计算单个点处的拓扑。

由GEOS模块执行。

可用性:1.4.0

[Important]

增强:已启用3.0.0支持 GEOMETRYCOLLECTION

[Important]

请勿对无效的几何图形使用此函数。你会得到意想不到的结果。

示例

--a circle within a circle
  SELECT ST_ContainsProperly(smallc, bigc) As smallcontainspropbig,
  ST_ContainsProperly(bigc,smallc) As bigcontainspropsmall,
  ST_ContainsProperly(bigc, ST_Union(smallc, bigc)) as bigcontainspropunion,
  ST_Equals(bigc, ST_Union(smallc, bigc)) as bigisunion,
  ST_Covers(bigc, ST_ExteriorRing(bigc)) As bigcoversexterior,
  ST_ContainsProperly(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
  smallcontainspropbig | bigcontainspropsmall | bigcontainspropunion | bigisunion | bigcoversexterior | bigcontainsexterior
------------------+------------------+------------------+------------+-------------------+---------------------
 f                     | t                    | f                    | 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
 

另请参阅

ST_GeometryType, ST_Boundary, ST_Contains, ST_Covers, ST_CoveredBy, ST_Equals, ST_Relate, ST_Within