[gdal-dev] How to read CSV with GeoJSON correctly?

Even Rouault even.rouault at spatialys.com
Thu Sep 7 03:27:27 PDT 2017


On jeudi 7 septembre 2017 03:16:03 CEST jratike80 wrote:
> Even Rouault-2 wrote
> 
> > Hi Jukka,
> > ...
> > That's not enough. As there are quoted strings in the GeoJSON content,
> > they
> > confuse the CSV reader. So you need to surround the whole GeoJSON content
> > by double-quotes, and escape the inside double quotes with a repeated
> > double quote character
> > (You can the use regular comma for separator, but semicolon is fine too)
> > ...
> 
> Thanks. It is actually well documented in one place of
> http://www.gdal.org/drv_csv.html
> "Complex attribute values (such as those containing commas, quotes or
> newlines) may be placed in double quotes. Any occurrences of double quotes
> within the quoted string should be doubled up to "escape" them."
> 
> However, it contradicts with what is said about reading spatial information
> from CSV
> "...Otherwise, if one or several columns contain a geometry definition
> encoded as WKT, WKB (encoded in hexadecimal) or GeoJSON, the name of such
> column(s) the GEOM_POSSIBLE_NAMES open option."
> 
> Adding extra double quotes inside GeoJSON make it invalid as GeoJSON and
> JSON as well. I would say that CSV driver does not support GeoJSON encoding
> at the moment.

Hard to support 2 unrelated/incompatible formats at the same time. It supports GeoJSON 
serialized as a valid CSV string, with CSV quoting and escaping rules (I've just edited the doc 
to mention that). If you use a graphical editor / spreadsheet and paste the GeoJSON content 
and save as CSV it should work (which I just did with LibreOffice calc). It is just when you edit 
directly the format at hand that things get more tricky ;-)

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170907/a1e80a5c/attachment-0001.html>


More information about the gdal-dev mailing list