1

I have a line layer (multiple lines but not large) that I'm working with in my PyQGIS plugin and I need to save the layer as a KML file in the end. My code looks like this:

saveLocation = filePath + "\\output.kml"
QgsVectorFileWriter.writeAsVectorFormat(layer,
    saveLocation, "utf-8", layer.crs(), "KML")

The layer I use is already reprojected to EPSG 4326. The plugin runs without error and a KML file does get saved in the specified location. However, when adding the KML file to the map it is empty -- some features from the layer remain in the attribute table but it seems like geometry info is lost completely. This method used to work.

Is the method deprecated somewhat, or is there something I'm doing wrong?

3
  • result, error = QgsVectorFileWriter.writeAsVectorFormat(...). Then check print(result) and print(error) to get more info, if any. Mar 27 at 23:13
  • no error message printed but print(result) yielded 0
    – WFL.GIS
    Mar 28 at 3:15
  • Same issue if you use qgis.org/pyqgis/master/core/… ? Mar 28 at 6:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.