CreateTopoGeom — 从拓扑元素数组创建一个新的拓扑几何对象 - tg_type: 1:[多]点, 2:[多]线, 3:[多]多边形, 4:集合
topogeometry CreateTopoGeom(varchar toponame, integer tg_type, integer layer_id, topoelementarray tg_objs, bigint tg_id);
topogeometry CreateTopoGeom(varchar toponame, integer tg_type, integer layer_id);
为由layer_id表示的图层创建一个拓扑几何对象,并将其注册到拓扑名称架构的关系表中。
tg_type 是一个整数:1:[多]点(点)、2:[多]线(线性)、3:[多]多边形(面)、4:集合。 layer_id 是topology.layer 表中的层id。
点状层由一组节点形成,线性层由一组边形成,区域层由一组面形成,集合可以由节点、边和面的混合形成。
省略组件数组会生成一个空的 TopoGeometry 对象。
可用性:1.1
Form from existing edges.
在"ri_topo"模式中为"layer 2"(我们的"ri_roads")创建一个拓扑几何对象,类型为(2) LINE,用于第一条边(我们在ST_CreateTopoGeo中加载的边)。
INSERT INTO ri.ri_roads(road_name, topo)
VALUES (
'Unknown',
topology.CreateTopoGeom(
'ri_topo',
2,
2,
'{{1,2}}'::topology.topoelementarray
)
);
Convert an areal geometry to best guess topogeometry.
假设我们有应该由面的集合形成的几何形状。 例如,我们有块组表,并且想知道每个块组的拓扑几何形状。 如果我们的数据完全一致,我们可以这样做:
Create the topogeometry column.
SELECT topology.AddTopoGeometryColumn( 'topo_boston', 'boston', 'blockgroups', 'topo', 'POLYGON');
1
Update the column assuming everything is perfectly aligned with the edges.
UPDATE boston.blockgroups AS bg
SET topo = topology.CreateTopoGeom(
'topo_boston',
3,
1,
foo.bfaces
)
FROM (
SELECT
b.gid,
topology.TopoElementArray_Agg(ARRAY[f.face_id, 3]) AS bfaces
FROM boston.blockgroups AS b
INNER JOIN topo_boston.face AS f
ON b.geom && f.mbr
WHERE ST_Covers(
b.geom,
topology.ST_GetFaceGeometry('topo_boston', f.face_id)
)
GROUP BY b.gid
) AS foo
WHERE foo.gid = bg.gid;
The world is rarely perfect, so this version allows some error. It counts a face if 50 percent of it falls within the expected block group boundary.
WITH candidate_faces AS (
SELECT
b.gid,
b.geom AS block_geom,
f.face_id,
topology.ST_GetFaceGeometry('topo_boston', f.face_id) AS face_geom
FROM boston.blockgroups AS b
INNER JOIN topo_boston.face AS f
ON b.geom && f.mbr
),
block_faces AS (
SELECT
gid,
topology.TopoElementArray_Agg(ARRAY[face_id, 3]) AS bfaces
FROM candidate_faces
WHERE ST_Covers(block_geom, face_geom)
OR (
ST_Intersects(block_geom, face_geom)
AND ST_Area(ST_Intersection(block_geom, face_geom))
> ST_Area(face_geom) * 0.5
)
GROUP BY gid
)
UPDATE boston.blockgroups AS bg
SET topo = topology.CreateTopoGeom(
'topo_boston',
3,
1,
block_faces.bfaces
)
FROM block_faces
WHERE block_faces.gid = bg.gid;
To convert the topogeometry back to a denormalized geometry aligned with faces and edges, cast the topogeometry to a geometry. The resulting geometries are aligned with the TIGER street centerlines.
UPDATE boston.blockgroups SET new_geom = topo::geometry;