Class: QgsVectorFileWriter¶
A convenience class for writing vector layers to disk based formats (e.g. Shapefiles, GeoPackage).
There are two possibilities how to use this class:
A static call to
QgsVectorFileWriter
.writeAsVectorFormat(…) which saves the whole vector layer.Create an instance of the class and issue calls to addFeature(…).
Class Hierarchy¶
Base classes¶
An interface for objects which accept features via addFeature(s) methods. |
Enums
alias of |
Methods
Adds a feature to the currently opened data source, using the style from a specified renderer. |
|
Returns the capabilities supported by the writer. |
|
Returns the GDAL (short) driver name associated with the output file. |
|
Returns the GDAL long driver name associated with the output file. |
|
Retrieves error message |
|
Checks whether there were any errors in constructor |
|
Sets the feature symbology export handling for the writer. |
|
Set reference scale for output. |
|
Returns the map of original source field index to output file field index. |
|
Returns the feature symbology export handling for the writer. |
|
Returns the reference scale for output. |
|
Write contents of vector layer to an (OGR supported) vector format |
Static Methods
Returns whether there are among the attributes specified some that do not exist yet in the layer |
|
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile |
|
Create a new vector file writer. |
|
Returns a list of the default dataset options for a specified driver. |
|
Returns a list of the default layer options for a specified driver. |
|
Delete a shapefile (and its accompanying shx / dbf / prj / qix / qpj / cpg / sbn / sbx / idm / ind) |
|
Returns the OGR driver name for a specified file extension. |
|
Returns edition capabilities for an existing dataset name. |
|
Returns filter string that can be used for dialogs. |
|
Creates a filter for an OGR driver key |
|
Returns the driver list that can be used for dialogs. |
|
Returns a list or pairs, with format filter string as first element and OGR format key as second element. |
|
Returns a list of file extensions for supported formats, e.g "shp", "gpkg". |
|
Returns |
|
Returns whether the target layer already exists. |
|
Writes a layer out to a vector file. |
|
Writes a layer out to a vector file. |
Attributes
- class qgis.core.QgsVectorFileWriter[source]¶
Bases:
QgsFeatureSink
- __init__(vectorFileName: str | None, fileEncoding: str | None, fields: QgsFields, geometryType: Qgis.WkbType, srs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem(), driverName: str | None = '', datasourceOptions: Iterable[str | None] = [], layerOptions: Iterable[str | None] = [], newFilename: str | None | None = '', symbologyExport: Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology, sinkFlags: QgsFeatureSink.SinkFlags | QgsFeatureSink.SinkFlag = QgsFeatureSink.SinkFlags())
Create a new vector file writer
Deprecated since version 3.40: Use
create()
instead.- Parameters:
vectorFileName (Optional[str])
fileEncoding (Optional[str])
fields (QgsFields)
geometryType (Qgis.WkbType)
srs (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem())driverName (Optional[str] = '')
datasourceOptions (Iterable[Optional[str]] = [])
layerOptions (Iterable[Optional[str]] = [])
newFilename (Optional[Optional[str]] = '')
symbologyExport (Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology)
sinkFlags (Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = QgsFeatureSink.SinkFlags())
- class ActionOnExistingFile¶
Bases:
int
- AppendToLayerAddFields = 3¶
- AppendToLayerNoNewFields = 2¶
- class BoolOption[source]¶
Bases:
SetOption
An available option for configuring file writing for a particular output format, presenting an boolean option.
- CanAddNewFieldsToExistingLayer = 4¶
- CanAddNewLayer = 1¶
- CanAppendToExistingLayer = 2¶
- CanDeleteLayer = 8¶
- Canceled = 10¶
- CreateOrOverwriteFile = 0¶
- CreateOrOverwriteLayer = 1¶
- class DriverDetails¶
Bases:
object
Details of available driver formats.
- driverName: str¶
Unique driver name
- longName: str¶
Descriptive, user friendly name for the driver
- class EditionCapabilities¶
- class EditionCapabilities(f: QgsVectorFileWriter.EditionCapabilities | QgsVectorFileWriter.EditionCapability)
- class EditionCapabilities(a0: QgsVectorFileWriter.EditionCapabilities)
Bases:
object
- class EditionCapability¶
Bases:
int
- ErrAttributeCreationFailed = 5¶
- ErrAttributeTypeUnsupported = 4¶
- ErrCreateDataSource = 2¶
- ErrCreateLayer = 3¶
- ErrDriverNotFound = 1¶
- ErrFeatureWriteFailed = 7¶
- ErrInvalidLayer = 8¶
- ErrProjection = 6¶
- ErrSavingMetadata = 9¶
- class FieldNameSource¶
Bases:
int
- class FieldValueConverter[source]¶
Bases:
object
Interface to convert raw field values to their user-friendly values.
- virtual clone(self) QgsVectorFileWriter.FieldValueConverter | None [source]¶
Creates a clone of the FieldValueConverter.
- Return type:
Optional[QgsVectorFileWriter.FieldValueConverter]
- virtual convert(self, fieldIdxInLayer: int, value: Any) Any [source]¶
Convert the provided value, for field fieldIdxInLayer. Default implementation will return provided value unmodified.
- Parameters:
fieldIdxInLayer (int) – field index
value (Any) – original raw value
- Return type:
Any
- Returns:
possibly modified value.
- class FilterFormatDetails¶
Bases:
object
Details of available filters and formats.
- driverName: str¶
Unique driver name
- filterString: str¶
Filter string for file picker dialogs
- globs: List[str]¶
Matching glob patterns for format, e.g.
*.shp
.Added in version 3.2.
- Hidden = 3¶
- class HiddenOption[source]¶
Bases:
Option
A hidden option for file writing for a particular output format.
- mValue¶
- Int = 2¶
- class IntOption[source]¶
Bases:
Option
An available option for configuring file writing for a particular output format, presenting an integer option.
- defaultValue¶
- class MetaData¶
- class MetaData(longName: str | None, trLongName: str | None, glob: str | None, ext: str | None, driverOptions: Any, layerOptions: Any, compulsoryEncoding: str | None = '')
- class MetaData(a0: QgsVectorFileWriter.MetaData)
Bases:
object
- compulsoryEncoding: str¶
Some formats require a compulsory encoding, typically UTF-8. If no compulsory encoding, empty string
- driverOptions¶
- ext¶
- glob¶
- layerOptions¶
- longName¶
- trLongName¶
- NoError = 0¶
- class Option[source]¶
Bases:
object
Describes an available option for configuring file writing for a particular output format.
- docString¶
- type¶
- class OptionType¶
Bases:
int
- Original = 0¶
- PreferAlias = 1¶
- class SaveVectorOptions[source]¶
Bases:
object
Options to pass to
QgsVectorFileWriter.writeAsVectorFormat()
.- actionOnExistingFile: QgsVectorFileWriter.ActionOnExistingFile¶
Action on existing file
- attributes: QgsAttributeList¶
Attributes to export (empty means all unless skipAttributeCreation is set)
- attributesExportNames: List[str]¶
Attributes export names
- ct: QgsCoordinateTransform¶
Transform to reproject exported geometries with, or invalid transform for no transformation
- datasourceOptions: List[str]¶
List of OGR data source creation options
- driverName: str¶
OGR driver to use
- feedback: QgsFeedback¶
Optional feedback object allowing cancellation of layer save
- fieldNameSource: QgsVectorFileWriter.FieldNameSource¶
Source for exported field names.
Added in version 3.18.
- fieldValueConverter: QgsVectorFileWriter.FieldValueConverter¶
Field value converter.
Ownership is not transferred and callers must ensure that the lifetime of fieldValueConverter exceeds the lifetime of the
QgsVectorFileWriter
object.
- fileEncoding: str¶
Encoding to use
- filterExtent: QgsRectangle¶
If not empty, only features intersecting the extent will be saved
- forceMulti: bool¶
Sets to
True
to force creation of multipart geometries
- includeConstraints: bool¶
Set to
True
to transfer field constraints to the exported vector file.Support for field constraints depends on the output file format.
Added in version 3.34.
- includeZ: bool¶
Sets to
True
to include z dimension in output. This option is only valid if overrideGeometryType is set
- layerMetadata: QgsLayerMetadata¶
Layer metadata to save for the exported vector file. This will only be used if saveMetadata is
True
.See also
Added in version 3.20.
- layerName: str¶
Layer name. If let empty, it will be derived from the filename
- layerOptions: List[str]¶
List of OGR layer creation options
- onlySelectedFeatures: bool¶
Write only selected features of layer
- overrideGeometryType: Qgis.WkbType¶
Set to a valid geometry type to override the default geometry type for the layer. This parameter allows for conversion of geometryless tables to null geometries, etc.
- saveMetadata: bool¶
Set to
True
to save layer metadata for the exported vector file.See also
Added in version 3.20.
- setFieldDomains: bool¶
Set to
True
to transfer field domains to the exported vector file.Support for field domains depends on the output file format.
Note
Only available in builds based on GDAL 3.5 or later
Added in version 3.36.
- skipAttributeCreation: bool¶
Only write geometries
- sourceDatabaseProviderConnection: QgsAbstractDatabaseProviderConnection¶
Source database provider connection, for field domains.
Ownership is not transferred and callers must ensure that the lifetime of sourceDatabaseProviderConnection exceeds the lifetime of the
QgsVectorFileWriter
object.Added in version 3.36.
- symbologyExport: Qgis.FeatureSymbologyExport¶
Symbology to export
- symbologyScale: float¶
Scale of symbology
- Set = 0¶
- class SetOption[source]¶
Bases:
Option
An available option for configuring file writing for a particular output format, presenting a choice of preset values.
- allowNone¶
- defaultValue¶
- values¶
- SkipNonSpatialFormats = 4¶
- SortRecommended = 2¶
- String = 1¶
- class StringOption[source]¶
Bases:
Option
An available option for configuring file writing for a particular output format, presenting a freeform string option.
- defaultValue¶
- SupportsMultipleLayers = 8¶
- SymbologyExport¶
alias of
FeatureSymbologyExport
- class VectorFormatOption¶
Bases:
int
- class VectorFormatOptions¶
- class VectorFormatOptions(f: QgsVectorFileWriter.VectorFormatOptions | QgsVectorFileWriter.VectorFormatOption)
- class VectorFormatOptions(a0: QgsVectorFileWriter.VectorFormatOptions)
Bases:
object
- class WriterError¶
Bases:
int
- addFeatureWithStyle(self, feature: QgsFeature, renderer: QgsFeatureRenderer | None, outputUnit: Qgis.DistanceUnit = Qgis.DistanceUnit.Meters) bool [source]¶
Adds a
feature
to the currently opened data source, using the style from a specifiedrenderer
.- Parameters:
feature (QgsFeature)
renderer (Optional[QgsFeatureRenderer])
outputUnit (Qgis.DistanceUnit = Qgis.DistanceUnit.Meters)
- Return type:
bool
- static areThereNewFieldsToCreate(datasetName: str | None, layerName: str | None, layer: QgsVectorLayer | None, attributes: Iterable[int]) bool [source]¶
Returns whether there are among the attributes specified some that do not exist yet in the layer
- Parameters:
datasetName (Optional[str])
layerName (Optional[str])
layer (Optional[QgsVectorLayer])
attributes (Iterable[int])
- Return type:
bool
- capabilities(self) Qgis.VectorFileWriterCapabilities [source]¶
Returns the capabilities supported by the writer.
Added in version 3.32.
- Return type:
- static convertCodecNameForEncodingOption(codecName: str | None) str [source]¶
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile
- Parameters:
codecName (Optional[str])
- Return type:
str
- static create(fileName: str | None, fields: QgsFields, geometryType: Qgis.WkbType, srs: QgsCoordinateReferenceSystem, transformContext: QgsCoordinateTransformContext, options: QgsVectorFileWriter.SaveVectorOptions, sinkFlags: QgsFeatureSink.SinkFlags | QgsFeatureSink.SinkFlag = QgsFeatureSink.SinkFlags(), newFilename: str | None | None = '', newLayer: str | None | None = '') QgsVectorFileWriter | None [source]¶
Create a new vector file writer.
- Parameters:
fileName (Optional[str]) – file name to write to
fields (QgsFields) – fields to write
geometryType (Qgis.WkbType) – geometry type of output file
srs (QgsCoordinateReferenceSystem) – spatial reference system of output file
transformContext (QgsCoordinateTransformContext) – coordinate transform context
options (QgsVectorFileWriter.SaveVectorOptions) – save options
sinkFlags (Union[QgsFeatureSink.SinkFlags, QgsFeatureSink.SinkFlag] = QgsFeatureSink.SinkFlags()) – feature sink flags
newFilename (Optional[Optional[str]] = '') – potentially modified file name (output parameter)
newLayer (Optional[Optional[str]] = '') – potentially modified layer name (output parameter)
Added in version 3.10.3.
- Return type:
Optional[QgsVectorFileWriter]
- static defaultDatasetOptions(driverName: str | None) List[str] [source]¶
Returns a list of the default dataset options for a specified driver.
- Parameters:
driverName (Optional[str]) – name of OGR driver
See also
- Return type:
List[str]
- static defaultLayerOptions(driverName: str | None) List[str] [source]¶
Returns a list of the default layer options for a specified driver.
- Parameters:
driverName (Optional[str]) – name of OGR driver
See also
- Return type:
List[str]
- static deleteShapeFile(fileName: str | None) bool [source]¶
Delete a shapefile (and its accompanying shx / dbf / prj / qix / qpj / cpg / sbn / sbx / idm / ind)
- Parameters:
fileName (Optional[str]) – /path/to/file.shp
- Return type:
bool
- Returns:
bool
True
if the file was deleted successfully
- driver(self) str [source]¶
Returns the GDAL (short) driver name associated with the output file.
See also
Added in version 3.32.
- Return type:
str
- static driverForExtension(extension: str | None) str [source]¶
Returns the OGR driver name for a specified file
extension
. E.g. the driver name for the “.shp” extension is “ESRI Shapefile”. If no suitable drivers are found then an empty string is returned.- Parameters:
extension (Optional[str])
- Return type:
str
- driverLongName(self) str [source]¶
Returns the GDAL long driver name associated with the output file.
See also
Added in version 3.32.
- Return type:
str
- static driverMetadata(driverName: str | None, driverMetadata: QgsVectorFileWriter.MetaData) bool [source]¶
- Parameters:
driverName (Optional[str])
driverMetadata (QgsVectorFileWriter.MetaData)
- Return type:
bool
- static editionCapabilities(datasetName: str | None) QgsVectorFileWriter.EditionCapabilities [source]¶
Returns edition capabilities for an existing dataset name.
- Parameters:
datasetName (Optional[str])
- Return type:
- static fileFilterString(options: QgsVectorFileWriter.VectorFormatOptions | QgsVectorFileWriter.VectorFormatOption = QgsVectorFileWriter.SortRecommended) str [source]¶
Returns filter string that can be used for dialogs.
The
options
argument can be used to control the sorting and filtering of returned drivers.- Parameters:
options (Union[QgsVectorFileWriter.VectorFormatOptions, QgsVectorFileWriter.VectorFormatOption] = QgsVectorFileWriter.SortRecommended)
- Return type:
str
- static filterForDriver(driverName: str | None) str [source]¶
Creates a filter for an OGR driver key
- Parameters:
driverName (Optional[str])
- Return type:
str
- hasError(self) QgsVectorFileWriter.WriterError [source]¶
Checks whether there were any errors in constructor
- Return type:
- static ogrDriverList(options: QgsVectorFileWriter.VectorFormatOptions | QgsVectorFileWriter.VectorFormatOption = QgsVectorFileWriter.SortRecommended) List[QgsVectorFileWriter.DriverDetails] ¶
Returns the driver list that can be used for dialogs. It contains all OGR drivers plus some additional internal QGIS driver names to distinguish between more supported formats of the same OGR driver.
The returned list consists of structs containing the driver long name (e.g. user-friendly display name for the format) and internal driver short name.
The
options
argument can be used to control the sorting and filtering of returned drivers.- Parameters:
options (Union[QgsVectorFileWriter.VectorFormatOptions, QgsVectorFileWriter.VectorFormatOption] = QgsVectorFileWriter.SortRecommended)
- Return type:
- setSymbologyExport(self, symExport: Qgis.FeatureSymbologyExport)[source]¶
Sets the feature symbology export handling for the writer.
See also
- Parameters:
symExport (Qgis.FeatureSymbologyExport)
- setSymbologyScale(self, scale: float)[source]¶
Set reference
scale
for output. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.See also
- Parameters:
scale (float)
- sourceFieldIndexToWriterFieldIndex(self) Any ¶
Returns the map of original source field index to output file field index.
Added in version 3.44.
- Return type:
Any
- static supportedFiltersAndFormats(options: QgsVectorFileWriter.VectorFormatOptions | QgsVectorFileWriter.VectorFormatOption = QgsVectorFileWriter.SortRecommended) List[QgsVectorFileWriter.FilterFormatDetails] ¶
Returns a list or pairs, with format filter string as first element and OGR format key as second element.
The
options
argument can be used to control the sorting and filtering of returned formats.See also
- Parameters:
options (Union[QgsVectorFileWriter.VectorFormatOptions, QgsVectorFileWriter.VectorFormatOption] = QgsVectorFileWriter.SortRecommended)
- Return type:
- static supportedFormatExtensions(options: QgsVectorFileWriter.VectorFormatOptions | QgsVectorFileWriter.VectorFormatOption = QgsVectorFileWriter.SortRecommended) List[str] [source]¶
Returns a list of file extensions for supported formats, e.g “shp”, “gpkg”.
The
options
argument can be used to control the sorting and filtering of returned formats.See also
- Parameters:
options (Union[QgsVectorFileWriter.VectorFormatOptions, QgsVectorFileWriter.VectorFormatOption] = QgsVectorFileWriter.SortRecommended)
- Return type:
List[str]
- static supportsFeatureStyles(driverName: str | None) bool [source]¶
Returns
True
if the specifieddriverName
supports feature styles.The
driverName
argument must be a valid GDAL driver name.- Parameters:
driverName (Optional[str])
- Return type:
bool
- symbologyExport(self) Qgis.FeatureSymbologyExport [source]¶
Returns the feature symbology export handling for the writer.
See also
- Return type:
- symbologyScale(self) float [source]¶
Returns the reference scale for output. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
See also
- Return type:
float
- static targetLayerExists(datasetName: str | None, layerName: str | None) bool [source]¶
Returns whether the target layer already exists.
- Parameters:
datasetName (Optional[str])
layerName (Optional[str])
- Return type:
bool
- writeAsVectorFormat(layer: QgsVectorLayer | None, fileName: str | None, fileEncoding: str | None, destCRS: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem(), driverName: str | None = '', onlySelected: bool = False, datasourceOptions: Iterable[str | None] = [], layerOptions: Iterable[str | None] = [], skipAttributeCreation: bool = False, newFilename: str | None | None = '', symbologyExport: Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology, symbologyScale: float = 1, filterExtent: QgsRectangle | None = None, overrideGeometryType: Qgis.WkbType = Qgis.WkbType.Unknown, forceMulti: bool = False, includeZ: bool = False, attributes: Iterable[int] = [], fieldValueConverter: QgsVectorFileWriter.FieldValueConverter | None = None)[source]¶
Write contents of vector layer to an (OGR supported) vector format
- Parameters:
layer (Optional[QgsVectorLayer]) – layer to write
fileName (Optional[str]) – file name to write to
fileEncoding (Optional[str]) – encoding to use
destCRS (
QgsCoordinateReferenceSystem
= QgsCoordinateReferenceSystem()) – CRS to reproject exported geometries to, or invalid CRS for no reprojectiondriverName (Optional[str] = '') – OGR driver to use
onlySelected (bool = False) – write only selected features of layer
datasourceOptions (Iterable[Optional[str]] = []) – list of OGR data source creation options
layerOptions (Iterable[Optional[str]] = []) – list of OGR layer creation options
skipAttributeCreation (bool = False) – only write geometries
newFilename (Optional[Optional[str]] = '') – will be set to the new file name created (in case it is different to fileName).
symbologyExport (Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology) – symbology to export
symbologyScale (float = 1) – scale of symbology
filterExtent (Optional[QgsRectangle] = None) – if not
None
, only features intersecting the extent will be saved (added in QGIS 2.4)overrideGeometryType (Qgis.WkbType = Qgis.WkbType.Unknown) – set to a valid geometry type to override the default geometry type for the layer. This parameter allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14)
forceMulti (bool = False) – set to
True
to force creation of multipart geometries (added in QGIS 2.14)includeZ (bool = False) – set to
True
to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14)attributes (Iterable[int] = []) – attributes to export (empty means all unless skipAttributeCreation is set)
fieldValueConverter (Optional[QgsVectorFileWriter.FieldValueConverter] = None) -> (QgsVectorFileWriter.WriterError) – field value converter (added in QGIS 2.16)
- Returns:
QgsVectorFileWriter.WriterError.NoError in case of success, or error code in case of error
errorMessage: the error message text, if an error occurs while writing the layer
Deprecated since version 3.40: Use
writeAsVectorFormatV2()
instead.
- writeAsVectorFormat(layer: QgsVectorLayer | None, fileName: str | None, fileEncoding: str | None, ct: QgsCoordinateTransform, driverName: str | None = '', onlySelected: bool = False, datasourceOptions: Iterable[str | None] = [], layerOptions: Iterable[str | None] = [], skipAttributeCreation: bool = False, newFilename: str | None | None = '', symbologyExport: Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology, symbologyScale: float = 1, filterExtent: QgsRectangle | None = None, overrideGeometryType: Qgis.WkbType = Qgis.WkbType.Unknown, forceMulti: bool = False, includeZ: bool = False, attributes: Iterable[int] = [], fieldValueConverter: QgsVectorFileWriter.FieldValueConverter | None = None)[source]
Writes a layer out to a vector file.
- Parameters:
layer (Optional[QgsVectorLayer]) – layer to write
fileName (Optional[str]) – file name to write to
fileEncoding (Optional[str]) – encoding to use
ct (
QgsCoordinateTransform
) – coordinate transform to reproject exported geometries with, or invalid transform for no transformationdriverName (Optional[str] = '') – OGR driver to use
onlySelected (bool = False) – write only selected features of layer
datasourceOptions (Iterable[Optional[str]] = []) – list of OGR data source creation options
layerOptions (Iterable[Optional[str]] = []) – list of OGR layer creation options
skipAttributeCreation (bool = False) – only write geometries
newFilename (Optional[Optional[str]] = '') – will be set to the new file name created (in case it is different to fileName).
symbologyExport (Qgis.FeatureSymbologyExport = Qgis.FeatureSymbologyExport.NoSymbology) – symbology to export
symbologyScale (float = 1) – scale of symbology
filterExtent (Optional[QgsRectangle] = None) – if not
None
, only features intersecting the extent will be saved (added in QGIS 2.4)overrideGeometryType (Qgis.WkbType = Qgis.WkbType.Unknown) – set to a valid geometry type to override the default geometry type for the layer. This parameter allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14)
forceMulti (bool = False) – set to
True
to force creation of multipart geometries (added in QGIS 2.14)includeZ (bool = False) – set to
True
to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14)attributes (Iterable[int] = []) – attributes to export (empty means all unless skipAttributeCreation is set)
fieldValueConverter (Optional[QgsVectorFileWriter.FieldValueConverter] = None) -> (QgsVectorFileWriter.WriterError) – field value converter (added in QGIS 2.16)
- Returns:
QgsVectorFileWriter.WriterError.NoError in case of success, or error code in case of error
errorMessage: the error message text, if an error occurs while writing the layer
Deprecated since version 3.40: Use
writeAsVectorFormatV2()
instead.
- writeAsVectorFormat(layer: QgsVectorLayer | None, fileName: str | None, options: QgsVectorFileWriter.SaveVectorOptions, newFilename: str | None | None = '')[source]
Writes a layer out to a vector file.
- Parameters:
layer (Optional[QgsVectorLayer]) – source layer to write
fileName (Optional[str]) – file name to write to
options (QgsVectorFileWriter.SaveVectorOptions) – options.
newFilename (Optional[Optional[str]] = '') -> (QgsVectorFileWriter.WriterError) – will be set to the new file name created (in case it is different to fileName).
- Returns:
QgsVectorFileWriter.WriterError.NoError in case of success, or error code in case of error
errorMessage: the error message text, if an error occurs while writing the layer
Deprecated since version 3.40: Use
writeAsVectorFormatV2()
instead.
- static writeAsVectorFormatV2(layer: QgsVectorLayer | None, fileName: str | None, transformContext: QgsCoordinateTransformContext, options: QgsVectorFileWriter.SaveVectorOptions, newFilename: str | None | None = '', newLayer: str | None | None = '')[source]¶
Writes a layer out to a vector file.
- Parameters:
layer (Optional[QgsVectorLayer]) – source layer to write
fileName (Optional[str]) – file name to write to
transformContext (QgsCoordinateTransformContext) – coordinate transform context
options (QgsVectorFileWriter.SaveVectorOptions) – save options
newFilename (Optional[Optional[str]] = '') – potentially modified file name (output parameter)
newLayer (Optional[Optional[str]] = '') -> (QgsVectorFileWriter.WriterError) – potentially modified layer name (output parameter)
- Returns:
Error message code, or QgsVectorFileWriter.NoError if the write operation was successful
errorMessage: the error message text, if an error occurs while writing the layer
Deprecated since version 3.20: Use
writeAsVectorFormatV3()
instead.
- static writeAsVectorFormatV3(layer: QgsVectorLayer | None, fileName: str | None, transformContext: QgsCoordinateTransformContext, options: QgsVectorFileWriter.SaveVectorOptions)[source]¶
Writes a layer out to a vector file.
- Parameters:
layer (Optional[QgsVectorLayer]) – source layer to write
fileName (Optional[str]) – file name to write to
transformContext (QgsCoordinateTransformContext) – coordinate transform context
options (QgsVectorFileWriter.SaveVectorOptions) -> (QgsVectorFileWriter.WriterError) – save options
- Returns:
Error message code, or QgsVectorFileWriter.NoError if the write operation was successful
newFilename: potentially modified file name (output parameter)
newLayer: potentially modified layer name (output parameter)
errorMessage: the error message text, if an error occurs while writing the layer
Added in version 3.20.