Skip to content

Instantly share code, notes, and snippets.

@zxmarcos
Created November 13, 2018 19:06
Show Gist options
  • Save zxmarcos/00ee0179c27a7c2e78aab8e5c42b30ce to your computer and use it in GitHub Desktop.
Save zxmarcos/00ee0179c27a7c2e78aab8e5c42b30ce to your computer and use it in GitHub Desktop.
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = 'SQLite'
options.fileEncoding = 'utf-8'
options.datasourceOptions = ['SPATIALITE=YES',
'OGR_SQLITE_PRAGMA=synchronous=OFF,journal_mode=MEMORY,locking_mode=EXCLUSIVE'
]
options.layerOptions = ['SPATIAL_INDEX=NO', 'FID=id']
options.onlySelectedFeatures = True
options.layerName = layer.name()
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
result, msg = QgsVectorFileWriter.writeAsVectorFormat(
layer,
output_file,
options)
if result != QgsVectorFileWriter.NoError:
print(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment