toTopoGeom — Creates a new topo geometry from a simple geometry
topogeometry toTopoGeom(geometry geom, varchar toponame, integer layer_id, float8 tolerance);
Creates a topogeometry object for layer denoted by layer_id and registers it in the relations table in the toponame schema.
Topological primitives required to represent the input geometry will be added, possibly splitting existing ones. Pre-existing TopoGeometry objects will retain their shapes.
When tolerance is given it will be used to snap the input geometry to existing primitives.
Availability: 2.0
This is a full self-contained workflow
-- do this if you don't have a topology setup already
-- creates topology not 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 it
SELECT topology.AddTopoGeometryColumn('topo_boston_test', 'public', 'nei_topo', 'topo', 'MULTIPOLYGON') As new_layer_id;
new_layer_id
-----------
1
--use new layer id in populating the new topogeometry column
-- we add the topogeoms to the new layer with 0 tolerance
INSERT INTO nei_topo(nei, topo)
SELECT nei, topology.toTopoGeom(geom, 'topo_boston_test', 1)
FROM neighborhoods
WHERE gid BETWEEN 1 and 15;
--use to verify what has happened --
SELECT * FROM
topology.TopologySummary('topo_boston_test');
-- summary--
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