CreateTopoGeom — Crée un nouvel objet géométrique topo à partir d'un tableau d'éléments topo - tg_type : 1 :[multi]point, 2 :[multi]ligne, 3 :[multi]poly, 4:collection
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);
Crée un objet topogéométrique pour la couche désignée par layer_id et l'enregistre dans la table des relations du schéma toponame.
tg_type est un nombre entier : 1 : [multi]point (ponctuel), 2 : [multi]ligne (linéaire), 3 : [multi]poly (aréolaire), 4:collection. layer_id est l'identifiant de la couche dans la table topology.layer.
Les couches ponctuelles sont formées à partir d'un ensemble de nœuds, les couches linéaires sont formées à partir d'un ensemble d'arêtes, les couches aréales sont formées à partir d'un ensemble de faces, et les collections peuvent être formées à partir d'un mélange de nœuds, d'arêtes et de faces.
L'omission du tableau de composants génère un objet TopoGeometry vide.
DIsponibilité : 1.1
Créer un topogeom dans le schéma ri_topo pour la couche 2 (nos ri_roads), de type (2) LINE, pour la première arête (que nous avons chargée dans ST_CreateTopoGeo).
INSERT INTO ri.ri_roads(road_name, topo) VALUES('Unknown', topology.CreateTopoGeom('ri_topo',2,2,'{{1,2}}'::topology.topoelementarray);
Supposons que nous ayons des géométries qui doivent être formées à partir d'une collection de faces. Nous disposons par exemple d'un tableau de groupes de blocs et nous voulons connaître la géométrie topographique de chaque groupe de blocs. Si nos données étaient parfaitement alignées, nous pourrions le faire :
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.
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;
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;