2

I am trying to use QgsVectorFileWriter to write a kml file from an active layer in QGIS, but cannot figure out how to define the KML Name element (called NameField in the QGIS save-as GUI) to correspond with a field in my shapefile, which is called "TYPE".

This code does not cause an error, but I cannot figure out how to define StringList to specify that the NameField column name is "Type":

QgsVectorFileWriter.writeAsVectorFormat(layer, kmlPointFile, "UTF-8", None, "KML", onlySelected = 0, datasourceOptions = StringList)
1

I have switched to using gdal through python - my solution is:

cmd = 'ogr2ogr -f GPX -dsco NameField=TYPE {0} {1}'.format(outFile, inFile)
os.system(cmd)
  • Hi, I have the same problem, so can you juste give me the full solution for your code is that possible please, because with juste this line i dont know how can I use it in QgsVectorFileWriter.writeAsVectorFormat. Thank you – nmokht97 Jul 22 '20 at 14:35

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.