Class: QgsVectorLayerExporter¶
- class qgis.core.QgsVectorLayerExporter¶
Bases:
QgsFeatureSink
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(…)
New in version 3.0.
QgsVectorLayerExporter(uri: str, provider: str, fields:
QgsFields
, geometryType: Qgis.WkbType, crs:QgsCoordinateReferenceSystem
, overwrite: bool = False, options: Dict[str, Any] = {}, sinkFlags: Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = QgsFeatureSink.SinkFlags()) 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 sourceoptions – optional provider dataset options
sinkFlags –
for how to add features
Enums
alias of
VectorExportResult
Methods
- param feature:
- param features:
Returns any encountered error code, or
False
if no error was encountered.Returns the number of error messages encountered during the export.
Returns any error message encountered during the export.
Writes the contents of vector layer to a different datasource.
- rtype:
bool
- rtype:
str
- ExportError¶
alias of
VectorExportResult
- addFeature(self, feature: QgsFeature, flags: QgsFeatureSink.Flags | QgsFeatureSink.Flag = QgsFeatureSink.Flags()) bool ¶
- Parameters:
feature (QgsFeature) –
flags (Union[QgsFeatureSink.Flags) –
- Return type:
bool
- addFeatures(self, features: Iterable[QgsFeature], flags: QgsFeatureSink.Flags | QgsFeatureSink.Flag = QgsFeatureSink.Flags()) bool ¶
- Parameters:
features (Iterable[QgsFeature]) –
flags (Union[QgsFeatureSink.Flags) –
- Return type:
bool
- errorCode(self) Qgis.VectorExportResult ¶
Returns any encountered error code, or
False
if no error was encountered.See also
See also
- Return type:
- errorCount(self) int ¶
Returns the number of error messages encountered during the export.
See also
See also
- Return type:
int
- errorMessage(self) str ¶
Returns any error message encountered during the export.
See also
See also
- Return type:
str
- exportLayer(layer: QgsVectorLayer, uri: str, providerKey: str, destCRS: QgsCoordinateReferenceSystem, onlySelected: bool = False, options: Dict[str, Any] = {}, feedback: QgsFeedback = None) Tuple[Qgis.VectorExportResult, str] ¶
Writes the contents of vector layer to a different datasource.
- Parameters:
layer (QgsVectorLayer) – source layer
uri (str) – URI for destination data source
providerKey (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 featureserrorMessage – if non-null, will be set to any error messages
options (Dict[str) – optional provider dataset options
feedback (
QgsFeedback
= None) – optional feedback object to show progress and cancellation of export
- Return type:
Tuple[Qgis.VectorExportResult, str]
- Returns:
NoError for a successful export, or encountered error
- flushBuffer(self) bool ¶
- Return type:
bool
- lastError(self) str ¶
- Return type:
str
- # Using a static call to