名称

CreateTopoGeom — 从拓扑元素数组创建一个新的拓扑几何对象 - tg_type:1:[多]点,2:[多]线,3:[多]面,4:集合

概要

topogeometry CreateTopoGeom(varchar toponame, integer tg_type, integer layer_id, topoelementarray tg_objs);

topogeometry CreateTopoGeom(varchar toponame, integer tg_type, integer layer_id);

描述

为由 layer_id 表示的图层创建一个拓扑几何对象,并将其注册到 toponame 模式的关系表中。

tg_type 是一个整数:1:[多]点(点状),2:[多]线(线状),3:[多]面(面状),4:集合。layer_id 是 topology.layer 表中的图层 ID。

点状图层由一组节点形成,线状图层由一组边形成,面状图层由一组面形成,集合可以由节点、边和面的混合形成。

省略组件数组会生成一个空的 TopoGeometry 对象。

可用性:1.1

示例:从现有边形成

在 ri_topo 模式中为图层 2(我们的 ri_roads)创建一个类型为 (2) LINE 的 topogeom,用于第一条边(我们在 ST_CreateTopoGeo 中加载)。

INSERT INTO ri.ri_roads(road_name, topo) VALUES('Unknown', topology.CreateTopoGeom('ri_topo',2,2,'{{1,2}}'::topology.topoelementarray);

示例:将面状几何转换为最佳猜测拓扑几何

假设我们有一些应该由面集合形成的几何图形。例如,我们有一个 blockgroups 表,并且想知道每个街区组的拓扑几何。如果我们的数据完美对齐,我们可以这样做

-- create our topo geometry column --
SELECT topology.AddTopoGeometryColumn(
	'topo_boston',
	'boston', 'blockgroups', 'topo', 'POLYGON');

-- addtopgeometrycolumn --
1

-- update our column assuming
-- everything is perfectly aligned with our 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 allow for some error
--count the face if 50% of it falls
-- within what we think is our blockgroup boundary
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))
	OR
 (  ST_Intersects(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id))
            AND ST_Area(ST_Intersection(b.geom, topology.ST_GetFaceGeometry('topo_boston', f.face_id) ) ) >
                ST_Area(topology.ST_GetFaceGeometry('topo_boston', f.face_id))*0.5
                )
            GROUP BY b.gid) As foo
WHERE foo.gid = bg.gid;

-- and if we wanted to convert our topogeometry back
-- to a denormalized geometry aligned with our faces and edges
-- cast the topo to a geometry
-- The really cool thing is my new geometries
-- are now aligned with my tiger street centerlines
UPDATE boston.blockgroups SET new_geom = topo::geometry;