CreateTopoGeom — 从拓扑元素数组创建新的拓扑几何对象 - tg_type: 1:[multi]point, 2:[multi]line, 3:[multi]poly, 4:collection
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:[multi]point(点状),2:[multi]line(线状),3:[multi]poly(面状),4:collection。 layer_id
是拓扑结构中 layer 表的图层 ID。
点状图层由节点集组成,线状图层由边集组成,面状图层由面集组成,集合可以由节点、边和面的混合组成。
省略组件数组会生成一个空的 TopoGeometry 对象。
可用性:1.1
在 ri_topo 模式下为图层 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);
假设我们有一些几何图形,应该由一组面组成。例如,我们有 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;