QGIS API Documentation 3.99.0-Master (8e76e220402)
Loading...
Searching...
No Matches
qgsvectorfilewriter.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorfilewriter.h
3 generic vector file writer
4 -------------------
5 begin : Jun 6 2004
6 copyright : (C) 2004 by Tim Sutton
7 email : tim at linfiniti.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#ifndef QGSVECTORFILEWRITER_H
20#define QGSVECTORFILEWRITER_H
21
22#include <ogr_api.h>
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
27#include "qgsfeaturesink.h"
28#include "qgsfeedback.h"
29#include "qgsfields.h"
30#include "qgsgeometryengine.h"
31#include "qgsogrutils.h"
32#include "qgsrendercontext.h"
33#include "qgsrenderer.h"
34
35#include <QString>
36
37using namespace Qt::StringLiterals;
38
39class QgsSymbolLayer;
40class QTextCodec;
42
52class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
53{
54 public:
62
67 class Option
68 {
69 public:
73 virtual ~Option() = default;
74
75 QString docString;
77 };
78
84 {
85 public:
86 SetOption( const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone = false )
87 : Option( docString, Set )
88 , values( values.begin(), values.end() )
91 {}
92
93 QSet<QString> values;
94 QString defaultValue;
96 };
97
103 {
104 public:
105 StringOption( const QString &docString, const QString &defaultValue = QString() )
108 {}
109
111 };
112
118 {
119 public:
120 IntOption( const QString &docString, int defaultValue )
121 : Option( docString, Int )
123 {}
124
126 };
127
133 {
134 public:
135 BoolOption( const QString &docString, bool defaultValue )
136 : SetOption( docString, QStringList() << u"YES"_s << u"NO"_s, defaultValue ? "YES" : "NO" )
137 {}
138 };
139
145 {
146 public:
147 explicit HiddenOption( const QString &value )
148 : Option( QString(), Hidden )
149 , mValue( value )
150 {}
151
152 QString mValue;
153 };
154
155 struct MetaData
156 {
157
158 MetaData() = default;
159
160 MetaData( const QString &longName, const QString &trLongName, const QString &glob, const QString &ext, const QMap<QString, QgsVectorFileWriter::Option *> &driverOptions, const QMap<QString, QgsVectorFileWriter::Option *> &layerOptions, const QString &compulsoryEncoding = QString() )
161 : longName( longName )
163 , glob( glob )
164 , ext( ext )
168 {}
169
170 QString longName;
171 QString trLongName;
172 QString glob;
173 QString ext;
174 QMap<QString, QgsVectorFileWriter::Option *> driverOptions;
175 QMap<QString, QgsVectorFileWriter::Option *> layerOptions;
178 };
179
194
205
216
217
221 class CORE_EXPORT FieldValueConverter
222 {
223 public:
224
226
227 virtual ~FieldValueConverter() = default;
228
234 virtual QgsField fieldDefinition( const QgsField &field );
235
242 virtual QVariant convert( int fieldIdxInLayer, const QVariant &value );
243
248 };
249
267
272
273
290
291#ifndef SIP_RUN
292
319#else
320
346#endif
347 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
348 const QString &fileName,
349 const QString &fileEncoding,
351 const QString &driverName = "GPKG",
352 bool onlySelected = false,
353 QString *errorMessage SIP_OUT = nullptr,
354 const QStringList &datasourceOptions = QStringList(),
355 const QStringList &layerOptions = QStringList(),
356 bool skipAttributeCreation = false,
357 QString *newFilename = nullptr,
359 double symbologyScale = 1.0,
360 const QgsRectangle *filterExtent = nullptr,
361 Qgis::WkbType overrideGeometryType = Qgis::WkbType::Unknown,
362 bool forceMulti = false,
363 bool includeZ = false,
364 const QgsAttributeList &attributes = QgsAttributeList(),
365 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = nullptr
366#ifndef SIP_RUN
367 , QString *newLayer = nullptr );
368#else
370#endif
371
372#ifndef SIP_RUN
373
401#else
402
429#endif
430 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
431 const QString &fileName,
432 const QString &fileEncoding,
433 const QgsCoordinateTransform &ct,
434 const QString &driverName = "GPKG",
435 bool onlySelected = false,
436 QString *errorMessage SIP_OUT = nullptr,
437 const QStringList &datasourceOptions = QStringList(),
438 const QStringList &layerOptions = QStringList(),
439 bool skipAttributeCreation = false,
440 QString *newFilename = nullptr,
442 double symbologyScale = 1.0,
443 const QgsRectangle *filterExtent = nullptr,
444 Qgis::WkbType overrideGeometryType = Qgis::WkbType::Unknown,
445 bool forceMulti = false,
446 bool includeZ = false,
447 const QgsAttributeList &attributes = QgsAttributeList(),
448 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = nullptr
449#ifndef SIP_RUN
450 , QString *newLayer = nullptr );
451#else
453#endif
454
592
593#ifndef SIP_RUN
594
606#else
607
618#endif
620 const QString &fileName,
622 QString *newFilename = nullptr,
623 QString *errorMessage SIP_OUT = nullptr
624#ifndef SIP_RUN
625 , QString *newLayer = nullptr );
626#else
628#endif
629
634 Q_DECL_DEPRECATED QgsVectorFileWriter( const QString &vectorFileName,
635 const QString &fileEncoding,
636 const QgsFields &fields,
637 Qgis::WkbType geometryType,
639 const QString &driverName = "GPKG",
640 const QStringList &datasourceOptions = QStringList(),
641 const QStringList &layerOptions = QStringList(),
642 QString *newFilename = nullptr,
645#ifndef SIP_RUN
646 , QString *newLayer = nullptr,
648 FieldNameSource fieldNameSource = Original
649#endif
651
677 Q_DECL_DEPRECATED QgsVectorFileWriter( const QString &vectorFileName,
678 const QString &fileEncoding,
679 const QgsFields &fields,
680 Qgis::WkbType geometryType,
682 const QString &driverName,
683 const QStringList &datasourceOptions,
684 const QStringList &layerOptions,
685 QString *newFilename,
687 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter,
688 const QString &layerName,
690 QString *newLayer = nullptr,
693 FieldNameSource fieldNameSource = Original,
694 bool includeConstraints = false,
695 bool setFieldDomains = true,
696 const QgsAbstractDatabaseProviderConnection *sourceDatabaseProviderConnection = nullptr
697 ) SIP_SKIP;
698
700 QgsVectorFileWriter &operator=( const QgsVectorFileWriter &rh ) = delete;
701
715 static QgsVectorFileWriter *create( const QString &fileName,
716 const QgsFields &fields,
717 Qgis::WkbType geometryType,
719 const QgsCoordinateTransformContext &transformContext,
722 QString *newFilename = nullptr,
723 QString *newLayer = nullptr ) SIP_FACTORY;
724
738 const QString &fileName,
739 const QgsCoordinateTransformContext &transformContext,
741 QString *newFilename = nullptr,
742 QString *newLayer = nullptr,
743 QString *errorMessage SIP_OUT = nullptr ) SIP_DEPRECATED;
744
758 const QString &fileName,
759 const QgsCoordinateTransformContext &transformContext,
761 QString *errorMessage SIP_OUT = nullptr,
762 QString *newFilename SIP_OUT = nullptr,
763 QString *newLayer SIP_OUT = nullptr );
764
769 {
771 QString driverName;
772
775
780 QStringList globs;
781 };
782
791 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
792
801 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
802
809 static bool supportsFeatureStyles( const QString &driverName );
810
815 {
817 QString longName;
818
820 QString driverName;
821 };
822
834 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
835
841 static QString driverForExtension( const QString &extension );
842
849 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
850
852 static QString filterForDriver( const QString &driverName );
853
855 static QString convertCodecNameForEncodingOption( const QString &codecName );
856
859
861 QString errorMessage() const;
862
869 QString driver() const;
870
877 QString driverLongName() const;
878
885
886 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
887
889 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
890 QString lastError() const override;
891
896
902 QMap<int, int> sourceFieldIndexToWriterFieldIndex() const { return mAttrIdxToOgrIdx; }
903
905 ~QgsVectorFileWriter() override;
906
912 static bool deleteShapeFile( const QString &fileName );
913
920
927
933 double symbologyScale() const { return mSymbologyScale; }
934
940 void setSymbologyScale( double scale );
941
942 static bool driverMetadata( const QString &driverName, MetaData &driverMetadata );
943
949 static QStringList defaultDatasetOptions( const QString &driverName );
950
956 static QStringList defaultLayerOptions( const QString &driverName );
957
964 static OGRwkbGeometryType ogrTypeFromWkbType( Qgis::WkbType type ) SIP_SKIP;
965
969 static QgsVectorFileWriter::EditionCapabilities editionCapabilities( const QString &datasetName );
970
974 static bool targetLayerExists( const QString &datasetName,
975 const QString &layerName );
976
980 static bool areThereNewFieldsToCreate( const QString &datasetName,
981 const QString &layerName,
982 QgsVectorLayer *layer,
983 const QgsAttributeList &attributes );
984
985 protected:
987 OGRGeometryH createEmptyGeometry( Qgis::WkbType wkbType ) SIP_SKIP;
988
990 OGRLayerH mLayer = nullptr;
991 OGRSpatialReferenceH mOgrRef = nullptr;
992
994
998
999 QTextCodec *mCodec = nullptr;
1000
1003
1005 QMap<int, int> mAttrIdxToOgrIdx;
1006
1008
1009 QMap< QgsSymbolLayer *, QString > mSymbolLayerTable;
1010
1013
1016
1019
1022
1024 bool mSetFieldDomains = true;
1025
1026 private:
1027#ifdef SIP_RUN
1029#endif
1030
1031 struct PreparedWriterDetails
1032 {
1033 std::unique_ptr< QgsFeatureRenderer > renderer;
1035 Qgis::WkbType sourceWkbType = Qgis::WkbType::Unknown;
1036 QgsFields sourceFields;
1037 QString providerType;
1038 long long featureCount = 0;
1039 QgsFeatureIds selectedFeatureIds;
1040 QString dataSourceUri;
1041 QString storageType;
1042 QgsFeatureIterator geometryTypeScanIterator;
1043 QgsExpressionContext expressionContext;
1044 QSet< int > fieldsToConvertToInt;
1045 QgsRenderContext renderContext;
1046 bool shallTransform = false;
1049 QgsAttributeList attributes;
1050 QgsFields outputFields;
1051 QgsFeatureIterator sourceFeatureIterator;
1052 QgsGeometry filterRectGeometry;
1053 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1054 QVariantMap providerUriParams;
1055 std::unique_ptr< QgsAbstractDatabaseProviderConnection > sourceDatabaseProviderConnection;
1056 };
1057
1062 static QgsVectorFileWriter::WriterError prepareWriteAsVectorFormat( QgsVectorLayer *layer,
1064 PreparedWriterDetails &details );
1065
1080 static QgsVectorFileWriter::WriterError writeAsVectorFormatV2( PreparedWriterDetails &details,
1081 const QString &fileName,
1082 const QgsCoordinateTransformContext &transformContext,
1084 QString *newFilename = nullptr,
1085 QString *newLayer = nullptr,
1086 QString *errorMessage SIP_OUT = nullptr,
1088
1094 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( PreparedWriterDetails &details,
1095 const QString &fileName,
1097 QString *newFilename = nullptr,
1098 QString *errorMessage SIP_OUT = nullptr,
1099 QString *newLayer = nullptr ) SIP_DEPRECATED;
1100
1101 void init( QString vectorFileName, QString fileEncoding, const QgsFields &fields,
1102 Qgis::WkbType geometryType, QgsCoordinateReferenceSystem srs,
1103 const QString &driverName, QStringList datasourceOptions,
1104 QStringList layerOptions, QString *newFilename,
1105 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter,
1106 const QString &layerName,
1107 QgsVectorFileWriter::ActionOnExistingFile action, QString *newLayer, QgsFeatureSink::SinkFlags sinkFlags,
1108 const QgsCoordinateTransformContext &transformContext,
1109 FieldNameSource fieldNameSource,
1110 const QgsAbstractDatabaseProviderConnection *sourceDatabaseProviderConnection );
1111 void resetMap( const QgsAttributeList &attributes );
1112
1113 std::unique_ptr< QgsFeatureRenderer > mRenderer;
1114 QgsRenderContext mRenderContext;
1115
1116
1117 std::unique_ptr< QgsCoordinateTransform > mCoordinateTransform;
1118
1119 bool mUsingTransaction = false;
1120 QSet< QMetaType::Type > mSupportedListSubTypes;
1121
1122 Qgis::VectorFileWriterCapabilities mCapabilities;
1123
1124 void createSymbolLayerTable( QgsVectorLayer *vl, const QgsCoordinateTransform &ct, OGRDataSourceH ds );
1125 gdal::ogr_feature_unique_ptr createFeature( const QgsFeature &feature );
1126 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1127
1129 QgsVectorFileWriter::WriterError exportFeaturesSymbolLevels( const PreparedWriterDetails &details, QgsFeatureIterator &fit, const QgsCoordinateTransform &ct, QString *errorMessage = nullptr );
1130 double mmScaleFactor( double scale, Qgis::RenderUnit symbolUnits, Qgis::DistanceUnit mapUnits );
1131 double mapUnitScaleFactor( double scale, Qgis::RenderUnit symbolUnits, Qgis::DistanceUnit mapUnits );
1132
1133 void startRender( QgsFeatureRenderer *sourceRenderer, const QgsFields &fields );
1134 void stopRender();
1135 std::unique_ptr< QgsFeatureRenderer > createSymbologyRenderer( QgsFeatureRenderer *sourceRenderer ) const;
1137 static void addRendererAttributes( QgsFeatureRenderer *renderer, QgsRenderContext &context, const QgsFields &fields, QgsAttributeList &attList );
1138
1140 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1141
1144};
1145
1148
1149// clazy:excludeall=qstring-allocations
1150
1151#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
DistanceUnit
Units of distance.
Definition qgis.h:5120
@ Meters
Meters.
Definition qgis.h:5121
QFlags< VectorFileWriterCapability > VectorFileWriterCapabilities
Capabilities supported by a QgsVectorFileWriter object.
Definition qgis.h:1102
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Unknown
Unknown.
Definition qgis.h:281
FeatureSymbologyExport
Options for exporting features considering their symbology.
Definition qgis.h:5858
@ NoSymbology
Export only data.
Definition qgis.h:5859
Provides common functionality for database based connections.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
Abstract base class for all 2D vector feature renderers.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
virtual QString lastError() const
Returns the most recent error encountered by the sink, e.g.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())=0
Adds a list of features to the sink.
QFlags< Flag > Flags
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
A structured metadata store for a map layer.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Abstract base class for symbol layers.
BoolOption(const QString &docString, bool defaultValue)
Interface to convert raw field values to their user-friendly values.
virtual QVariant convert(int fieldIdxInLayer, const QVariant &value)
Convert the provided value, for field fieldIdxInLayer.
virtual QgsVectorFileWriter::FieldValueConverter * clone() const
Creates a clone of the FieldValueConverter.
virtual QgsField fieldDefinition(const QgsField &field)
Returns a possibly modified field definition.
IntOption(const QString &docString, int defaultValue)
Describes an available option for configuring file writing for a particular output format.
Option(const QString &docString, QgsVectorFileWriter::OptionType type)
QgsVectorFileWriter::OptionType type
virtual ~Option()=default
Options to pass to QgsVectorFileWriter::writeAsVectorFormat().
bool forceMulti
Sets to true to force creation of multipart geometries.
QgsCoordinateTransform ct
Transform to reproject exported geometries with, or invalid transform for no transformation.
QStringList attributesExportNames
Attributes export names.
QgsLayerMetadata layerMetadata
Layer metadata to save for the exported vector file.
QString layerName
Layer name. If let empty, it will be derived from the filename.
QgsRectangle filterExtent
If not empty, only features intersecting the extent will be saved.
bool includeConstraints
Set to true to transfer field constraints to the exported vector file.
const QgsAbstractDatabaseProviderConnection * sourceDatabaseProviderConnection
Source database provider connection, for field domains.
QgsVectorFileWriter::FieldValueConverter * fieldValueConverter
Field value converter.
QStringList layerOptions
List of OGR layer creation options.
Qgis::WkbType overrideGeometryType
Set to a valid geometry type to override the default geometry type for the layer.
bool includeZ
Sets to true to include z dimension in output. This option is only valid if overrideGeometryType is s...
Qgis::FeatureSymbologyExport symbologyExport
Symbology to export.
bool saveMetadata
Set to true to save layer metadata for the exported vector file.
QgsVectorFileWriter::ActionOnExistingFile actionOnExistingFile
Action on existing file.
QgsAttributeList attributes
Attributes to export (empty means all unless skipAttributeCreation is set).
bool onlySelectedFeatures
Write only selected features of layer.
QgsVectorFileWriter::FieldNameSource fieldNameSource
Source for exported field names.
bool skipAttributeCreation
Only write geometries.
bool setFieldDomains
Set to true to transfer field domains to the exported vector file.
QStringList datasourceOptions
List of OGR data source creation options.
QgsFeedback * feedback
Optional feedback object allowing cancellation of layer save.
An available option for configuring file writing for a particular output format, presenting a choice ...
SetOption(const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone=false)
StringOption(const QString &docString, const QString &defaultValue=QString())
A convenience class for writing vector layers to disk based formats (e.g.
static QgsVectorFileWriter::WriterError writeAsVectorFormatV3(QgsVectorLayer *layer, const QString &fileName, const QgsCoordinateTransformContext &transformContext, const QgsVectorFileWriter::SaveVectorOptions &options, QString *errorMessage=nullptr, QString *newFilename=nullptr, QString *newLayer=nullptr)
Writes a layer out to a vector file.
Qgis::FeatureSymbologyExport mSymbologyExport
EditionCapability
Edition capability flags.
@ CanAddNewFieldsToExistingLayer
Flag to indicate that new fields can be added to an existing layer. Imply CanAppendToExistingLayer.
@ CanAppendToExistingLayer
Flag to indicate that new features can be added to an existing layer.
@ CanAddNewLayer
Flag to indicate that a new layer can be added to the dataset.
@ CanDeleteLayer
Flag to indicate that an existing layer can be deleted.
static bool supportsFeatureStyles(const QString &driverName)
Returns true if the specified driverName supports feature styles.
Qgis::WkbType mWkbType
Geometry type which is being used.
double mSymbologyScale
Scale for symbology export (e.g. for symbols units in map units).
QMap< int, int > mAttrIdxToOgrIdx
Map attribute indizes to OGR field indexes.
@ Canceled
Writing was interrupted by manual cancellation.
@ ErrSavingMetadata
Metadata saving failed.
gdal::ogr_datasource_unique_ptr mDS
static Q_DECL_DEPRECATED QgsVectorFileWriter::WriterError writeAsVectorFormatV2(QgsVectorLayer *layer, const QString &fileName, const QgsCoordinateTransformContext &transformContext, const QgsVectorFileWriter::SaveVectorOptions &options, QString *newFilename=nullptr, QString *newLayer=nullptr, QString *errorMessage=nullptr)
Writes a layer out to a vector file.
QFlags< EditionCapability > EditionCapabilities
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
double symbologyScale() const
Returns the reference scale for output.
static QString driverForExtension(const QString &extension)
Returns the OGR driver name for a specified file extension.
Qgis::VectorFileWriterCapabilities capabilities() const
Returns the capabilities supported by the writer.
friend class QgsVectorFileWriterTask
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 elem...
OGRSpatialReferenceH mOgrRef
static QgsVectorFileWriter * create(const QString &fileName, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &srs, const QgsCoordinateTransformContext &transformContext, const QgsVectorFileWriter::SaveVectorOptions &options, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QString *newFilename=nullptr, QString *newLayer=nullptr)
Create a new vector file writer.
QString driver() const
Returns the GDAL (short) driver name associated with the output file.
Q_DECL_DEPRECATED QgsVectorFileWriter(const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &srs=QgsCoordinateReferenceSystem(), const QString &driverName="GPKG", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=nullptr, Qgis::FeatureSymbologyExport symbologyExport=Qgis::FeatureSymbologyExport::NoSymbology, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QString *newLayer=nullptr, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext(), FieldNameSource fieldNameSource=Original)
Create a new vector file writer.
static Q_DECL_DEPRECATED 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, Qgis::FeatureSymbologyExport symbologyExport=Qgis::FeatureSymbologyExport::NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, Qgis::WkbType overrideGeometryType=Qgis::WkbType::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.
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
QgsVectorFileWriter::WriterError hasError() const
Checks whether there were any errors in constructor.
VectorFormatOption
Options for sorting and filtering vector formats.
@ SupportsMultipleLayers
Filter to only formats which support multiple layers.
@ SkipNonSpatialFormats
Filter out any formats which do not have spatial support (e.g. those which cannot save geometries).
@ SortRecommended
Use recommended sort order, with extremely commonly used formats listed first.
static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(VectorFormatOptions options=SortRecommended)
Returns the driver list that can be used for dialogs.
QString driverLongName() const
Returns the GDAL long driver name associated with the output file.
QFlags< VectorFormatOption > VectorFormatOptions
WriterError mError
Contains error value if construction was not successful.
Qgis::FeatureSymbologyExport symbologyExport() const
Returns the feature symbology export handling for the writer.
FieldNameSource
Source for exported field names.
@ PreferAlias
Use the field alias as the exported field name, wherever one is set. Otherwise use the original field...
@ Original
Use original field names.
friend class TestQgsVectorFileWriter
bool mIncludeConstraints
Whether to transfer field constraints to output.
bool addFeatureWithStyle(QgsFeature &feature, QgsFeatureRenderer *renderer, Qgis::DistanceUnit outputUnit=Qgis::DistanceUnit::Meters)
Adds a feature to the currently opened data source, using the style from a specified renderer.
static QStringList supportedFormatExtensions(VectorFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats, e.g "shp", "gpkg".
bool mSetFieldDomains
Whether to set field domains to output.
static QString convertCodecNameForEncodingOption(const QString &codecName)
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.
FieldValueConverter * mFieldValueConverter
Field value converter.
QString errorMessage() const
Retrieves error message.
void setSymbologyExport(Qgis::FeatureSymbologyExport symExport)
Sets the feature symbology export handling for the writer.
QMap< QgsSymbolLayer *, QString > mSymbolLayerTable
static QString fileFilterString(VectorFormatOptions options=SortRecommended)
Returns filter string that can be used for dialogs.
QMap< int, int > sourceFieldIndexToWriterFieldIndex() const
Returns the map of original source field index to output file field index.
ActionOnExistingFile
Enumeration to describe how to handle existing files.
@ CreateOrOverwriteLayer
Create or overwrite layer.
@ CreateOrOverwriteFile
Create or overwrite file.
@ AppendToLayerNoNewFields
Append features to existing layer, but do not create new fields.
@ AppendToLayerAddFields
Append features to existing layer, and create new fields if needed.
Represents a vector layer which manages a vector based dataset.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
Definition qgsfield.h:30
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
Details of available driver formats.
QString longName
Descriptive, user friendly name for the driver.
QString driverName
Unique driver name.
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.
QStringList globs
Matching glob patterns for format, e.g.
MetaData(const QString &longName, const QString &trLongName, const QString &glob, const QString &ext, const QMap< QString, QgsVectorFileWriter::Option * > &driverOptions, const QMap< QString, QgsVectorFileWriter::Option * > &layerOptions, const QString &compulsoryEncoding=QString())
QMap< QString, QgsVectorFileWriter::Option * > driverOptions
QMap< QString, QgsVectorFileWriter::Option * > layerOptions
QString compulsoryEncoding
Some formats require a compulsory encoding, typically UTF-8. If no compulsory encoding,...