I'm trying to export positions of a set of points using pyqgis
I saw the numerous posts concerning exporting shp dataset to csv but the command used in all of them is not working.
- How to write vector layer to csv file with geometry by PYTHON?
- Create a csv with geometry as WKT in QGIS (and choosing the field delimiter)
- Save as .csv with coordinates in both QGIS 2.2 and PyqGIS
My code line is:
QgsVectorFileWriter.writeAsVectorFormat(final_palmtrees_layer, result_path+'_trees_pos.csv', "utf-8", None, "CSV", layerOptions ='GEOMETRY=AS_XY')
There are two issues with this line
- I wrote it in the console and i'm getting a "7" error code in the console, but I cannot find what it means.
- I put it in a script and i'm getting the csv file but only the attributes, not the points position + excel tells that the file is corrupted
layerOptions
as a list. E.g.layerOptions=['GEOMETRY=AS_XY']
QgsVectorFileWriter.writeAsVectorFormat(layer, 'C:\...\xy.csv', "utf-8", None, "CSV", layerOptions =['GEOMETRY=AS_XY'])
. Indeed it's written list in QGIS API, I just saw it. Is there a place to see error codes ?r'C:\...\xy.csv'
or'C:\...\\xy.csv'