4

I downloaded a GeoJSON file from vangdata.carto.com and I'm trying to convert it to CSV that has geometry data in tact. I'm trying to achieve the same result as a CSV file when exported from public.opendatasoft.com which is following:

This is the Geo_Shape column

"{""type"": ""MultiPolygon"", ""coordinates"": [[[[3.20543629, 42.07333392606152], [3.206103403, 42.07336071406152], [3.20583872...

Which then is very easy to digest by BigQuery. Unfortunately, online converters seem to only export the textual data from GeoJSON, leaving the geometry out completely.

In QGIS, when I load GeoJSON file, the map shows correctly: enter image description here

Then right click -> Export -> Save Feature As

enter image description here enter image description here

The settings are standard, I leave Geometry section as Automatic but unfortunately the exported CSV does not contain the geometry column at all

I stumbled upon this topic that gave me the idea of using QGIS to convert those files rather than online converters: Windows software to convert GeoJSON (> 6Mb) to Excel/CSV?

How can I convert the GeoJSON (or TopoJSON or even Shapefile - I can get any from vangdata.carto.com) to a CSV with geometry column like above?

1
  • 1
    "that has in tact" is a typo, but I can't figure out what you meant to type.
    – Vince
    Commented Feb 25, 2021 at 12:26

2 Answers 2

5

You need to set Layer Options > GEOMETRY to any option except <Default> in Save Vector Layer as... window.

1
  • Thanks. I tested it and it worked with GEOMETRY > AS_WKT, all the others would remove the geometry column. And of course WKT is also compatible with BigQuery
    – Moseleyi
    Commented Feb 25, 2021 at 10:50
1

You can also use this official GDAL recipe if you prefer command line

ogr2ogr -f CSV -dialect sqlite -sql "select AsGeoJSON(geometry) AS geom, * from input" output.csv input.shp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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