3

These questions have been asked before, but since they are not answered I will try to pick up the ends here.

1) First, as stated here:

QGIS 2.2 saving layer as CSV with GEOMETRY=AS_WKT not working

in Qgis 2.2 it is not possible to save a shapefile as .csv including the coordinates using the function _GEOMETRY=AS_WKT_. The issue

http://hub.qgis.org/issues/9597

is set to closed. Does it mean that it has been fixed? And if so, how to make it work again?

2) Second, if you want to save a shape file as .csv with coordinates through PyQgis it can be done with:

https://gis.stackexchange.com/questions/61857/how-to-write-vector-layer-to-csv-file-with-geometry-by-python

as stated here:

How to write vector layer to csv file with geometry by PYTHON?

But again, this does not save the coordinates, and I can't find any solution to this either. So right now, I still have to use an old version on QGIS.

IS there any solutions to these, available at the moment?

  • The bug is fixed in current master, available as qgis-dev in the Osgeo4W setup, or by building from source. It will be available to all in QGIS 2.4. – AndreJ Apr 15 '14 at 7:05
  • Ok, good to know. So at the moment in QGIS 2.2 it is not possible to save a shape file with coordinates to .csv via python console? – Toke Apr 15 '14 at 8:13
  • Only with the mmqgis plugin. – AndreJ Apr 15 '14 at 8:46
  • How do you call mmqgis's Geometry export to CSV from the console? I cant find any documentation on it. – Toke Apr 15 '14 at 9:52
  • Sorry, I don't use the console. – AndreJ Apr 15 '14 at 10:16
3

In PYQGIS a shape file can be save as a .csv with coordinates by:

QgsVectorFileWriter.writeAsVectorFormat(vlayer, "xy.csv", "utf-8", None, "CSV", layerOptions ='GEOMETRY=AS_WKT')

This is not working in QGIS 2.2 but will work again in QGIS 2.4.

  • use layerOptions =['GEOMETRY=AS_WKT'] in QGIS 2.18 – Clement Apr 9 '18 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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