PostGIS Topology: Difference between revisions
m (→Example) |
m (→Example) |
||
Line 64: | Line 64: | ||
== Example == | == Example == | ||
[[Image:topo_example.png|center|thumb|480px| | [[Image:topo_example.png|center|thumb|480px|Example: Two polygons with one hole]] | ||
For '''GRASS native format''': | For '''GRASS native format''': |
Revision as of 15:40, 15 April 2013
PostGIS Topology allows to store topological vector data in PostGIS database. It's available in PostGIS 2.0 and later. GRASS GIS supports PostGIS Topology in version GRASS 7.0 and later through GRASS-PostGIS data provider.
Background
Topological models used by GRASS GIS and PostGIS Topology are different - see below.
GRASS GIS Topology Model
In the GRASS GIS model various topological elements are defined:
- nodes - point elements
- For each node is defined which lines/boundaries starts and ends in this node.
- lines - linear elements which are not forming areas
- For each line is defined by start and end node.
- boundaries - linear elements which can form areas
- For each line is defined by start and end node, and by the area on the left and right.
- centroids - point located inside area
- For each centroid is defined by area within the centroid is located.
- areas - topologically correct areal elements formed by closed set of boundaries and one centroid located inside the area
- For each area is defined by list of boundaries which forms the area (outer ring), and by list of isles located inside the area.
- isle - inner ring (closed set of boundaries) located inside area (note that inner ring is not allowed to touch the area boundary)
- For each isle is defined by list of boundaries which forms the isle (it's outer ring), and by the area where the isle is located.
For other info and examples, see programmer's manual.
PostGIS Topology Model
PostGIS Topology model is based on ISO standard 13249. The model defines only three topological elements:
- nodes - point elements
- Is defined by geometry (point) and by the face where the node is located (can be NULL)
- edges - linear elements
- Is defined by geometry (linestring), start and end node, next left and right edge (ie. connectivity) and by the face on the left and right.
- faces - area elements
- Is defined by bounding box.
PostGIS Topology implementation for GRASS GIS
- Points are stored as isolated nodes (containing_face is null)
- Centroids are stored as isolated nodes (containing_case is not null)
- Lines are stored as edges (left_face and right_face is 0)
- Boundaries are stored edges
- Areas are stored as faces (with id > 0)
- Isles are stored as faces (with id <= 0) (including universal face defined by PostGIS Topology)
Currently the areas and isles are build from GRASS Topology. It's planned to add to the PostGIS Topology model information about areas and isles:
- new table 'areas'
- new table 'isles'
GRASS also stores important metadata in 'topology.grass' table, currently only bounding box for the map.
SELECT * from topology.grass; topology_id | bbox -------------+--------------------------------------------------------------------------------- ... 767 | BOX3D(264003.759398496 55720.5513784461 0,654141.604010025 270194.235588972 0) ...
Example
For GRASS native format:
| Number of points: 0 Number of centroids: 2 | | Number of lines: 0 Number of boundaries: 4 | | Number of areas: 3 Number of islands: 2 |
Topology dump for native GRASS format (v.build):
----------------------------------- Nodes (3 nodes, alive + dead): node = 1, n_lines = 3, xyz = 452944.862155, 246704.260652, 0.000000 line = 5, type = 4, angle = -1.562600 (270.4696) line = 3, type = 4, angle = -0.148597 (351.4860) line = 6, type = 4, angle = 2.956736 (169.4085) node = 2, n_lines = 3, xyz = 453966.165414, 122105.263158, 0.000000 line = -6, type = 4, angle = -3.012183 (187.4146) line = -3, type = 4, angle = -0.615090 (324.7580) line = -5, type = 4, angle = 1.578993 (90.4696) node = 3, n_lines = 2, xyz = 475413.533835, 128233.082707, 0.000000 line = 4, type = 4, angle = -0.650627 (322.7218) line = -4, type = 4, angle = 0.489957 (28.0725) ----------------------------------- Lines (6 lines, alive + dead): line = 1, type = 8, offset = 18, area = 3 line = 2, type = 8, offset = 47, area = 1 line = 3, type = 4, offset = 384, n1 = 1, n2 = 2, left = -1, right = 1 line = 4, type = 4, offset = 469, n1 = 3, n2 = 3, left = 2, right = -2 line = 5, type = 4, offset = 570, n1 = 1, n2 = 2, left = 1, right = 3 line = 6, type = 4, offset = 607, n1 = 1, n2 = 2, left = 3, right = -1 ----------------------------------- Areas (3 areas, alive + dead): area = 1, n_lines = 2, n_isles = 1 centroid = 2 line = 3 line = -5 isle = 2 area = 2, n_lines = 1, n_isles = 0 centroid = 0 line = -4 area = 3, n_lines = 2, n_isles = 0 centroid = 1 line = 5 line = -6 ----------------------------------- Islands (2 islands, alive + dead): isle = 1, n_lines = 2 area = 0 line = -3 line = 6 isle = 2, n_lines = 1 area = 1 line = 4
In PostGIS Topology model will be this example stored as
- 3 nodes (n1, n2, n3)
SELECT node_id,containing_face,st_astext(geom) from topo_example.node; node_id | containing_face | st_astext ---------+-----------------+------------------------------------------ 1 | | POINT(452944.862155388 246704.260651629) 2 | | POINT(453966.165413534 122105.263157895) 3 | | POINT(475413.533834587 128233.082706767)
- 4 edges (3, 4, 5, 6)
SELECT edge_id,next_left_edge,next_right_edge,left_face,right_face,st_geometrytype(geom) from topo_example.edge; edge_id | next_left_edge | next_right_edge | left_face | right_face | st_geometrytype ---------+----------------+-----------------+-----------+------------+----------------- 1 | -4 | 3 | 0 | 1 | ST_LineString 2 | 2 | -2 | 2 | 1 | ST_LineString 3 | -1 | 4 | 1 | 3 | ST_LineString 4 | -3 | 1 | 3 | 0 | ST_LineString
- 3 faces (two areas and one hole)
SELECT face_id,st_geometrytype(mbr) from topo_example.face; face_id | st_geometrytype ---------+----------------- 0 | 1 | ST_Polygon 2 | ST_Polygon 3 | ST_Polygon
See also
- v.out.postgis manual
- Working with external data in GRASS 7 and v.external.out manual
- PostGIS support in GRASS GIS
External links
GRASS GIS:
- GRASS GIS Topology manual
PostGIS:
- http://trac.osgeo.org/postgis/wiki/UsersWikiSimplifyWithTopologyExt
- PostGIS Topology manual
- PostGIS Topology wiki page
- State of the art of FOSS4G for topology and network analysis (FOSS4G 2010)
- strk's page about PostGIS
- PostGIS topology ISO SQL/MM complete (strk's blog)
- Simplifying a map layer using PostGIS topology (strk's blog)
Concepts:
- Topo-Geo-and-Topo-Net - The Concepts • Routine Details
- ISO 13249-3 Information Technology - Database languages - SQL Multimedia and application packages (Text for FDIS)