[GIS] loading a CSV with an embedded GeoJSON polygon geometry in QGIS

csvgeojsonpolygonwell-known-text

This open data portal offers download as CSV file. For larger datasets, that's the only way to download the whole dataset in one go. The CSV format is pretty creative: the polygon geometry is in GeoJSON in the "geometry" column.

If I drag and drop this file to my QGIS 2.18.1, it does not render as something geometrical. If however, I change the name of the "geometry" column to "WKT", QGIS does in fact render it. It only works with the WKT header, which is ironical. If I try to add the same info with the "Add CSV layer", it does not recognize the geometry column, as you can only feed that dialog window with WKT format, not GeoJSON.

Is this somehow normal behavior or is it a QGIS bug? Is it a valid option to offer this kind of format to the world on an open data website, or should I raise an issue to change the geometry data to WKT format?

Direct link to example data. Data structure:

"id";"objectid";"geometry";"gisid";"naam";"shape";"shape_length";"shape_area"

"1";"800";"{""type"":""Polygon"",""coordinates"":[[[4.4322857553331,51.236057528816],…[4.4322857553331,51.236057528816]]]}";"LEZ_01";"Lage-emissiezone (LEZ)";"";"1015.8237876604";"29420.558095414"

Best Answer

  1. The "geometry" column as shown contains a list of complete and valid GeoJSON objects consistent with examples shown here: http://geojson.org/geojson-spec.html#appendix-a-geometry-examples.
  2. CSV as such has no specification, so it is not technically invalid to have GeoJSON objects stored in a column. There is a GeoCSV specification, with which the supplied data does not comply (non-point geometry should be in WKT format). In general, CSVs containing geometry use WKT.
  3. QGIS not recognising a column called "geometry"containing GeoJSON objects is not a bug, although possibly it could be considered a limitation.
  4. QGIS recognising a column called "WKT" containing GeoJSON objects could be considered a bug as this is counter-intuitive.

I would recommend filing a request to QGIS to support GeoJSON objects within a column called "geometry" and an option for recognising GeoJSON in the add delimited layer dialog. Support for GeoJSON in a column named "WKT" should be removed.

I would also recommend that the data supplier create CSVs that are usable by the majority of GIS software i.e. storing data in WKT format. Alternatively, they could provide the data as standalone .geojson files containing both attributes and geometries.