Name

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

Synopsis

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表示的图层创建一个拓扑几何对象,并将其注册到拓扑名称架构的关系表中。

tg_type 是一个整数:1:[多]点(点)、2:[多]线(线性)、3:[多]多边形(面)、4:集合。 layer_id 是topology.layer 表中的层id。

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

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

可用性:1.1

示例:从现有边形成

在"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);

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

假设我们有应该由面的集合形成的几何形状。 例如,我们有块组表,并且想知道每个块组的拓扑几何形状。 如果我们的数据完全一致,我们可以这样做:

-- 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;