| 1 | = Postgis Topology = |
| 2 | |
| 3 | |
| 4 | PostGIS topology support is in pre-alpha stage. |
| 5 | It consists in a topology schema model and accessory functions. |
| 6 | |
| 7 | With topology support enabled you can store [wiki:UsersWikiTopologicalPrimitives topological elements], |
| 8 | define TopoGeometry objects as being composed by these elements, |
| 9 | convert TopoGeometry objects to simple [wiki:UsersWikiGeometryType Geometry] objects |
| 10 | to use all functions defined on the latter. |
| 11 | |
| 12 | Topological elements are Faces, Edges and Nodes. |
| 13 | |
| 14 | An entity-relationship diagram of the topology concepts can |
| 15 | be found in the CVS repository of PostGIS (head branch), under |
| 16 | the topology/ER directory. |
| 17 | |
| 18 | The CVS repository also contains initial code, being a set of |
| 19 | definitions and pl/pgsql functions. A README file therein contains |
| 20 | usage and test notes. |
| 21 | |
| 22 | = Enabling Postgis Topology = |
| 23 | |
| 24 | In order to enable postgis support you need to be equipped with the following: |
| 25 | |
| 26 | * A schema-aware postgresql installation (7.3 and up) |
| 27 | * PostGIS-1.1.x (current HEAD branch in CVS) |
| 28 | * Geos-2.1 or up |
| 29 | |
| 30 | Move under the topology/ directory and run: |
| 31 | |
| 32 | {{{ |
| 33 | $ make |
| 34 | $ psql -f topology.sql <your_test_database> |
| 35 | |
| 36 | }}} |
| 37 | |
| 38 | No C libs involved so far, so no need to make install. |
| 39 | |
| 40 | To uninstall/disable just drop the 'topology' schema. It contains |
| 41 | all the objects installed by the topology.sql script (remember to cascade). |
| 42 | |
| 43 | = Creating a Topology = |
| 44 | |
| 45 | Topology data are stored in named SCHEMAs, where the topology |
| 46 | name is the name of the SCHEMA containing its data. |
| 47 | |
| 48 | A catalogue of avalable topologies is kept under the |
| 49 | "topology"."topology" table. |
| 50 | |
| 51 | To create/destroy a topology: |
| 52 | |
| 53 | {{{ |
| 54 | SELECT topology.CreateTopology(name, [srid], [tolerance [srid]], [tolerance]); |
| 55 | SELECT topology.DropTopology(name); |
| 56 | |
| 57 | }}} |
| 58 | |
| 59 | |
| 60 | == Loading Topology data == |
| 61 | |
| 62 | To load topology data in a topology you can use INSERT |
| 63 | statements filling up the Edge, Node and Face relations |
| 64 | under your topology schema: |
| 65 | |
| 66 | |
| 67 | * Edge |
| 68 | * edge_id integer PRIMARY KEY |
| 69 | * start_node integer REFERENCES Node.node_id) |
| 70 | * end_node integer REFERENCES Node.node_id) |
| 71 | * next_left_edge integer REFERENCES abs(Edge.edge_id) |
| 72 | * next_right_edge integer REFERENCES abs(Edge.edge_id) |
| 73 | * left_face integer REFERENCES Face.face_id |
| 74 | * right_face integer REFERENCES Face.face_id |
| 75 | * geom geometry ( a linestring ) |
| 76 | |
| 77 | |
| 78 | * Node |
| 79 | * node_id integer PRIMARY KEY |
| 80 | * containing_face integer REFERENCES Face.face_id |
| 81 | * geom geometry ( a point ) |
| 82 | |
| 83 | * Face |
| 84 | * face_id integer PRIMARY KEY |
| 85 | * mbr box2d ( can be NULL ) |
| 86 | |
| 87 | Details on semantic are contained in the SQL/MM specification, which |
| 88 | this implementation follows as for these views structure. |
| 89 | |
| 90 | == Validating Topology == |
| 91 | |
| 92 | To verify validity of a topology: |
| 93 | |
| 94 | {{{ |
| 95 | SELECT * FROM topology.ValidateTopology(name); |
| 96 | |
| 97 | }}} |
| 98 | |
| 99 | The return set will contain references to elements involved in the invalidity. |
| 100 | |
| 101 | == Editing a Topology == |
| 102 | |
| 103 | See TopologyEditing |
| 104 | |
| 105 | = Working with !TopoGeometry objects = |
| 106 | |
| 107 | See CreatingTopoGeometryObjects |
| 108 | |
| 109 | == Getting simple Geometry values from !TopoGeometry objects == |
| 110 | |
| 111 | You currently need to explicit call the TopoGeometry=>Geometry |
| 112 | cast function. This will probably be made implicit when the |
| 113 | code is more tested: |
| 114 | |
| 115 | {{{ |
| 116 | SELECT topology.Geometry(TopoGeometry); |
| 117 | |
| 118 | }}} |
| 119 | |
| 120 | = Testing Topology implementation = |
| 121 | |
| 122 | Tests are included under the topology/test/ directory. |
| 123 | Run make w/out args to see a list of supported targets. |