[postgis-users] PostGIS Topology Pledge: completed !

Sandro Santilli strk at keybit.net
Mon Jan 30 03:49:36 PST 2012


As of revision 8963 (included in upcoming 2.0.0alpha3 [1]), the function
to convert simple layers to topologically defined layers [2] is completed.

 [1] 2.0.0alpha3 http://www.postgis.org/download/
 [2] toTopoGeom http://trac.osgeo.org/postgis/ticket/1017

This means that building a persistent topology for your public.states.geom
layer would be as simple as this:

 SELECT CreateTopology('states_topo');
 SELECT AddTopoGeometryColumn('states_topo',
                              'public', 'states', 'topogeom',
                              'POLYGON');
 UPDATE public.states
   SET topogeom = toTopoGeom(geom, 'states_topo');

You can then check correctness of the conversion:

 SELECT gid FROM public.states WHERE NOT ST_Equals(geom, topogeom);

Look for area overlaps:

 SELECT r1.element_id FROM states_topo.relation r1, states_topo.relation r2
 WHERE r1.topogeo_id != r2.topogeo_id AND r1.element_id = r2.element_id;

Or underlaps:

 SELECT face_id FROM istat_topo.face WHERE face_id > 0
 AND face_id NOT IN ( SELECT element_id FROM istat_topo.relation );

Perform any editing required to clean things up [3], or to simplify the edges.
You can take a look at the primitives with QGIS db_manager plugin [4], or even
at the actual TopoGeometries with QGIS master [5] (although it will be slow in
selecting features within the viewport, see ticket #1290 [6]).

 [3] http://strk.keybit.net/blog/2011/11/21/topology-cleaning-with-postgis/
 [4] qgis db_manager http://www.qgis.org/wiki/DB_Manager_plugin_GSoC_2011
 [5] QuantumGIS http://www.qgis.org
 [6] overlap TopoGeometry http://trac.osgeo.org/postgis/ticket/1290

And of course you can convert TopoGeometries back to simple geometries when needed
for performance or compatibility reasons:

 ALTER TABLE public.states ADD newgeom geometry;
 UPDATE public.states SET newgeom = topogeom::geometry;

Happy edge walking!
http://strk.keybit.net/blog/2012/01/28/a-walk-on-the-wild-side/

 --------------------------------
  C L O S I N G    C R E D I T S
 --------------------------------

I was able to dedicate my time to the implementation of the toTopoGeom
function thanks to the contribution of a disparate group of people and
companies putting a part of the money each to reach the bigger target:

   Andrea Peri            Anne Ghisla               R3 GIS
   Silvio Grosso          GFOSS (gfoss.it)          Cooperativa Alveo
   AusVet                 Ingvild Nystuen           Luca S. Percich
   Richard Greenwod       Andreas Neumann           Oslandia

A special thank goes to Andrea Peri for his initial kick-starter contribution
which allowed me to set an affordable target for the pledge.

Also thanks to the Geographical Free and Open Source Software association
(GFOSS) for the help with reducing paperwork involved in handling all the
contributions.

--strk;

  ,------o-. 
  |   __/  |    Thank you for PostGIS-2.0 Topology !
  |  / 2.0 |    http://www.pledgebank.com/postgistopology
  `-o------'




More information about the postgis-users mailing list