名稱

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 結構描述中的 relations 表格中。

tg_type 是一個整數:1:[多]點(點狀)、2:[多]線(線狀)、3:[多]面(面狀)、4:集合。layer_id 是 topology.layer 表格中的圖層 ID。

點狀圖層由節點集合組成,線狀圖層由邊的集合組成,面狀圖層由面的集合組成,而集合可以由節點、邊和面的混合組成。

省略組件陣列會產生一個空的拓樸幾何物件。

可用性:1.1

範例:從現有的邊形成

在 ri_topo 結構描述中為圖層 2 (我們的 ri_roads) 建立一個類型為 (2) 線的拓樸幾何物件,對應於第一條邊(我們在 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;