4

I would like to know which topology file formats are supported by QGIS.

I am particularly interested in displaying topologies encoded with TopoJSON or GML. But any other portable topology file formats would be useful.

  • gdal.org/ogr_formats.html notes that GML is included, topojson is included for reading according to gdal.org/drv_geojson.html – AndreJ Sep 14 '16 at 12:22
  • I tried to open this TopoJSON example and QGis replies: "Invalid Data Source". I am yet to find a GML topology example. – Luís de Sousa Sep 14 '16 at 12:37
  • It works for me, with ogr2ogr and directly in QGIS. Did you download the RAW that can be viewed in a text editor? – AndreJ Sep 14 '16 at 13:09
  • Fyi, OpenJump has an excellent tool to build topology for a Shapefile. Tools, Edit Geometry, Convert, Planar Graph. – klewis Sep 14 '16 at 20:08
  • AndreJ: you are correct, I was not providing valid TopoJSON files to QGis. Please submit an answer, you were the first to point this out. – Luís de Sousa Sep 15 '16 at 6:23
1

You might have got the wrong data from Github:

https://github.com/mbostock/topojson/blob/master/examples/world-110m.json claims to be json format, but is really the HTML site rendering the image.

Click on the Raw button to get the real data file https://raw.githubusercontent.com/mbostock/topojson/master/examples/world-110m.json.

That one opens fine in QGIS.

For GML format, try http://www.kadaster.nl/web/artikel/download/TOPgrenzen-demobestand.htm . It loads into QGIS, but read-only. You can however save layers to GML, which will be read-only too. According to http://www.gdal.org/drv_gml.html, OGR has limited support for GML reading and writing. Update of existing files is not supported.

GRASS topology can also be handled in QGIS: http://docs.qgis.org/testing/en/docs/user_manual/grass_integration/grass_integration.html#the-grass-vector-data-model, but I don't know if anybody offers data in GRASS format.

  • Can QGis open any other topology file formats? – Luís de Sousa Sep 21 '16 at 15:55
  • See my extended answer. – AndreJ Sep 21 '16 at 17:22
2

What is topology for you ? (same in your question Python library to create topologies). It seems to me that you mix topology, geometry and file formats

From ArcUser: Understanding Topology

Mathematical topology assumes that geographic features occur on a two-dimensional plane. Through planar enforcement, spatial features can be represented through nodes (0-dimensional cells); edges, sometimes called arcs (one-dimensional cells); or polygons (two-dimensional cells). Because features can exist only on a plane, lines that cross are broken into separate lines that terminate at nodes representing intersections rather than simple vertices.

These are the concepts of the Planar Graph theory (Geospatial Topology, the Basics)

enter image description hereenter image description here

arcs/areas topology and nodes topology, figures from Full planar topology in GRASS (Prima parte) and Full planar topology in GRASS (Seconda parte) (in Italian)

1) According to these principles, a shapefile, or a GeoJSON file, for example, store simple geometries without topology (called "spaghetti" topology): the common arc of two adjacent polygons is coded twice (= 2 closed polygons)

GeoJSON:

"features": [
{ "type": "Feature", "properties": { "id": null }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 245694.390306939720176, 142516.899188055162085 ], [ 246286.755701988382498, 142258.933612792025087 ], [ 246468.287032729102066, 140778.020125170383835 ], [ 245092.470631325762952, 140510.500269341951935 ], [ 245121.133473021676764, 140988.214297607017215 ], [ 244738.962250409618719, 141523.254009263851913 ], [ 245694.390306939720176, 142516.899188055162085 ] ] ] } },
{ "type": "Feature", "properties": { "id": null }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 246286.755701988382498, 142258.933612792025087 ], [ 247309.063722475577379, 142707.984799361176556 ], [ 247767.66918961002375, 142526.453468620456988 ], [ 248082.960448264959268, 141523.254009263851913 ], [ 247901.4291175242397, 140806.682966866297647 ], [ 246468.287032729102066, 140778.020125170383835 ], [ 246286.755701988382498, 142258.933612792025087 ] ] ] } } 
]}

2) In contrast, TopoJSON has a true arc-node topology (geometry + topological rules)

The same polygons in the TopoJSON format (Arc-node topology data structures in Python GIS packages)

{'objects': {'name': {u'crs': {u'type': u'name', u'properties': {u'name': u'urn:ogc:def:crs:EPSG::31370'}}, u'type': 'GeometryCollection', 'geometries': [{u'type': u'Polygon', 'properties': {u'id': None}, 'arcs': [[0, 1]]}, {u'type': u'Polygon', 'properties': {u'id': None}, 'arcs': [[2, -1]]}]}}, 'type': 'Topology', 'bbox': [244738.96225040962, 140510.50026934195, 248082.96044826496, 142707.98479936118], '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]]], 'transform': {'translate': [244738.96225040962, 140510.50026934195], 'scale': [0.33443326311184524, 0.21977043004492694]}}

Therefore the formats shapefile, GeoJSON and GML have no topology and TopoJSON, yes. All contains geometries.

enter image description here

shapefiles, GeoJSON vs TopoJSON

3) They are other "true" topological data structures in the GIS World (ESRI ArcInfo topology. GRASS vectors topology, PosGIS topology, SpatiaLite topology), look at Are there Desktop GIS alternatives to ArcGIS 10.X for topology and vector conflation?.

enter image description here

ArcInfo Workstation topology,figure from ArcGIS Topology basics

4) But be careful:

  • QGIS (and other Python modules as ogr and Shapely) use the GEOS C++ library (geometries without explicit topology rules, you can use geometric predicates and relationships but polygons = closed rings, for example)
  • and even if the layer is topologically correct in GRASS GIS, ESRI,SpatiaLite, PostGIS or TopoJSON, this would not be the case of the resulting layer in QGIS (Shapefile)

Therefore, you can open world-110m.json (TopoJSON topology) with QGIS but the resulting topology is not preserved if you save it as a shapefile.

You can use the Topology Checker Plugin to control a shapefile, but the resulting layer will remain a shapefile.

  • Gene, this is a long text, but it does not answer my question. Also, various of the things you wrote are incorrect. For instance, GML does support topology, this information is given in the link I left in the answer. The topology schema is available at the OpenGIS website. – Luís de Sousa Sep 15 '16 at 6:06
  • Ok and thanks, I eliminate the GML format but the problem remains with QGIS: what format you use, the resultant layer contains only geometries without topological rules – gene Sep 15 '16 at 6:45
  • I have now tested a few TopoJSON topologies composed of boundaries and areas and so far QGis has managed quite well. – Luís de Sousa Sep 15 '16 at 9:29

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.