Name

toTopoGeom — Converts a simple Geometry into a topo geometry.

Synopsis

topogeometry toTopoGeom(geometry geom, varchar toponame, integer layer_id, float8 tolerance=-1);

topogeometry toTopoGeom(geometry geom, topogeometry topogeom, float8 tolerance=-1);

Description

Converts a simple Geometry into a TopoGeometry.

Topological primitives required to represent the input geometry will be added to the underlying topology, possibly splitting existing ones, and they will be associated with the output TopoGeometry in the relation table.

Existing TopoGeometry objects (with the possible exception of topogeom, if given) will retain their shapes.

When tolerance is given it will be used to snap the input geometry to existing primitives. The special value -1 (default) means use the topology precision as tolerance.

In the first form a new TopoGeometry will be created for the given layer (layer_id) of the given topology (toponame).

In the second form the primitives resulting from the conversion will be added to the pre-existing TopoGeometry (topogeom), possibly adding space to its final shape. To have the new shape completely replace the old one see clearTopoGeom.

Availability: 2.0

Enhanced: 2.1.0 adds the version taking an existing TopoGeometry.

Changed: 3.7.0 changes meaning of tolerance 0 to really mean 0 and -1 (new default) to request using the topology precision.

Examples

This is a full self-contained workflow

Create the topology without allowing any tolerance.

SELECT topology.CreateTopology('topo_boston_test', 2249);

Create a new table.

CREATE TABLE nei_topo(gid serial primary key, nei varchar(30));

Add a topogeometry column to the new table.

SELECT topology.AddTopoGeometryColumn('topo_boston_test', 'public', 'nei_topo', 'topo', 'MULTIPOLYGON') AS new_layer_id;
1

Use the new layer identifier to populate the topogeometry column.

INSERT INTO nei_topo(nei, topo)
SELECT nei,  topology.toTopoGeom(geom, 'topo_boston_test', 1)
FROM neighborhoods
WHERE gid BETWEEN 1 and 15;

Verify what happened.

SELECT * FROM
    topology.TopologySummary('topo_boston_test');
Topology topo_boston_test (5), SRID 2249, precision 0
61 nodes, 87 edges, 35 faces, 15 topogeoms in 1 layers
Layer 1, type Polygonal (3), 15 topogeoms
 Deploy: public.nei_topo.topo

Shrink all TopoGeometry polygons by 10 meters.

UPDATE nei_topo SET topo = toTopoGeom(ST_Buffer(topo, -10), clearTopoGeom(topo), 0);
        

Find faces that are left without any TopoGeometry reference after the shrink operation.

SELECT ST_GetFaceGeometry('topo_boston_test', f.face_id)
  FROM topo_boston_test.face f
  WHERE f.face_id > 0
  AND NOT EXISTS (
    SELECT * FROM topo_boston_test.relation
    WHERE layer_id = 1 AND element_id = f.face_id
  );