QGIS API Documentation
3.6.0-Noosa (5873452)
|
A convenience class for writing vector files to disk. More...
#include <qgsvectorfilewriter.h>
Classes | |
class | BoolOption |
struct | DriverDetails |
Details of available driver formats. More... | |
class | FieldValueConverter |
Interface to convert raw field values to their user-friendly value. More... | |
struct | FilterFormatDetails |
Details of available filters and formats. More... | |
class | HiddenOption |
class | IntOption |
struct | MetaData |
class | Option |
class | SaveVectorOptions |
Options to pass to writeAsVectorFormat() More... | |
class | SetOption |
class | StringOption |
Public Member Functions | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &srs=QgsCoordinateReferenceSystem(), const QString &driverName="GPKG", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=nullptr, QgsVectorFileWriter::SymbologyExport symbologyExport=QgsVectorFileWriter::NoSymbology, QgsFeatureSink::SinkFlags sinkFlags=nullptr, QString *newLayer=nullptr) | |
Create a new vector file writer. More... | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &srs, const QString &driverName, const QStringList &datasourceOptions, const QStringList &layerOptions, QString *newFilename, QgsVectorFileWriter::SymbologyExport symbologyExport, QgsVectorFileWriter::FieldValueConverter *fieldValueConverter, const QString &layerName, QgsVectorFileWriter::ActionOnExistingFile action, QString *newLayer=nullptr) | |
Create a new vector file writer. More... | |
QgsVectorFileWriter (const QgsVectorFileWriter &rh)=delete | |
QgsVectorFileWriter cannot be copied. More... | |
~QgsVectorFileWriter () override | |
Close opened shapefile for writing. More... | |
bool | addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override |
Adds a single feature to the sink. More... | |
bool | addFeatures (QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override |
Adds a list of features to the sink. More... | |
bool | addFeatureWithStyle (QgsFeature &feature, QgsFeatureRenderer *renderer, QgsUnitTypes::DistanceUnit outputUnit=QgsUnitTypes::DistanceMeters) |
Adds a feature to the currently opened data source, using the style from a specified renderer. More... | |
QMap< int, int > | attrIdxToOgrIdx () |
QString | errorMessage () |
Retrieves error message. More... | |
QgsVectorFileWriter::WriterError | hasError () |
Checks whether there were any errors in constructor. More... | |
QgsVectorFileWriter & | operator= (const QgsVectorFileWriter &rh)=delete |
QgsVectorFileWriter cannot be copied. More... | |
void | setSymbologyExport (QgsVectorFileWriter::SymbologyExport symExport) |
void | setSymbologyScale (double scale) |
Set reference scale for output. More... | |
QgsVectorFileWriter::SymbologyExport | symbologyExport () const |
double | symbologyScale () const |
Returns the reference scale for output. More... | |
Public Member Functions inherited from QgsFeatureSink | |
virtual | ~QgsFeatureSink ()=default |
virtual bool | addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=nullptr) |
Adds all features from the specified iterator to the sink. More... | |
virtual bool | flushBuffer () |
Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination. More... | |
Static Public Member Functions | |
static bool | areThereNewFieldsToCreate (const QString &datasetName, const QString &layerName, QgsVectorLayer *layer, const QgsAttributeList &attributes) |
Returns whether there are among the attributes specified some that do not exist yet in the layer. More... | |
static QString | convertCodecNameForEncodingOption (const QString &codecName) |
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile. More... | |
static QStringList | defaultDatasetOptions (const QString &driverName) |
Returns a list of the default dataset options for a specified driver. More... | |
static QStringList | defaultLayerOptions (const QString &driverName) |
Returns a list of the default layer options for a specified driver. More... | |
static bool | deleteShapeFile (const QString &fileName) |
Delete a shapefile (and its accompanying shx / dbf / prf) More... | |
static QString | driverForExtension (const QString &extension) |
Returns the OGR driver name for a specified file extension. More... | |
static bool | driverMetadata (const QString &driverName, MetaData &driverMetadata) |
static QgsVectorFileWriter::EditionCapabilities | editionCapabilities (const QString &datasetName) |
Returns edition capabilities for an existing dataset name. More... | |
static QString | fileFilterString (VectorFormatOptions options=SortRecommended) |
Returns filter string that can be used for dialogs. More... | |
static QString | filterForDriver (const QString &driverName) |
Creates a filter for an OGR driver key. More... | |
static QList< QgsVectorFileWriter::DriverDetails > | ogrDriverList (VectorFormatOptions options=SortRecommended) |
Returns the driver list that can be used for dialogs. More... | |
static OGRwkbGeometryType | ogrTypeFromWkbType (QgsWkbTypes::Type type) |
Gets the ogr geometry type from an internal QGIS wkb type enum. More... | |
static QList< QgsVectorFileWriter::FilterFormatDetails > | supportedFiltersAndFormats (VectorFormatOptions options=SortRecommended) |
Returns a list or pairs, with format filter string as first element and OGR format key as second element. More... | |
static QStringList | supportedFormatExtensions (VectorFormatOptions options=SortRecommended) |
Returns a list of file extensions for supported formats, e.g "shp", "gpkg". More... | |
static bool | supportsFeatureStyles (const QString &driverName) |
Returns true if the specified driverName supports feature styles. More... | |
static bool | targetLayerExists (const QString &datasetName, const QString &layerName) |
Returns whether the target layer already exists. More... | |
static QgsVectorFileWriter::WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateReferenceSystem &destCRS=QgsCoordinateReferenceSystem(), const QString &driverName="GPKG", bool onlySelected=false, QString *errorMessage=nullptr, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=nullptr, QgsVectorFileWriter::SymbologyExport symbologyExport=QgsVectorFileWriter::NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, QgsWkbTypes::Type overrideGeometryType=QgsWkbTypes::Unknown, bool forceMulti=false, bool includeZ=false, const QgsAttributeList &attributes=QgsAttributeList(), QgsVectorFileWriter::FieldValueConverter *fieldValueConverter=nullptr, QString *newLayer=nullptr) |
Write contents of vector layer to an (OGR supported) vector format. More... | |
static QgsVectorFileWriter::WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateTransform &ct, const QString &driverName="GPKG", bool onlySelected=false, QString *errorMessage=nullptr, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=nullptr, QgsVectorFileWriter::SymbologyExport symbologyExport=QgsVectorFileWriter::NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, QgsWkbTypes::Type overrideGeometryType=QgsWkbTypes::Unknown, bool forceMulti=false, bool includeZ=false, const QgsAttributeList &attributes=QgsAttributeList(), QgsVectorFileWriter::FieldValueConverter *fieldValueConverter=nullptr, QString *newLayer=nullptr) |
Writes a layer out to a vector file. More... | |
static QgsVectorFileWriter::WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const QgsVectorFileWriter::SaveVectorOptions &options, QString *newFilename=nullptr, QString *errorMessage=nullptr, QString *newLayer=nullptr) |
Writes a layer out to a vector file. More... | |
Protected Member Functions | |
OGRGeometryH | createEmptyGeometry (QgsWkbTypes::Type wkbType) |
Protected Attributes | |
QMap< int, int > | mAttrIdxToOgrIdx |
Map attribute indizes to OGR field indexes. More... | |
QTextCodec * | mCodec = nullptr |
gdal::ogr_datasource_unique_ptr | mDS |
WriterError | mError |
Contains error value if construction was not successful. More... | |
QString | mErrorMessage |
QgsFields | mFields |
FieldValueConverter * | mFieldValueConverter = nullptr |
Field value converter. More... | |
OGRLayerH | mLayer = nullptr |
QString | mOgrDriverName |
OGRSpatialReferenceH | mOgrRef = nullptr |
QMap< QgsSymbolLayer *, QString > | mSymbolLayerTable |
SymbologyExport | mSymbologyExport |
double | mSymbologyScale |
Scale for symbology export (e.g. for symbols units in map units) More... | |
QgsWkbTypes::Type | mWkbType |
Geometry type which is being used. More... | |
Friends | |
class | QgsVectorFileWriterTask |
class | TestQgsVectorFileWriter |
A convenience class for writing vector files to disk.
There are two possibilities how to use this class:
Definition at line 45 of file qgsvectorfilewriter.h.
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteLayer.
Definition at line 261 of file qgsvectorfilewriter.h.
Edition capability flags.
Definition at line 237 of file qgsvectorfilewriter.h.
Enumerator | |
---|---|
Set | |
String | |
Int | |
Hidden |
Definition at line 48 of file qgsvectorfilewriter.h.
Enumerator | |
---|---|
NoSymbology | |
FeatureSymbology | |
SymbolLayerSymbology |
Definition at line 181 of file qgsvectorfilewriter.h.
Options for sorting and filtering vector formats.
Definition at line 193 of file qgsvectorfilewriter.h.
Definition at line 167 of file qgsvectorfilewriter.h.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFields & | fields, | ||
QgsWkbTypes::Type | geometryType, | ||
const QgsCoordinateReferenceSystem & | srs = QgsCoordinateReferenceSystem() , |
||
const QString & | driverName = "GPKG" , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() , |
||
QString * | newFilename = nullptr , |
||
QgsVectorFileWriter::SymbologyExport | symbologyExport = QgsVectorFileWriter::NoSymbology , |
||
QgsFeatureSink::SinkFlags | sinkFlags = nullptr , |
||
QString * | newLayer = nullptr |
||
) |
Create a new vector file writer.
Definition at line 95 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFields & | fields, | ||
QgsWkbTypes::Type | geometryType, | ||
const QgsCoordinateReferenceSystem & | srs, | ||
const QString & | driverName, | ||
const QStringList & | datasourceOptions, | ||
const QStringList & | layerOptions, | ||
QString * | newFilename, | ||
QgsVectorFileWriter::SymbologyExport | symbologyExport, | ||
QgsVectorFileWriter::FieldValueConverter * | fieldValueConverter, | ||
const QString & | layerName, | ||
QgsVectorFileWriter::ActionOnExistingFile | action, | ||
QString * | newLayer = nullptr |
||
) |
Create a new vector file writer.
vectorFileName | file name to write to |
fileEncoding | encoding to use |
fields | fields to write |
geometryType | geometry type of output file |
srs | spatial reference system of output file |
driverName | OGR driver to use |
datasourceOptions | list of OGR data source creation options |
layerOptions | list of OGR layer creation options |
newFilename | potentially modified file name (output parameter) |
symbologyExport | symbology to export |
fieldValueConverter | field value converter (added in QGIS 2.16) |
layerName | layer name. If let empty, it will be derived from the filename (added in QGIS 3.0) |
action | action on existing file (added in QGIS 3.0) |
newLayer | potentially modified layer name (output parameter) (added in QGIS 3.4) |
Definition at line 119 of file qgsvectorfilewriter.cpp.
|
delete |
QgsVectorFileWriter cannot be copied.
|
override |
Close opened shapefile for writing.
Definition at line 2369 of file qgsvectorfilewriter.cpp.
|
overridevirtual |
Adds a single feature to the sink.
Feature addition behavior is controlled by the specified flags.
Reimplemented from QgsFeatureSink.
Definition at line 2026 of file qgsvectorfilewriter.cpp.
|
overridevirtual |
Adds a list of features to the sink.
Feature addition behavior is controlled by the specified flags.
Implements QgsFeatureSink.
Definition at line 2031 of file qgsvectorfilewriter.cpp.
bool QgsVectorFileWriter::addFeatureWithStyle | ( | QgsFeature & | feature, |
QgsFeatureRenderer * | renderer, | ||
QgsUnitTypes::DistanceUnit | outputUnit = QgsUnitTypes::DistanceMeters |
||
) |
Adds a feature to the currently opened data source, using the style from a specified renderer.
Definition at line 2042 of file qgsvectorfilewriter.cpp.
|
static |
Returns whether there are among the attributes specified some that do not exist yet in the layer.
Definition at line 3543 of file qgsvectorfilewriter.cpp.
|
inline |
Definition at line 715 of file qgsvectorfilewriter.h.
|
static |
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.
Definition at line 3152 of file qgsvectorfilewriter.cpp.
|
protected |
Definition at line 729 of file qgsvectorfilewriter.cpp.
|
static |
Returns a list of the default dataset options for a specified driver.
driverName | name of OGR driver |
Definition at line 1986 of file qgsvectorfilewriter.cpp.
|
static |
Returns a list of the default layer options for a specified driver.
driverName | name of OGR driver |
Definition at line 1995 of file qgsvectorfilewriter.cpp.
|
static |
Delete a shapefile (and its accompanying shx / dbf / prf)
fileName | /path/to/file.shp |
Definition at line 2848 of file qgsvectorfilewriter.cpp.
|
static |
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.
Definition at line 3093 of file qgsvectorfilewriter.cpp.
|
static |
Definition at line 1969 of file qgsvectorfilewriter.cpp.
|
static |
Returns edition capabilities for an existing dataset name.
Definition at line 3488 of file qgsvectorfilewriter.cpp.
QString QgsVectorFileWriter::errorMessage | ( | ) |
Retrieves error message.
Definition at line 2021 of file qgsvectorfilewriter.cpp.
|
static |
Returns filter string that can be used for dialogs.
The options argument can be used to control the sorting and filtering of returned drivers.
Definition at line 3127 of file qgsvectorfilewriter.cpp.
|
static |
Creates a filter for an OGR driver key.
Definition at line 3141 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::WriterError QgsVectorFileWriter::hasError | ( | ) |
Checks whether there were any errors in constructor.
Definition at line 2016 of file qgsvectorfilewriter.cpp.
|
static |
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.
Definition at line 2999 of file qgsvectorfilewriter.cpp.
|
static |
Gets the ogr geometry type from an internal QGIS wkb type enum.
Will drop M values and convert Z to 2.5D where required.
Definition at line 2004 of file qgsvectorfilewriter.cpp.
|
delete |
QgsVectorFileWriter cannot be copied.
|
inline |
Definition at line 728 of file qgsvectorfilewriter.h.
void QgsVectorFileWriter::setSymbologyScale | ( | double | scale | ) |
Set reference scale for output.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
Definition at line 2874 of file qgsvectorfilewriter.cpp.
|
static |
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.
Definition at line 2880 of file qgsvectorfilewriter.cpp.
|
static |
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.
Definition at line 2957 of file qgsvectorfilewriter.cpp.
|
static |
Returns true if the specified driverName supports feature styles.
The driverName argument must be a valid GDAL driver name.
Definition at line 143 of file qgsvectorfilewriter.cpp.
|
inline |
Definition at line 727 of file qgsvectorfilewriter.h.
|
inline |
Returns the reference scale for output.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
Definition at line 736 of file qgsvectorfilewriter.h.
|
static |
Returns whether the target layer already exists.
Definition at line 3527 of file qgsvectorfilewriter.cpp.
|
static |
Write contents of vector layer to an (OGR supported) vector format.
layer | layer to write |
fileName | file name to write to |
fileEncoding | encoding to use |
destCRS | CRS to reproject exported geometries to, or invalid CRS for no reprojection |
driverName | OGR driver to use |
onlySelected | write only selected features of layer |
errorMessage | pointer to buffer fo error message |
datasourceOptions | list of OGR data source creation options |
layerOptions | list of OGR layer creation options |
skipAttributeCreation | only write geometries |
newFilename | QString pointer which will contain the new file name created (in case it is different to fileName). |
symbologyExport | symbology to export |
symbologyScale | scale of symbology |
filterExtent | if not a null pointer, only features intersecting the extent will be saved (added in QGIS 2.4) |
overrideGeometryType | 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 | set to true to force creation of multi* geometries (added in QGIS 2.14) |
includeZ | set to true to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14) |
attributes | attributes to export (empty means all unless skipAttributeCreation is set) |
fieldValueConverter | field value converter (added in QGIS 2.16) |
newLayer | QString pointer which will contain the new layer name created (in case it is different to the provided layer name) (added in QGIS 3.4, not available in python) |
Definition at line 2388 of file qgsvectorfilewriter.cpp.
|
static |
Writes a layer out to a vector file.
layer | layer to write |
fileName | file name to write to |
fileEncoding | encoding to use |
ct | coordinate transform to reproject exported geometries with, or invalid transform for no transformation |
driverName | OGR driver to use |
onlySelected | write only selected features of layer |
errorMessage | pointer to buffer fo error message |
datasourceOptions | list of OGR data source creation options |
layerOptions | list of OGR layer creation options |
skipAttributeCreation | only write geometries |
newFilename | QString pointer which will contain the new file name created (in case it is different to fileName). |
symbologyExport | symbology to export |
symbologyScale | scale of symbology |
filterExtent | if not a null pointer, only features intersecting the extent will be saved (added in QGIS 2.4) |
overrideGeometryType | 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 | set to true to force creation of multi* geometries (added in QGIS 2.14) |
includeZ | set to true to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14) |
attributes | attributes to export (empty means all unless skipAttributeCreation is set) |
fieldValueConverter | field value converter (added in QGIS 2.16) |
newLayer | QString pointer which will contain the new layer name created (in case it is different to the provided layer name) (added in QGIS 3.4, not available in python) |
Definition at line 2425 of file qgsvectorfilewriter.cpp.
|
static |
Writes a layer out to a vector file.
layer | source layer to write |
fileName | file name to write to |
options | options. |
newFilename | QString pointer which will contain the new file name created (in case it is different to fileName). |
errorMessage | pointer to buffer fo error message |
newLayer | QString pointer which will contain the new layer name created (in case it is different to the provided layer name) (added in QGIS 3.4, not available in python) |
Definition at line 2832 of file qgsvectorfilewriter.cpp.
|
friend |
Definition at line 911 of file qgsvectorfilewriter.h.
|
friend |
Definition at line 912 of file qgsvectorfilewriter.h.
|
protected |
Map attribute indizes to OGR field indexes.
Definition at line 814 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 808 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 798 of file qgsvectorfilewriter.h.
|
protected |
Contains error value if construction was not successful.
Definition at line 805 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 806 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 802 of file qgsvectorfilewriter.h.
|
protected |
Field value converter.
Definition at line 826 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 799 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 823 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 800 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 818 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 816 of file qgsvectorfilewriter.h.
|
protected |
Scale for symbology export (e.g. for symbols units in map units)
Definition at line 821 of file qgsvectorfilewriter.h.
|
protected |
Geometry type which is being used.
Definition at line 811 of file qgsvectorfilewriter.h.