ST_Distance

定义

ST_Distance 用于返回两个几何之间的距离。这一距离是两个几何的最近折点之间的距离。

语法

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

返回类型

双精度型

示例

法规执行官员需要了解特定宗地上是否有建筑物在地块线的 1 英尺范围内。buildings 表的 building_id 列唯一标识每个建筑物。lot_id 列标识建筑物所在宗地。建筑物面存储每个建筑物的覆盖区的几何。parcels 表存储唯一标识每个地块并与建筑物要素类中的地块 ID 相同的 APN 以及包含地块几何的宗地 ST_Polygon。

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

CREATE TABLE parcels (apn integer unique, parcel sde.st_geometry);

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

INSERT INTO buildings (building_id, lot_id, footprint) VALUES (
2,
400,
sde.st_polygon ('polygon ((12 3, 12 6, 15 6, 15 3, 12 3))', 0)
); 

INSERT INTO buildings (building_id, lot_id, footprint) VALUES (
3,
400,
sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);

INSERT INTO buildings (building_id, lot_id, footprint) VALUES (
4,
402,
sde.st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);

INSERT INTO parcels (apn, parcel) VALUES (
400,
sde.st_polygon ('polygon ((-1 -1, -1 11, 11 11, 19 11, 31 11, 31 -1, 19 -1, 11 -1, -1 -1))', 0)
);

INSERT INTO parcels (apn, parcel) VALUES (
402,
sde.st_polygon ('polygon ((39 -1, 39 11, 51 11, 51 -1, 39 -1))', 0)
);

接着,法规执行官员查询 buildings 和 parcels 表,以获得宗地 400 上的所有建筑物 ID 以及各建筑物与地块线之间距离的列表。(单位在使用的投影系统中定义。)因为此宗地上有三个建筑物,所以应返回三条记录。

Oracle

SELECT UNIQUE p.apn, b.building_id, sde.st_distance(b.footprint, sde.st_boundary(p.parcel)) DISTANCE
FROM BUILDINGS b, PARCELS p
WHERE b.lot_id = p.apn
AND p.apn = 400
ORDER BY DISTANCE;

APN		BUILDING_ID      DISTANCE

400		           1					1
400   			  3					1
400    			  3					4

PostgreSQL

SELECT DISTINCT p.apn, b.building_id, sde.st_distance(b.footprint, sde.st_boundary(p.parcel)) AS Distance
FROM buildings b, parcels p
WHERE b.lot_id = p.apn
AND p.apn = 400
ORDER BY Distance;

apn	     building_id		distance

400            1				1
400            3				1
400     	   2				4
9/15/2013