Populating a TopoGeometry column from an existing geometry

The conversion function is called topology.toTopoGeom, and it accepts the following arguments:

  • geom: Input geometry column
  • toponame: Name of topology
  • layer_id: ID of topology layer (it's returned by the topology.AddTopoGeometry function, and can be checked in the topology.layer table)
  • tolerance: Snapping tolerance for conversion

The statement for our data will be as follows:

UPDATE countries SET topogeom = topology.toTopoGeom(geom,'my_topology',1,0.00028); 

The conversion is a time-consuming process. For Natural Earth data, i7 CPU, 8 GB of RAM and a SSD, it took 6.5 minutes to complete. For bigger datasets, the process can take hours.

The conversion step can be used to fix some minor inconsistencies in non-topological data: unconnected lines or silver polygons. The errors will be corrected up to the tolerance parameter, that is, in our case, if lines are closer than 1 arc-second apart, they will become connected.

Now we can inspect the database again. The topological element tables (nodes, edge_data, and faces) were populated, and can be visualized in QGIS.

Note that, QGIS has a handy tool called TopoViewer. To use it, open DB Manager from the database main menu, select a my_topology schema, and pick TopoViewer from the Schema menu. This will add all topology elements to the map view, show the edge directionality, and label the elements' IDs:

Topology visualized with QGIS TopoViewer 

If everything is correct, it's time to DROP an existing Simple Feature geometry column: it will not be updated as the underlying topology changes. Instead, the new TopoGeometry column can be used (but not edited) in GIS software as though it was an ordinary geometry column, thanks to PostgreSQL's autocast feature:

ALTER TABLE countries DROP COLUMN geom; 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset