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-wit[..]
[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------'
Great news,
Congratulations! Lets try it!!
It would be really nice if some people from QGIS, gvSIG, uDIG, etc.
start thinking about building a plugin for it.
Regards,
Jose
We've discussed it some for QGIS in Zurich, mostly storming and comparing
GRASS and PostGIS topology to see if they could share some handling code.
I came back home with a few topologies drafted on tissue paper and some
notes about the required interface for a QGIS Provider. But didn't
organize that information yet.
A pre-Zurich attempt at organizing ideas about qgis-pgis topo editing
is here: https://github.com/strk/qgis_pgis_topoedit/wiki
At the moment it only contains a table of ISO/SQLMM editing functions
and an indication of which datastores could be affected by each, but
will likely be the place in which I'll add outcomes of the Zurich meeting.
--strk;
,------o-.
| __/ | Thank you for PostGIS-2.0 Topology !
| / 2.0 | http://www.pledgebank.com/postgistopology
`-o------'
Thanks strk,
this is great news - thank you for your efforts,
cheers
Ben
--
Ben Madin
t : +61 8 6102 5535
m : +61 448 887 220
e : ben*******
AusVet Animal Health Services
P.O. Box 5467
Broome WA 6725
Australia
AusVet's website: http://www.ausvet.com.au/
This transmission is for the intended addressee only and anyone else subscribed to this mailing list. Clearly then it is not confidential information. If you have received this transmission in error, sorry. The contents of this email are the opinion of the writer only and are not endorsed by AusVet Animal Health Services unless expressly stated otherwise. Although AusVet uses virus scanning software we do not accept liability for viruses or similar in any attachments. Congratulations on reading this boring and probably completely unnecessary bit - you may be the only person ever to do so!
Thanks strk,
I was trying to use the topology functions.
UPDATE public.sa_provinces
SET topogeom = toTopoGeom(the_geom, 'sa_provinces_topo');
I get the following message:
ERROR: function totopogeom(geometry, unknown) does not exist
LINE 2: SET topogeom = toTopoGeom(the_geom, 'sa_provinces_topo');
^
HINT: No function matches the given name and argument types. You might
need to add explicit type casts.
Before running this function i used SET serch_path TO topology, public;
Any pointer what might i be doing wrong.
Oops, my fault, it lacks a layer_id, which is the one returned by
the previous call to AddTopoGeometryColumn, so assuming you followed
my steps (and thus created a single topology layer) it becomes:
UPDATE public.states
SET topogeom = toTopoGeom(geom, 'states_topo', 1);
Full session again:
SELECT CreateTopology('states_topo');
SELECT AddTopoGeometryColumn('states_topo',
'public', 'states', 'topogeom',
'POLYGON');
UPDATE public.states
SET topogeom = toTopoGeom(geom, 'states_topo', 1);
--strk;
,------o-.
| __/ | Thank you for PostGIS-2.0 Topology !
| / 2.0 | http://www.pledgebank.com/postgistopology
`-o------'
Excellent work strk, thanks for this!
Could you please provide some examples how this can be used in queries? Does it speed up querying for neighbours etc.?
Also, does it support network topologies, something I could use with pgrouting or so?
Thanks,
Martin
--
Martin Tomko, PhD.
Senior Project Manager, Information Infrastructure Design, AURIN
Level 5, Architecture Building
University of Melbourne VIC 3010
AUSTRALIA
T: +61 3 9035 3298
E: tomkom*******>
W: www.aurin.org.au <www.aurin.org.au>
W: http://martintomko.wordpress.com/
The focus insofar is about normalized storage. Speed you can squeeze out
but you're mostly on your own in this phase. If you understand the model
correctly you'll figure out how to build your queries in order to go faster,
and what you'd like to have in the core to speed it up further.
For nearest neighbours you'd use the same calls you would for simple
geometries but you'd be looking at edges rather than full polygons, thus
making a better use of the index.
Nope, this is strictly planar topology.
--strk;
,------o-.
| __/ | Thank you for PostGIS-2.0 Topology !
| / 2.0 | http://www.pledgebank.com/postgistopology
`-o------'