ST_Contains
定义
ST_Contains 获取两个几何对象,如果第一个对象完全包含第二个对象,则返回 1 (Oracle) 或 t (PostgreSQL);否则返回 0 (Oracle) 或 f (PostgreSQL)。
语法
sde.st_contains (g1 sde.st_geometry, g2 sde.st_geometry)
返回类型
布尔型
示例
在下面的示例中,创建了两个表。一个是包含城市的建筑物覆盖区的 bfp;另一个是包含其地块的 lots。城市工程师想要确保所有建筑物覆盖区都完全位于其地块内。
在这两个表中,多面数据类型存储建筑物覆盖区和地块的几何。数据库设计者为这两个要素选择了多面,因为地块可被自然要素(如河流)分隔,而建筑物覆盖区可由几个建筑物构成。
Oracle
CREATE TABLE bfp (building_id integer,
footprint sde.st_geometry);
CREATE TABLE lots (lot_id integer,
lot sde.st_geometry);
INSERT INTO BFP (building_id, footprint) VALUES (
1,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);
INSERT INTO BFP (building_id, footprint) VALUES (
2,
sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);
INSERT INTO BFP (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)
);
PostgreSQL
CREATE TABLE bfp (building_id integer,
footprint st_geometry);
CREATE TABLE lots (lot_id integer,
lot st_geometry);
INSERT INTO bfp (building_id, footprint) VALUES (
1,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);
INSERT INTO bfp (building_id, footprint) VALUES (
2,
st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);
INSERT INTO bfp (building_id, footprint) VALUES (
3,
st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);
INSERT INTO lots (lot_id, lot) VALUES (
1,
st_polygon ('polygon ((-1 -1, -1 11, 11 11, 11 -1, -1 -1))', 0)
);
INSERT INTO lots (lot_id, lot) VALUES (
2,
st_polygon ('polygon ((19 -1, 19 11, 29 9, 31 -1, 19 -1))', 0)
);
INSERT INTO lots (lot_id, lot) VALUES (
3,
st_polygon ('polygon ((39 -1, 39 11, 51 11, 51 -1, 39 -1))', 0)
);
城市工程师选择并未完全包含在一个地块中的建筑物。
Oracle
SELECT UNIQUE (building_id)
FROM BFP, LOTS
WHERE sde.st_intersects (lot, footprint) = 1
AND sde.st_contains (lot, footprint) = 0;
BUILDING_ID
2
PostgreSQL
SELECT DISTINCT (building_id)
FROM bfp, lots
WHERE st_intersects (lot, footprint) = 't'
AND st_contains (lot, footprint) = 'f';
building_id
2
9/15/2013