2

I am looking at using the traditional arc-node topological data structure to make some spatial data analysis more efficient. I would like to avoid reinventing the wheel. Is there an implementation in any (preferably open-source) Python spatial data package where I could build and access the face, edge and node tables?

For background info, the topology is discussed for instance here http://library.oceanteacher.org/OTMediawiki/index.php/Vector_Data_Topology

2

The traditional arc-node topological data structure presented here is the ESRI ArcInfo topology. There are other topological data structures in the GIS World (GRASS vectors, PosGIS topology, SpatiaLite topology or the TopoJSON format). Look at Full planar topology in GRASS (Prima parte) (in Italian) or PostGIS topology ISO SQL/MM complete They all use the Planar Graph theory.

There are no Python pure geospatial modules dealing with the ArcInfo topology (they are based on the GEOS C++ library) but there are some to process the Grass vector, PostGIS or SpatiaLite topologies using GRASS GIS, PostGIS and SpatiaLite.

You could also emulate the Arc/Node topology in Python using modules as Shapely (PlanarGraph or using the TopoJSON/ GeoJSON formats (topojson.py or TopoJSON-Arcs)

1) with GEOS (GeoJSON format: two adjacent polygons from Shapely)

enter image description here

import json 
with open("geos.geojson") as f:
    geojson = json.load(f)
print geojson
{u'crs': {u'type': u'name', u'properties': {u'name': u'urn:ogc:def:crs:EPSG::31370'}}, u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'Polygon', u'coordinates': [[[245694.39030693972, 142516.89918805516], [246286.75570198838, 142258.93361279203], [246468.2870327291, 140778.02012517038], [245092.47063132576, 140510.50026934195], [245121.13347302168, 140988.21429760702], [244738.96225040962, 141523.25400926385], [245694.39030693972, 142516.89918805516]]]}, u'type': u'Feature', u'properties': {u'id': None}}, {u'geometry': {u'type': u'Polygon', u'coordinates': [[[246286.75570198838, 142258.93361279203], [247309.06372247558, 142707.98479936118], [247767.66918961002, 142526.45346862046], [248082.96044826496, 141523.25400926385], [247901.42911752424, 140806.6829668663], [246468.2870327291, 140778.02012517038], [246286.75570198838, 142258.93361279203]]]}, u'type': u'Feature', u'properties': {u'id': None}}]}
for geom in geojson['features']:
   print geom['geometry']
{u'type': u'Polygon', u'coordinates': [[[245694.39030693972, 142516.89918805516], [246286.75570198838, 142258.93361279203], [246468.2870327291, 140778.02012517038], [245092.47063132576, 140510.50026934195], [245121.13347302168, 140988.21429760702], [244738.96225040962, 141523.25400926385], [245694.39030693972, 142516.89918805516]]]}
{u'type': u'Polygon', u'coordinates': [[[246286.75570198838, 142258.93361279203], [247309.06372247558, 142707.98479936118], [247767.66918961002, 142526.45346862046], [248082.96044826496, 141523.25400926385], [247901.42911752424, 140806.6829668663], [246468.2870327291, 140778.02012517038], [246286.75570198838, 142258.93361279203]]]}

The result is two polygons with adjacent boundaries duplicated

2) with an arc-node topology from TopoJSON

from topojson.topojson import conversion
topo  = conversion.convert(geojson)
print topo['arcs']
[[[4628, 7955], [542, -6738]], [[5170, 1217], [-4113, -1217], [85, 2173], [-1142, 2435], [2856, 4521], [1772, -1174]], [[4628, 7955], [3056, 2044], [1372, -827], [943, -4564], [-543, -3261], [-4286, -130]]]
print topo['transform']
{'translate': [244738.96225040962, 140510.50026934195], 'scale': [0.33443326311184524, 0.21977043004492694]}
print topo['bbox']
[244738.96225040962, 140510.50026934195, 248082.96044826496, 142707.98479936118]

Here a single boundary can share several polygons

For example, the shared boundary between California and Nevada is represented only once, rather than being duplicated for both states (from TopoJSON)

  • Thank you very much. What I was after, however, is a way to build and access the individual Faces, Edges and Nodes tables. I do work with Fiona and Shapely ( and happily with GEOS), but I want to build, maintain and access the three distinct data structures ( tables, linked lists or whatever) that contain the symbolic links between the ids of faces, edges and nodes, rather than the coordinates themselves of a cleaned, topological structure. Thanks anyway for the answer. – MartinT Oct 13 '15 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.