ST_Difference
定义
ST_Difference 获取两个 ST_Geometry 对象,然后返回表示两个源对象之差的 ST_Geometry 对象。
语法
sde.st_difference (g1 sde.st_geometry, g2 sde.st_geometry)
返回类型
ST_Geometry
示例
城市工程师需要知道没有被建筑物覆盖的城市地块的总面积。实际上,她想要知道减去建筑物面积之后的地块面积的总和。
CREATE TABLE footprints (building_id integer, footprint sde.st_geometry); CREATE TABLE lots (lot_id integer, lot sde.st_geometry); INSERT INTO footprints (building_id, footprint) VALUES ( 1, sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0) ); INSERT INTO footprints (building_id, footprint) VALUES ( 2, sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0) ); INSERT INTO footprints (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) );
城市工程师通过 lot_id 相等连接 footprints 表和 lots 表,然后获取地块减去覆盖区之后的差值面积之和。
Oracle
SELECT SUM (sde.st_area (sde.st_difference (lot, footprint))) FROM FOOTPRINTS bf, LOTS WHERE bf.building_id = lots.lot_id; SUM(ST_AREA(ST_DIFFERENCE(LOT,FOOTPRINT))) 114
PostgreSQL
SELECT SUM (sde.st_area (sde.st_difference (lot, footprint))) FROM footprints bf, lots WHERE bf.building_id = lots.lot_id; sum 114
7/10/2012