ST_Equals

定義

ST_Equals は、2 つの ST_Geometry を比較し、同じ場合は 1(Oracle)または t(PostgreSQL)、それ以外の場合は 0(Oracle)または f(PostgreSQL)を返します。

構文

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

戻り値のタイプ

Integer(ブール値)

都市 GIS 技術者は、bldgs テーブルの中に重複したデータがあるのではないかと疑っています。懸念を払拭するために、テーブルにクエリを実行して同じ建物のマルチポリゴンがあるかどうかを判定します。

bldgs テーブルが作成され、次のステートメントによって入力されます。bldg_id 列は建物を一意に識別し、footprint は建物のジオメトリを格納します。

Oracle

CREATE TABLE bldgs (bldg_id integer unique,
footprint sde.st_geometry);

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

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

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

INSERT INTO BLDGS (bldg_id, footprint) VALUES (
4,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

PostgreSQL

CREATE TABLE bldgs (bldg_id integer unique,
footprint st_geometry);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
1,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
2,
st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
3,
st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
4,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

bldgs テーブルは、equal 述語によって空間的に自身に結合し、同じ 2 つのマルチポリゴンを見つけた場合は 1 を返します。b1.bldg_id<>b2.bldg_id 条件は、ジオメトリを自身と比較しないようにします。

Oracle

SELECT UNIQUE (b1.bldg_id), b2.bldg_id
FROM BLDGS b1, BLDGS b2
WHERE sde.st_equals (b1.footprint, b2.footprint) = 1
AND b1.bldg_id <> b2.bldg_id;

BLDG_ID   BLDG_ID

    4           1
    1           4

PostgreSQL

SELECT DISTINCT (b1.bldg_id), b2.bldg_id
FROM bldgs b1, bldgs b2
WHERE st_equals (b1.footprint, b2.footprint) = 't'
AND b1.bldg_id <> b2.bldg_id;

bldg_id   bldg_id

    1           4
    4           1

3/6/2012