Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export selected features as gpx for use in qgis action
layer = QgsProject.instance().mapLayer('[% @layer_id %]')
from qgis.core import Qgis, QgsVectorFileWriter
exportpath="D:/loeschen/test.gpx"
error, error_string = QgsVectorFileWriter.writeAsVectorFormat( layer,
exportpath,
"UTF-8",
layer.crs(),
"GPX",
onlySelected=True)
#layerOptions=['...'] )
#print (error[0])
# NoError = 0, ErrDriverNotFound =1, ErrCreateDataSource =2, ErrCreateLayer,
# ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed,
# ErrInvalidLayer, Canceled
if error == QgsVectorFileWriter.NoError:
qgis.utils.iface.messageBar().pushMessage("GPX saved", Qgis.Success)
else:
print('Error: {details}'.format(details=error_string))
qgis.utils.iface.messageBar().pushMessage('Error creating GPX: {details}'.format(details=error_string), Qgis.Critical)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment