1

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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 12, 2019 at 9:52

1 Answer 1

0

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.

answered Sep 16, 2019 at 7:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.