Nombre

CreateTopoGeom — Crea un nuevo objeto de geometría topo de la matriz de elementos topo - tg_type: 1:[multi]point, 2:[multi]line, 3:[multi]poly, 4:collection

Sinopsis

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

Description

Crea un objeto de topogeometría para la capa indicada por layer_id y lo registra en la tabla relations del esquema toponame.

tg_type es un entero: 1:[multi]point (punctal), 2:[multi]line (lineal), 3:[multi]poly (areal), 4:collection. layer_id es el identificador de capa de la tabla topology.layer.

las capas puntuales se forman a partir de un conjunto de nodos, las capas lineales se forman a partir de un conjunto de aristas, las capas de área se forman a partir de un conjunto de caras, y las colecciones se pueden formar a partir de una mezcla de nodos, aristas y caras.

Omitir la matriz de componentes genera un objeto TopoGeometry vacío.

Availability: 1.1

Ejemplos

Form from existing edges.

Crea un topogeom en el esquema ri_topo para la capa 2 (nuestra ri_roads), de tipo (2) LINE, para el primer borde (cargamos en ST_CreateTopoGeo).

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

Convert an areal geometry to best guess topogeometry.

Digamos que tenemos geometrías que deben ser formadas a partir de una colección de caras. Tenemos por ejemplo la tabla blockgroups y queremos conocer la geometría topo de cada grupo de bloques. Si nuestros datos estuvieran perfectamente alineados, podríamos hacer esto:

Create the topogeometry column.

Code
SELECT topology.AddTopoGeometryColumn(
'topo_boston',
'boston', 'blockgroups', 'topo', 'POLYGON');

Output
1

Update the column assuming everything is perfectly aligned with the edges.

Code
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.

Code
WITH candidate_faces AS (
    SELECT
        b.gid,
        b.geom AS block_geom,
        f.face_id,
        topology.ST_GetFaceGeometry('topo_boston', f.face_id) AS face_geom
    FROM boston.blockgroups AS b
    INNER JOIN topo_boston.face AS f
        ON b.geom && f.mbr
),
block_faces AS (
    SELECT
        gid,
        topology.TopoElementArray_Agg(ARRAY[face_id, 3]) AS bfaces
    FROM candidate_faces
    WHERE ST_Covers(block_geom, face_geom)
        OR (
            ST_Intersects(block_geom, face_geom)
            AND ST_Area(ST_Intersection(block_geom, face_geom))
                
> ST_Area(face_geom) * 0.5
        )
    GROUP BY gid
)
UPDATE boston.blockgroups AS bg
SET topo = topology.CreateTopoGeom(
    'topo_boston',
    3,
    1,
    block_faces.bfaces
)
FROM block_faces
WHERE block_faces.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.

Code
UPDATE boston.blockgroups SET new_geom = topo::geometry;