• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ER/H04-Sep-2021-311306

sql/H04-Sep-2021-4,0293,609

test/H04-Sep-2021-10,0557,479

Makefile.inH A D04-Sep-20214.5 KiB14774

READMEH A D04-Sep-20217.4 KiB238159

TODOH A D04-Sep-2021269 2117

postgis_topology.cH A D04-Sep-2021132.2 KiB5,0084,186

topology.sql.inH A D04-Sep-202158.7 KiB2,1011,862

topology_drop_after.sql.inH A D04-Sep-2021808 1917

topology_drop_before.sql.inH A D04-Sep-20211 KiB2320

README

1=Introduction
2
3This module contains support for topological geometry modelling.
4Functions exist to satisfy the ISO/SQLMM topology-geometry model
5and more are provided to add an additional abstraction level for
6topological features and layers, both simple and hierarchical.
7
8You can see an ER diagram of the full conceptual model in the ER dir.
9You need xfig (http://epb.lbl.gov/xfig/).
10
11All routines, types and other management objects are stored in the
12"topology" SCHEMA.
13
14Comments welcome --strk(2012-03-13);
15
16=Requirements
17
18  Many ISO/SQLMM functions use GEOS-3.3.0+ signatures.
19  The script is still buildable with previous GEOS versions
20  but you'll need 3.3.0+ at runtime for most uses.
21
22=Building
23
24  To build the topology support:
25
26  $ make
27
28=Testing
29
30  To run regression tests:
31
32  $ make check
33
34=Install, upgrade, uninstall
35
36To enable topology support:
37
38	$ psql -f topology.sql <your_postgis_enabled_db>
39
40	It will create a 'topology' schema in <your_postgis_enabled_db>
41	hosting all the topology functions. To be run with db-owner perms.
42	Remember to grant execute to users.
43
44To uninstall:
45
46	$ psql -c 'drop schema topology cascade'
47
48To upgrade between minor releases:
49
50	$ psql -f topology_upgrade_<version>_minor.sql <your_postgis_enabled_db>
51
52Major releases upgrades should follow the "HARD UPGRADE" procedure
53described in main postgis manual.
54
55=Usage
56
57Topology data are stored in named SCHEMAs, where the topology
58name is the name of the SCHEMA containing its data.
59
60A catalogue of avalable topologies is kept under the
61"topology"."topology" table.
62
63==Creating a topology
64
65To create a topology:
66
67	SELECT topology.CreateTopology(<name>, [srid], [tolerance]);
68
69Example:
70
71	SELECT topology.CreateTopology('test_schema', 4326 , 0.0001);
72	or
73	-- unknown srid, 0 tolerance
74	SELECT topology.CreateTopology('test_schema');
75
76	NOTE: the new schema ('test_schema' in example) will be create
77	      so it must not exist before.
78
79==Destroying a topology
80
81To destroy a topology:
82
83	SELECT topology.DropTopology(<name>);
84
85==Loading topology data
86
87To load topology data in a topology you can use INSERT
88statements filling up the Edge, Node and Face relations
89under you topology schema:
90
91
92	* Edge
93	 * edge_id integer PRIMARY KEY
94	 * start_node integer REFERENCES Node.node_id)
95	 * end_node integer REFERENCES Node.node_id)
96	 * next_left_edge integer REFERENCES abs(Edge.edge_id)
97	 * next_right_edge integer REFERENCES abs(Edge.edge_id)
98	 * left_face integer REFERENCES Face.face_id
99	 * right_face integer REFERENCES Face.face_id
100	 * geom geometry ( a linestring )
101
102
103	* Node
104	 * node_id integer PRIMARY KEY
105	 * containing_face integer REFERENCES Face.face_id
106	 * geom geometry ( a point )
107
108	* Face
109	 * face_id integer PRIMARY KEY
110	 * mbr box2d ( can be NULL )
111
112The next_*_edge of an edge is the edge you encounter next while going
113around the specified face (right or left) in counterclockwise order
114(so that the face is on your left). Note that due to this definition
115the edge being considered is traversed in reverse order when traversing
116its "right" face. The values are signed to indicate wheter the next edge
117will be traversed in its original or reversed orientation.
118
119More details on semantic are contained in the SQL/MM specification, which
120this implementation follows as for these views structure.
121
122==Validating topology data
123
124To verify validity of a topology:
125
126	SELECT * FROM topology.ValidateTopology(name);
127
128==Defining TopoGeometry objects
129
130Currently, TopoGeometry objects can only be defined by specifying their
131component topology elements. We do support both basic TopoGeometry
132and hierarchical TopoGeometry. Basic TopoGeometry objects are those
133composed by base topolocal elements (faces, edges, nodes). Hierarchical
134TopoGeometry objects are composed by other TopoGeometry objects.
135
136Each TopoGeometry object belongs to a specific Layer of a specific
137Topology. Before creating a TopoGeometry object you need to create
138its Layer in the Topology. A Topology Layer is an association of
139a feature-table with the topology. It also contain type and hierarchy
140information. We create a layer using the AddTopoGeometryColumn() function:
141
142	topology.AddTopoGeometryColumn(topology_name,
143		schema_name, table_name, column_name, feature_type,
144		[child_layer])
145
146The function will both add the requested column to the table and add
147a record to the topology.layer table with all the given info.
148
149If you don't specify [child_layer] (or set it to NULL) this layer
150would contain Basic TopoGeometries (composed by primitive topology
151elements). Otherwise this layer will contain hierarchical TopoGeometries
152(composed by TopoGeometries from the child_layer).
153
154Once the layer is created (it's id is returned by the AddTopoGeometryColumn
155function) you're ready to construct TopoGeometry objects in it:
156
157  	topology.CreateTopoGeom(
158
159    		topology_name,
160
161    		feature_type,	-- 1:[multi]point, 2:[multi]line,
162		             	-- 3:[multi]poly, 4:collection
163
164    		layer_id,    	-- as returned by AddTopoGeometryColumn
165
166		TopoElementArray);
167
168The TopoElementArray type is a bidimensional array of integers.
169Value semantics depend on the type of the layer associated with
170the TopoGeometry object. For Basic TopoGeometry objects this would
171be:
172	{{element_type, element_id}, ...}
173
174For Hierarchical TopoGeometry objects this would be:
175
176	{{child_layer_id, topogeometry_id}, ...}
177
178==Converting Geometry to TopoGeometry while populating the topology
179
180You can import a Geometry into an existing topology and at the same
181time get its topological definition (its TopoGeometry equivalent)
182using the toTopoGeom function:
183
184    topology.toTopoGeom(
185
186        geometry, -- the simple geometry
187
188        topology_name,
189
190        layer_id -- as returned by AddTopoGeometryColumn
191    );
192
193==Getting simple Geometry values from TopoGeometry objects
194
195TopoGeometry to Geometry casting is implicit, so any function accepting
196a Geometry would transparently also accept a TopoGeometry. Some functions
197may be optimized for TopoGeometry.
198
199=Issues
200
201==Topology tolerance
202
203GEOS (and JTS) often fail due to input precision.
204The CreateTopogeo() function currently accept a precision
205specification, we might use this to enforce a precision
206to the topology element geometries, by mean of SnapToGrid
207calls, or alternatively, force use of a specific PrecisionModel
208when using GEOS function. The former seems cleaner, but would
209require a trigger to run on all inserts, even when the geometry
210being input has already been snapped by caller.
211
212==ST_GetFaceGeometry() implementation
213
214The ST_GetFaceGeometry() function is currently implemented
215as a call to polygonize() receiving all edges with the
216given Face on the left or right side. This reduces the number
217of SQL queries to 1, but makes it hard to detect any
218inconsistency in the underlying topology.
219Also, the polygonize() function does not use *any* of the
220metadata informations in the Edge table, so replacing it
221with a more topology-aware function could speed it up.
222
223==ValidateTopology() performance
224
225The ValidateTopology() function, as for SQL/MM specification
226uses ST_GetFaceGeometry() to check for Within() and Overlap()
227conditions. This is an expensive task, and might be replaced
228by topology-aware replacement of the two predicates. The
229Face geometries might also be cached, but that might still
230be slower then overloading the predicates.
231
232==Topology table constraints
233
234In addition to the constraints defined in SQL/MM specification,
235this implementation adds constraints to enforce Node and Edge
236geometry types to be 'POINT' and 'LINESTRING' respectively.
237
238