3

I tried to convert ogr2gui to convert geojson files to csv. The geojson file contains point data only. The resulting csv only contains attribute data, no coordinates.

Is there a way to get the coordinates from geojson file using ogr2ogr?

1
  • Qgis 2.4 can do this.
    – neogeomat
    Jun 30, 2014 at 13:18

1 Answer 1

5

I am not sure which GDAL version ogr2gui is using but with a current ogr2ogr it is for sure possible.

Read first the driver manual page http://www.gdal.org/drv_csv.html

Layer creation options:

GEOMETRY (Starting with GDAL 1.6.0): By default, the geometry of a feature written to a .csv file is discarded. It is possible to export the geometry in its WKT representation by specifying GEOMETRY=AS_WKT. It is also possible to export point geometries into their X,Y,Z components (different columns in the csv file) by specifying GEOMETRY=AS_XYZ, GEOMETRY=AS_XY or GEOMETRY=AS_YX. The geometry column(s) will be prepended to the columns with the attributes values.

Let's make a test by reading some geojson from a WFS service

ogr2ogr -f csv test.csv -lco GEOMETRY=AS_WKT "http://demo.opengeo.org/geoserver/wfs?service=wfs&version=1.0.0&request=getfeature&typename=og:archsites&outputformat=application/json"

The result looks like this

WKT,cat,str1,bbox
"POINT (593493 4914730)",1,Signature Rock,"(4:593493,4914730,593493,4914730)"
"POINT (591950 4923000)",2,No Name,"(4:591950,4923000,591950,4923000)"
"POINT (589860 4922000)",3,Canyon Station,"(4:589860,4922000,589860,4922000)"
"POINT (590400 4922820)",4,Spearfish Creek,"(4:590400,4922820,590400,4922820)"
"POINT (593549 4925500)",5,No Name,"(4:593549,4925500,593549,4925500)"
"POINT (600375 4925235)",6,Prairie Site,"(4:600375,4925235,600375,4925235)"
"POINT (606635 4920773)",7,Jensen Pass,"(4:606635,4920773,606635,4920773)"

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.