In QGIS 3.10, the data for the layer SIMnodes seem to be OK as inspected in the respective data table but trying to save it into a shapefile:

cSIMnodes = QgsProject.instance().homePath() + '\\SIMnodes.shp'

QgsVectorFileWriter.writeAsVectorFormat(layer = SIMnodes,
       fileName = cSIMnodes,
       fileEncoding = 'UTF-8',
       destCRS = QgsCoordinateReferenceSystem(4326),
       driverName = 'ESRI Shapefile')

yields all real numbers in the resulting Esri shapefile to be wrong {for example 234.5 is written as 2.0}.

All integers and all strings are written well.


In my case, your request "QgsCoordinateReferenceSystem(4326)" doesn't work.

To export, the syntax is as follows :

layer = iface.activeLayer()
file_path = "C:/Users/v.bre/Desktop/test/test.shp"
encoding = "utf-8"
crs = QgsCoordinateReferenceSystem('EPSG:2154')
format = "ESRI Shapefile"

writer = QgsVectorFileWriter.writeAsVectorFormat(layer,file_path,encoding,layer.crs(),format)

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.