2

It seems the answer linked here doesn't work in latest version of QGIS 2.14

layer = QgsVectorLayer("/home/reyman/Projets/cours/coursPython/pyQgis/shape/passages/passages.shp", "passages", "ogr")
if not layer.isValid():
  print "Layer failed to load!"

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

return the warning :

Warning 6: layer creation option 'G' is not formatted with the key=value format
Warning 6: layer creation option 'E' is not formatted with the key=value format
Warning 6: layer creation option 'O' is not formatted with the key=value format
Warning 6: layer creation option 'M' is not formatted with the key=value format
Warning 6: layer creation option 'E' is not formatted with the key=value format
Warning 6: layer creation option 'T' is not formatted with the key=value format
Warning 6: layer creation option 'R' is not formatted with the key=value format
Warning 6: layer creation option 'Y' is not formatted with the key=value format
Warning 6: '' is an unexpected value for  layer creation option of type string-select.
Warning 6: layer creation option 'A' is not formatted with the key=value format
Warning 6: layer creation option 'S' is not formatted with the key=value format
Warning 6: layer creation option '_' is not formatted with the key=value format
Warning 6: layer creation option 'W' is not formatted with the key=value format
Warning 6: layer creation option 'K' is not formatted with the key=value format
Warning 6: layer creation option 'T' is not formatted with the key=value format
3

You can find the answer in the QGIS API documentation: http://www.qgis.org/api/2.14/classQgsVectorFileWriter.html#ac25d02c9ad8bfe6113ba7a06a981a447

What layerOptions parameter is expecting is a list of strings, not a single string. So, your layerOptions value should be: ['GEOMETRY=AS_WKT']

QgsVectorFileWriter.writeAsVectorFormat( layer, 
                                         "wkt.csv", 
                                         "utf-8", 
                                         None, 
                                         "CSV",  
                                         layerOptions=['GEOMETRY=AS_WKT'] )

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.