The topology extension is not enabled automatically with basic PostGIS functionality. In order to use topology functions, they have to be activated using a PostgreSQL CREATE EXTENSION statement:
CREATE EXTENSION postgis_topology;
This will add topology functions to a database, and create metadata tables in it. Let's have a closer look at them.
We can see a newly created topology schema. It contains topology functions and two metadata tables:
- Topology: Storing information about separate topologies in a database
- Layer: Storing information about topological layers
A topology in PostGIS is a collection of topological elements (nodes, edges, and faces) with specified precision, coordinate system, and dimensionality (2D or 3D). Every topology is stored in a separate schema. A layer is a relationship between topology and a feature table. Each topology can have zero or more layers, and same topological elements can be used in more than one layer - which is useful for hierarchical data, such as administrative division or higher-order watersheds.
Topology functions in PostGIS can be divided into two groups: those that are defined by the ISO standard, and those specific to PostGIS. Standard functions are prefixed with ST_ while the non-standard functions aren't (this is a convention similar to one used by MS SQL Server). Sometimes, standard and non-standard functions have similar functionality, and the ST_ variant exists purely for standard conformance. For detailed usage of topology functions, read on.