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

Even Rouault even.rouault at spatialys.com
Thu Sep 7 02:37:25 PDT 2017


Hi Jukka,

> 
> I copy-pasted the CSV example and edited it to use semicolon as field
> separator. 

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)

Id;geoJSON
49518;"{""type"":""Polygon"",""coordinates"":[[[29.9596,-2.3272],[29.9189,-2.7028],[29.7235,-2.8189],[29.3706,-2.8401],[29.1497,-2.5917],[29.0405,-2.7447],[28.8619,-2.5309],[29.1194,-2.2488],[29.1361,-1.8602],[29.3616,-1.5092],[29.8237,-1.3089],[29.9149,-1.4825],[30.0524,-1.4314],[30.4704,-1.0525],[30.8394,-1.6514],[30.8567,-2.3151],[30.1356,-2.4382],[29.9596,-2.3272]]]}"


$ ogrinfo test.csv -al  -oo GEOM_POSSIBLE_NAMES=geoJSON -fields=no -q

Layer name: test
OGRFeature(test):1
  POLYGON ((29.9596 -2.3272,29.9189 -2.7028,29.7235 -2.8189,29.3706 -2.8401,29.1497 -2.5917,29.0405 -2.7447,28.8619 -2.5309,29.1194 -2.2488,29.1361 -1.8602,29.3616 -1.5092,29.8237 -1.3089,29.9149 -1.4825,30.0524 -1.4314,30.4704 -1.0525,30.8394 -1.6514,30.8567 -2.3151,30.1356 -2.4382,29.9596 -2.3272))

Even

-- 
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/039eef03/attachment-0001.html>


More information about the gdal-dev mailing list