ST_GeomFromWKB

定义

ST_GeomFromWKB 采用熟知二进制 (WKB) 表示和空间参考 ID 作为输入,返回 ST_Geometry 对象。

语法

Oracle

sde.st_geomfromwkb (wkb blob, srid integer)

PostgreSQL

sde.st_geomfromwkb (wkb, srid integer)
sde.st_geomfromwkb (esri_shape bytea, srid integer)

返回类型

ST_Geometry

示例

在以下示例中,对结果行进行了重新格式化,以增强可读性。结果中的间距将根据在线显示而有所不同。以下代码说明了如何使用 ST_GeomFromWKB 函数由 WKB 线表示来创建和插入线。以下示例通过 WKB 表示的空间参考系 1 中的 ID 和几何将记录插入到 sample_geometries 表中。

Oracle

CREATE TABLE sample_geometries (id integer, geometry sde.st_geometry, wkb blob);

INSERT INTO SAMPLE_GEOMETRIES (id, geometry) VALUES (
1901, 
sde.st_geomfromtext ('point (1 2)', 0)
);

INSERT INTO SAMPLE_GEOMETRIES (id, geometry) VALUES (
1902,
sde.st_geomfromtext ('linestring (33 2, 34 3, 35 6)', 0)
);

INSERT INTO SAMPLE_GEOMETRIES (id, geometry) VALUES (
1903,
sde.st_geomfromtext ('polygon ((3 3, 4 6, 5 3, 3 3))', 0)
);
 
UPDATE SAMPLE_GEOMETRIES
SET wkb = sde.st_asbinary (geometry)
WHERE id = 1901;

UPDATE SAMPLE_GEOMETRIES
SET wkb = sde.st_asbinary (geometry)
WHERE id = 1902;

UPDATE SAMPLE_GEOMETRIES
SET wkb = sde.st_asbinary (geometry)
WHERE id = 1903;

SELECT id, sde.st_astext (sde.st_geomfromwkb (wkb, 0))
FROM SAMPLE_GEOMETRIES;

ID   GEOMETRY 

1901 POINT (1.00000000 2.00000000) 
1902 LINESTRING (33.00000000 2.00000000, 34.00000000 3.00000000, 35.00000000 6.00000000) 
1903 POLYGON ((3.00000000 3.00000000, 5.00000000 3.00000000, 4.00000000 6.00000000, 3.00000000 3.00000000)) 

PostgreSQL

CREATE TABLE sample_geometries (id integer, geometry sde.st_geometry, wkb bytea);

INSERT INTO sample_geometries (id, geometry) VALUES (
1901, 
sde.st_geometry ('point (1 2)', 0)
);

INSERT INTO sample_geometries (id, geometry) VALUES (
1902,
sde.st_geometry ('linestring (33 2, 34 3, 35 6)', 0)
);

INSERT INTO sample_geometries (id, geometry) VALUES (
1903,
sde.st_geometry ('polygon ((3 3, 4 6, 5 3, 3 3))', 0)
);
 
UPDATE sample_geometries
SET wkb = sde.st_asshape (geometry)
WHERE id = 1901;

UPDATE sample_geometries
SET wkb = sde.st_asshape (geometry)
WHERE id = 1902;

UPDATE sample_geometries
SET wkb = sde.st_asshape (geometry)
WHERE id = 1903;

SELECT id, sde.st_astext (sde.st_geomfromshape (wkb, 0)) 
FROM sample_geometries;

id   st_astext

1901 POINT (1 2) 
1902 LINESTRING (33 2, 34 3, 35 6) 
1903 POLYGON ((3 3, 5 3, 4 6, 3 3)) 

3/7/2012