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)

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.