网格基本能力
本文档演示 Yukon 中 GeoSOT 编码的基本能力,包括二维点线面编码、三维模型编码、网格层级聚合、带洞面编码和带飞地面编码。
示例数据:
demo-geosot.udbx,包含二维点、线、面、三维模型(精模和 BIM)。可视化工具:DBeaver、QGIS 或 SuperMap iDesktopX(本文展示三维场景效果,使用 SuperMap iDesktopX)。
二维线面数据编码
对二维点、线、面数据的 geometry 列计算 geosotgrid,并转换为 geometry 对象。
示例数据表:building_point_demo、builing_line_demo、building_region_demo。
1. 二维点编码
--- 1.1 创建表存储二维网格结果:building_point_grid22
CREATE TABLE building_point_grid22 (
smid serial4 NOT NULL,
smgeometry geometry(polygon, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
--- 1.2 为 building_point_demo 表的 smgeometry 列构造 22 层网格,并将格网转换成 geometry 对象,写入
WITH a AS (
SELECT smid, ST_GeoSOTGrid(smgeometry, 22) AS grids
FROM building_point_demo
)
INSERT INTO building_point_grid22 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromGeoSOTGrid(unnest(grids)),
ST_AsText(unnest(grids)),
unnest(grids),
smid
FROM a;
2. 二维线编码
--- 2.1 创建表存储二维网格结果:building_line2d_grid22
CREATE TABLE building_line2d_grid22 (
smid serial4 NOT NULL,
smgeometry geometry(polygon, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
--- 2.2 为 builing_line_demo 表的 smgeometry 列构造 22 层网格,并将格网转换成 geometry 对象,写入
WITH a AS (
SELECT smid, ST_GeoSOTGrid(smgeometry, 22) AS grids
FROM builing_line_demo
)
INSERT INTO building_line2d_grid22 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromGeoSOTGrid(unnest(grids)),
ST_AsText(unnest(grids)),
unnest(grids),
smid
FROM a;
3. 二维面编码
--- 3.1 创建表存储二维网格结果:building_region2d_grid22
CREATE TABLE building_region2d_grid22 (
smid serial4 NOT NULL,
smgeometry geometry(polygon, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
--- 3.2 为 building_region_demo 表的 smgeometry 列构造 22 层网格,并将格网转换成 geometry 对象,写入
WITH a AS (
SELECT smid, ST_GeoSOTGrid(smgeometry, 22) AS grids
FROM building_region_demo
)
INSERT INTO building_region2d_grid22 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromGeoSOTGrid(unnest(grids)),
ST_AsText(unnest(grids)),
unnest(grids),
smid
FROM a;
效果:新生成的 building_point_grid22、building_line2d_grid22 和 building_region2d_grid22 表格可视化效果如下:
三维模型对象编码
精模数据编码
取三维模型对象的包围盒,计算三维编码,并转换为 geometry 对象。
示例数据:building_1。
--- 4.1 创建表存储三维网格:building_1_grid22
CREATE TABLE building_1_grid22 (
smid serial4 NOT NULL,
smgeometry geometry(multipolygonz, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
--- 4.2 为 building_1 表的 smgeometry 列构造 22 层网格,并将格网转换成 geometry 对象,写入
--- 注:st_boundary(geomodel) 方法得到的 Box3D,z 方向起算点在地心,
--- GeoSOT 的 z 方向起算点在地表,所以需要进行平移处理
WITH a AS (
SELECT smid,
ST_GeoSOTGrid(
ST_Translate(
ST_SetSRID(ST_Boundary(smgeometry), 4490),
0, 0, -6378137
),
22
) AS grids
FROM building_1
)
INSERT INTO building_1_grid22 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromText(
REGEXP_REPLACE(
ST_AsText(ST_GeomFromGeoSOTGrid(unnest(grids))),
'POLYHEDRALSURFACE',
'MULTIPOLYGON'
)
),
ST_AsText(unnest(grids)),
unnest(grids),
smid
FROM a;
效果:新生成的 building_1_grid22 表格与原始三维模型叠加后可视化效果如下:
BIM 数据编码
步骤与精模编码相同。示例数据:BIM 模型。
效果:
网格层级聚合
从已有的精细层网格生成粗糙层网格。示例中从 15 层网格生成 12 层网格,示例数据:bj_l。
-- 5.1 创建表存储 15 层级网格数据:building_line_grid15
CREATE TABLE building_line_grid15 (
smid serial4 NOT NULL,
smgeometry geometry(polygon, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
-- 为 bj_l 表的 smgeometry 列构造 15 层网格,并将格网转换成 geometry 对象,写入
WITH a AS (
SELECT smid, ST_GeoSOTGrid(smgeometry, 15) AS grids
FROM bj_l
)
INSERT INTO building_line_grid15 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromGeoSOTGrid(unnest(grids)),
ST_AsText(unnest(grids)),
unnest(grids),
smid
FROM a;
-- 5.2 创建表存储 12 层级网格数据:building_line_grid12
CREATE TABLE building_line_grid12 (
smid serial4 NOT NULL,
smgeometry geometry(polygon, 4490),
astext VARCHAR(765),
grid GeoSOTGrid,
idgeo INT4
);
-- 5.3 从步骤 5.1 的 15 层网格 building_line_grid15 生成 12 层网格
WITH a AS (
SELECT ST_Aggregate(grid, 12) AS grid, idgeo
FROM building_line_grid15
)
INSERT INTO building_line_grid12 (smgeometry, astext, grid, idgeo)
SELECT ST_GeomFromGeoSOTGrid(grid),
ST_AsText(grid),
grid,
idgeo
FROM a;
效果:GeoSOT 编码的第 12 层为不规则网格,本例中新生成的 12 层网格可视化效果如下:
带洞的面对象编码
对带洞的面对象编码处理过程与普通 geometry 一致。示例数据:hole。
-- 对 hole 里的对象进行编码,并转成 geometry 存在 tb_18 表中
CREATE SEQUENCE public.tb_18_id_seq
INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE;
CREATE TABLE public.tb_18 (
id INT4 NOT NULL DEFAULT nextval('tb_18_id_seq'::regclass) PRIMARY KEY,
g geometry
);
INSERT INTO tb_18 (g)
SELECT ST_GeomFromGeoSOTGrid(unnest(ST_GeoSOTGrid(smgeometry, 18)))
FROM hole h;
效果:
带飞地的面对象编码
对带飞地的面对象编码处理过程与普通 geometry 一致。示例数据:hebei。
-- 对示例数据里的对象进行编码,并转成 geometry 存在 tb_13 表中
CREATE SEQUENCE public.tb_13_id_seq
INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE;
CREATE TABLE public.tb_13 (
id INT4 NOT NULL DEFAULT nextval('tb_13_id_seq'::regclass) PRIMARY KEY,
g geometry
);
INSERT INTO tb_13 (g)
SELECT ST_GeomFromGeoSOTGrid(unnest(ST_GeoSOTGrid(smgeometry, 13)))
FROM hebei;
效果: