I want to export a point-layer to a CSV using a plugin I am working on. Amongst other attributes, the coordinates are exported via layerOptions=['GEOMETRY=AS_XY']
. Everything is working fine, however, I need the coordinates with only 2 decimals instead of the standard 10 for further processing in LaTeX.
Here's a minimum example of my code:
QgsVectorFileWriter.writeAsVectorFormat(layerPKT, QgsProject.instance().readPath("./")+'/KVZ_NEU.csv', "utf-8", layer.crs(), "CSV", True, layerOptions=['GEOMETRY=AS_XY'])
This is the output I get:
X,Y,PNR,KG,IND,GFN,KLASSIFIZI,BEVTYP
31490.0792899652,181684.344823149,"1","75314",,,n,GP
And this is the output I want:
X,Y,PNR,KG,IND,GFN,KLASSIFIZI,BEVTYP
31490.08,181684.34,"1","75314",,,n,GP
1 Answer 1
Here's a little workaround for my problem:
I created two new attributes X
and Y
for the layer and set the length and precision as posted here.
Then I used a QGIS Expression $x
and $y
in order to populate the new fields.