Created
June 22, 2020 15:25
-
-
Save thbaumann/2ee1657d913e6706dd41d2e16a189c6e to your computer and use it in GitHub Desktop.
export selected features as gpx for use in qgis action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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