I tipi e le funzioni della Topologia PostGIS si usano per gestire oggetti topologici quali facce, bordi e nodi.
La presentazione di Sandro Santilli alla conferenza PostGIS Day Paris 2011 fornisce una buona introduzione alla Topologia PostGIS Topology with PostGIS 2.0 slide deck.
Vincent Picavet provides a good synopsis and overview of what is Topology, how is it used, and various FOSS4G tools that support it in PostGIS Topology PGConf EU 2012.
Un esempio di database GIS topologico è il database del US Census Topologically Integrated Geographic Encoding and Referencing System (TIGER). Se vuoi sperimentare con la topologia PostGIS ed hai bisogno di dati, vedi Topology_Load_Tiger.
Il modulo topologico era presente in versioni precedenti di PostGIS ma non era mai stato parte della documentazione ufficiale. A partire da PostGIS 2.0.0 è in corso una ripulitura generale per rimuovere le funzioni deprecate, risolvere noti problemi di usabilità, migliorare la documentazione delle funzioni, aggiungere funzioni e aumentare la conformità con gli standard SQL-MM.
Dettagli del progetto si possono trovare sul PostGIS Topology Wiki
Tutte le funzioni e le tabelle associate con questo modulo sono installate in uno schema chiamato topology
.
Le funzioni definite dallo standard SQL/MM hanno il prefisso ST_ e le funzioni specifiche di PostGIS sono senza prefisso.
Il supporto topologico è incluso di default a partire da PostGIS 2.0, a può essere disabilitato passando l'opzione --without-topology all'invocazione dello script configure al momento della compilazione, come descritto in Chapter 2, Installazione PostGIS
Questa sezione contiene una lista dei tipi di dato PostgreSQL installati dalla Topologia PostGIS. Nota che sono descritti i comportamenti di conversione di questi tipi di dato, informazione molto importante nel progettazione di funzioni proprie.
ValidateTopology
.
Questa sezione contiene una lista dei domini PostgreSQL installati dalla Topologia PostGIS. I domini possono essere usati come tipo di dato per gli oggetti ritornati da alcune funzioni o utilizzati come colonne di tabelle. La distinzione tra un dominio e un tipo è che un dominio è un tipo esistente con dei vincoli di controllo associati.
Questa sezione fornisce una lista delle funzioni topologiche usate per costruire nuovi schemi topologici, validare le topologie e gestire le colonne di tipo TopoGeometry
table_name
in schema schema_name
and unregisters the columns from topology.layer table.
This section discusses management of database statistics during topology building.
Adding elements to a topology triggers many database queries for finding existing edges that will be split, adding nodes and updating edges that will node with the new linework. For this reason it is useful that statistics about the data in the topology tables are up-to-date.
PostGIS Topology population and editing functions do not automatically update the statistics because a updating stats after each and every change in a topology would be overkill, so it is the caller's duty to take care of that.
That the statistics updated by autovacuum will NOT be visible to transactions which started before autovacuum process completed, so long-running transactions will need to run ANALYZE themselves, to use updated statistics. |
This section covers the topology functions for creating new topologies.
This section covers topology functions for adding, moving, deleting, and splitting edges, faces, and nodes. All of these functions are defined by ISO SQL/MM.
alinestring
to a topology connecting two existing isolated nodes anode
and anothernode
and returns the edge id of the new edge.
apoint
geometry exists as a node an error is thrown. Returns description of move.
aface
.
This section covers the functions for processing topologies in non-standard ways.
This section covers the topology functions for creating new topogeometries.
topoelementarray
for a set of element_id, type arrays (topoelements).
This section covers the topology functions for editing existing topogeometries.
topoelementarray
(an array of topoelements) containing the topological elements and type of the given TopoGeometry (primitive elements).
topoelement
objects containing the topological element_id,element_type of the given TopoGeometry (primitive elements).
This section lists the Topology functions used to check relationships between topogeometries and topology primitives
Once you have created topologies, and maybe associated topological layers, you might want to export them into a file-based format for backup or transfer into another database.
Using the standard dump/restore tools of PostgreSQL is problematic because topologies are composed by a set of tables (4 for primitives, an arbitrary number for layers) and records in metadata tables (topology.topology and topology.layer). Additionally, topology identifiers are not univoque across databases so that parameter of your topology will need to be changes upon restoring it.
In order to simplify export/restore of topologies a pair of executables are provided: pgtopo_export
and pgtopo_import
. Example usage:
pgtopo_export dev_db topo1 | pgtopo_import topo1 | psql staging_db
The pgtopo_export
script takes the name of a database and a topology and outputs a dump file which can be used to import the topology (and associated layers) into a new database.
By default pgtopo_export
writes the dump file to the standard output so that it can be piped to pgtopo_import
or redirected to a file (refusing to write to terminal). You can optionally specify an output filename with the -f
commandline switch.
By default pgtopo_export
includes a dump of all layers defined against the given topology. This may be more data than you need, or may be non-working (in case your layer tables have complex dependencies) in which case you can request skipping the layers with the --skip-layers
switch and deal with those separately.
Invoking pgtopo_export
with the --help
(or -h
for short) switch will always print short usage string.
The dump file format is a compressed tar archive of a pgtopo_export
directory containing at least a pgtopo_dump_version
file with format version info. As of version 1
the directory contains tab-delimited CSV files with data of the topology primitive tables (node, edge_data, face, relation), the topology and layer records associated with it and (unless --skip-layers
is given) a custom-format PostgreSQL dump of tables reported as being layers of the given topology.
The pgtopo_import
script takes a pgtopo_export
format topology dump and a name to give to the topology to be created and outputs an SQL script reconstructing the topology and associated layers.
The generated SQL file will contain statements that create a topology with the given name, load primitive data in it, restores and registers all topology layers by properly linking all TopoGeometry values to their correct topology.
By default pgtopo_import
reads the dump from the standard input so that it can be used in conjunction with pgtopo_export
in a pipeline. You can optionally specify an input filename with the -f
commandline switch.
By default pgtopo_import
includes in the output SQL file the code to restore all layers found in the dump.
This may be unwanted or non-working in case your target database already have tables with the same name as the ones in the dump. In that case you can request skipping the layers with the --skip-layers
switch and deal with those separately (or later).
SQL to only load and link layers to a named topology can be generated using the --only-layers
switch. This can be useful to load layers AFTER resolving the naming conflicts or to link layers to a different topology (say a spatially-simplified version of the starting topology).