PostGIS Topology

From GRASS-Wiki
Jump to navigation Jump to search

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 Data Model

In the GRASS GIS data model are defined various topological elements:

  • nodes - 0D elements
    For each node is defined which lines/boundaries starts and ends in this node.
  • lines - 1D elements which cannot forming areas
    For each line is defined by start and end node.
  • boundaries - 1D 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 validation: see for example here

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

Example: Two polygons with one hole

In 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 = 100.000000, 0.000000, 0.000000
  line =   3, type = 4, angle = 0.000000 (0.0000)
  line =   2, type = 4, angle = 1.570796 (90.0000)
  line =   1, type = 4, angle = 3.141593 (180.0000)
node = 2, n_lines = 3, xyz = 100.000000, 100.000000, 0.000000
  line =  -2, type = 4, angle = -1.570796 (270.0000)
  line =  -3, type = 4, angle = 0.000000 (0.0000)
  line =  -1, type = 4, angle = 3.141593 (180.0000)
node = 3, n_lines = 2, xyz = 110.000000, 25.000000, 0.000000
  line =   6, type = 4, angle = 0.000000 (0.0000)
  line =  -6, type = 4, angle = 1.570796 (90.0000)
-----------------------------------
Lines (6 lines, alive + dead):
line = 1, type = 4, offset = 18, n1 = 1, n2 = 2, left = -1, right = 1
line = 2, type = 4, offset = 87, n1 = 1, n2 = 2, left = 1, right = 2
line = 3, type = 4, offset = 124, n1 = 1, n2 = 2, left = 2, right = -1
line = 4, type = 8, offset = 193, area = 1
line = 5, type = 8, offset = 222, area = 2
line = 6, type = 4, offset = 251, n1 = 3, n2 = 3, left = 3, right = -2
-----------------------------------
Areas (3 areas, alive + dead):
area = 1, n_lines = 2, n_isles = 0 centroid = 4
  line =   1
  line =  -2
area = 2, n_lines = 2, n_isles = 1 centroid = 5
  line =   2
  line =  -3
  isle =   2
area = 3, n_lines = 1, n_isles = 0 centroid = 0
  line =  -6
-----------------------------------
Islands (2 islands, alive + dead):
isle = 1, n_lines = 2 area = 0
  line =  -1
  line =   3
isle = 2, n_lines = 1 area = 2
  line =   6

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

External links

GRASS GIS:

PostGIS:

Concepts: