ST_Within

定义

如果第一个 ST_Geometry 对象完全位于第二个 ST_Geometry 对象的范围内,则 ST_Within 返回 1 (Oracle) 或 t (PostgreSQL);否则,将返回 0 (Oracle) 或 f (PostgreSQL)。

语法

sde.st_within (g1 sde.st_geometry, g2 sde.st_geometry)

返回类型

布尔型

示例

下例中,创建了两个表文件:一个是 bfootprints,包含的是城市建筑物覆盖区的数据,另一个是 lots,包含的是建筑物所属地块的数据。城市工程师想要确保所有建筑物覆盖区都完全位于其地块内。

在这两个表中,多面数据类型用于存储建筑物覆盖区和地块的 ST_Geometry。数据库设计者将这两个要素的数据类型设置为 ST_MultiPolygons,因为她意识到地块可通过自然要素(例如河流)进行分隔,建筑物覆盖区则可能由若干建筑物组成。

CREATE TABLE bfootprints (building_id integer,
footprint sde.st_geometry);

CREATE TABLE lots (lot_id integer,
lot sde.st_geometry);


INSERT INTO bfootprints (building_id, footprint) VALUES (
1,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO bfootprints (building_id, footprint) VALUES (
2,
sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);

INSERT INTO bfootprints (building_id, footprint) VALUES (
3,
sde.st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);

INSERT INTO lots (lot_id, lot) VALUES (
1,
sde.st_polygon ('polygon ((-1 -1, -1 11, 11 11, 11 -1, -1 -1))', 0)
);

INSERT INTO lots (lot_id, lot) VALUES (
2,
sde.st_polygon ('polygon ((19 -1, 19 11, 29 9, 31 -1, 19 -1))', 0)
);

INSERT INTO lots (lot_id, lot) VALUES (3,
sde.st_polygon ('polygon ((39 -1, 39 11, 51 11, 51 -1, 39 -1))', 0)
);

市政工程师选择出所有未完全位于地块内的建筑物。

Oracle

SELECT bf.building_id
FROM BFOOTPRINTS bf, LOTS l
WHERE sde.st_intersects (bf.footprint, l.lot) = 1 
AND sde.st_within (bf.footprint, l.lot) = 0;

BUILDING_ID

          2

PostgreSQL

SELECT bf.building_id
FROM bfootprints bf, lots l
WHERE sde.st_intersects (bf.footprint, l.lot) = 't' 
AND sde.st_within (bf.footprint, l.lot) = 'f';

building_id

          2
9/15/2013