Class: QgsVectorLayerExporter

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

QgsVectorLayerExporter can be used in two ways:

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

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

Class Hierarchy

Inheritance diagram of qgis.core.QgsVectorLayerExporter

Base classes

QgsFeatureSink

An interface for objects which accept features via addFeature(s) methods.

Enums

ExportError

alias of VectorExportResult

Methods

attributeEditCapabilities

Returns the attribute capabilities of the exporter.

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.

Static Methods

exportLayer

Writes the contents of vector layer to a different datasource.

class qgis.core.QgsVectorLayerExporter[source]

Bases: QgsFeatureSink

__init__(uri: str | None, provider: str | None, fields: QgsFields, geometryType: Qgis.WkbType, crs: QgsCoordinateReferenceSystem, overwrite: bool = False, options: Dict[str | None, Any] = {}, sinkFlags: QgsFeatureSink.SinkFlags | QgsFeatureSink.SinkFlag = QgsFeatureSink.SinkFlags())

Constructor for QgsVectorLayerExporter.

Parameters:
  • uri (Optional[str]) – URI for destination data source

  • provider (Optional[str]) – string key for destination data provider

  • fields (QgsFields) – fields to include in created layer

  • geometryType (Qgis.WkbType) – destination geometry type

  • crs (QgsCoordinateReferenceSystem) – desired CRS, or an invalid (default constructed) CRS if not available

  • overwrite (bool = False) – set to True to overwrite any existing data source

  • options (Dict[Optional[str], Any] = {}) – optional provider dataset options

  • sinkFlags (Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = QgsFeatureSink.SinkFlags()) – for how to add features

ExportError

alias of VectorExportResult

attributeEditCapabilities(self) Qgis.VectorDataProviderAttributeEditCapabilities[source]

Returns the attribute capabilities of the exporter.

Added in version 3.32.

Return type:

Qgis.VectorDataProviderAttributeEditCapabilities

errorCode(self) Qgis.VectorExportResult[source]

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

See also

errorMessage()

See also

errorCount()

Return type:

Qgis.VectorExportResult

errorCount(self) int[source]

Returns the number of error messages encountered during the export.

See also

errorMessage()

See also

errorCode()

Return type:

int

errorMessage(self) str[source]

Returns any error message encountered during the export.

See also

errorCount()

See also

errorCode()

Return type:

str

static exportLayer(layer: QgsVectorLayer | None, uri: str | None, providerKey: str | None, destCRS: QgsCoordinateReferenceSystem, onlySelected: bool = False, options: Dict[str | None, Any] = {}, feedback: QgsFeedback | None = None)[source]

Writes the contents of vector layer to a different datasource.

Parameters:
  • layer (Optional[QgsVectorLayer]) – source layer

  • uri (Optional[str]) – URI for destination data source

  • providerKey (Optional[str]) – string key for destination data provider

  • destCRS (QgsCoordinateReferenceSystem) – destination CRS, or an invalid (default constructed) CRS if not available

  • onlySelected (bool = False) – set to True to export only selected features

  • options (Dict[Optional[str], Any] = {}) – optional provider dataset options

  • feedback (Optional[QgsFeedback] = None) -> (Qgis.VectorExportResult) – optional feedback object to show progress and cancellation of export

Returns:

  • NoError for a successful export, or encountered error

  • errorMessage: if non-null, any error messages