Class: QgsVectorLayerExporter

class qgis.core.QgsVectorLayerExporter(uri: str, provider: str, fields: QgsFields, geometryType: QgsWkbTypes.Type, crs: QgsCoordinateReferenceSystem, overwrite: bool = False, options: Dict[str, Any] = {}, sinkFlags: Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = 0)

Bases: qgis._core.QgsFeatureSink

Constructor for QgsVectorLayerExporter.

Parameters:
  • uri – URI for destination data source
  • provider – string key for destination data provider
  • fields – fields to include in created layer
  • geometryType – destination geometry type
  • crs – desired CRS, or an invalid (default constructed) CRS if not available
  • overwrite – set to True to overwrite any existing data source
  • options – optional provider dataset options
  • sinkFlags – for how to add features

A convenience class for exporting vector layers to a destination data provider.

QgsVectorLayerExporter can be used in two ways:

1. Using a static call to QgsVectorLayerExporter.exportLayer(…) which exports the entire layer to the destination provider.

  1. Create an instance of the class and issue calls to addFeature(…)

New in version 3.0: Enums

Methods

addFeature
addFeatures
errorCode Returns any encountered error code, or False if no error was encountered.
errorCount Returns the number of error messages encountered during the export.
errorMessage Returns any error message encountered during the export.
exportLayer Writes the contents of vector layer to a different datasource.
flushBuffer

Signals

Attributes

ErrAttributeCreationFailed
ErrAttributeTypeUnsupported
ErrConnectionFailed
ErrCreateDataSource
ErrCreateLayer
ErrFeatureWriteFailed
ErrInvalidLayer
ErrInvalidProvider
ErrProjection
ErrProviderUnsupportedFeature
ErrUserCanceled
NoError
ErrAttributeCreationFailed = 4
ErrAttributeTypeUnsupported = 3
ErrConnectionFailed = 10
ErrCreateDataSource = 1
ErrCreateLayer = 2
ErrFeatureWriteFailed = 6
ErrInvalidLayer = 7
ErrInvalidProvider = 8
ErrProjection = 5
ErrProviderUnsupportedFeature = 9
ErrUserCanceled = 11
class ExportError

Bases: int

NoError = 0
addFeature(self, feature: QgsFeature, flags: Union[QgsFeatureSink.Flags, QgsFeatureSink.Flag] = 0) → bool
addFeatures(self, features: object, flags: Union[QgsFeatureSink.Flags, QgsFeatureSink.Flag] = 0) → bool
errorCode(self) → QgsVectorLayerExporter.ExportError

Returns any encountered error code, or False if no error was encountered.

See also

errorMessage()

See also

errorCount()

errorCount(self) → int

Returns the number of error messages encountered during the export.

See also

errorMessage()

See also

errorCode()

errorMessage(self) → str

Returns any error message encountered during the export.

See also

errorCount()

See also

errorCode()

exportLayer(layer: QgsVectorLayer, uri: str, providerKey: str, destCRS: QgsCoordinateReferenceSystem, onlySelected: bool = False, options: Dict[str, Any] = {}, feedback: QgsFeedback = None) → Tuple[QgsVectorLayerExporter.ExportError, str]

Writes the contents of vector layer to a different datasource.

Parameters:
  • layer – source layer
  • uri – URI for destination data source
  • providerKey – string key for destination data provider
  • destCRS – destination CRS, or an invalid (default constructed) CRS if not available
  • onlySelected – set to True to export only selected features
  • errorMessage – if non-null, will be set to any error messages
  • options – optional provider dataset options
  • feedback – optional feedback object to show progress and cancellation of export
Returns:

NoError for a successful export, or encountered error

flushBuffer(self) → bool