QGIS API Documentation 3.99.0-Master (752b475928d)
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
35class QgsSymbolLayer;
36class QTextCodec;
38
48class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
49{
50 public:
58
63 class Option
64 {
65 public:
69 virtual ~Option() = default;
70
71 QString docString;
73 };
74
80 {
81 public:
82 SetOption( const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone = false )
83 : Option( docString, Set )
84 , values( values.begin(), values.end() )
87 {}
88
89 QSet<QString> values;
90 QString defaultValue;
92 };
93
99 {
100 public:
101 StringOption( const QString &docString, const QString &defaultValue = QString() )
104 {}
105
107 };
108
114 {
115 public:
116 IntOption( const QString &docString, int defaultValue )
117 : Option( docString, Int )
119 {}
120
122 };
123
129 {
130 public:
131 BoolOption( const QString &docString, bool defaultValue )
132 : SetOption( docString, QStringList() << QStringLiteral( "YES" ) << QStringLiteral( "NO" ), defaultValue ? "YES" : "NO" )
133 {}
134 };
135
141 {
142 public:
143 explicit HiddenOption( const QString &value )
144 : Option( QString(), Hidden )
145 , mValue( value )
146 {}
147
148 QString mValue;
149 };
150
151 struct MetaData
152 {
153
154 MetaData() = default;
155
156 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() )
157 : longName( longName )
159 , glob( glob )
160 , ext( ext )
164 {}
165
166 QString longName;
167 QString trLongName;
168 QString glob;
169 QString ext;
170 QMap<QString, QgsVectorFileWriter::Option *> driverOptions;
171 QMap<QString, QgsVectorFileWriter::Option *> layerOptions;
174 };
175
190
201
212
213
217 class CORE_EXPORT FieldValueConverter
218 {
219 public:
220
222
223 virtual ~FieldValueConverter() = default;
224
230 virtual QgsField fieldDefinition( const QgsField &field );
231
238 virtual QVariant convert( int fieldIdxInLayer, const QVariant &value );
239
244 };
245
263
268
269
286
287#ifndef SIP_RUN
288
315#else
316
342#endif
343 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
344 const QString &fileName,
345 const QString &fileEncoding,
347 const QString &driverName = "GPKG",
348 bool onlySelected = false,
349 QString *errorMessage SIP_OUT = nullptr,
350 const QStringList &datasourceOptions = QStringList(),
351 const QStringList &layerOptions = QStringList(),
352 bool skipAttributeCreation = false,
353 QString *newFilename = nullptr,
355 double symbologyScale = 1.0,
356 const QgsRectangle *filterExtent = nullptr,
357 Qgis::WkbType overrideGeometryType = Qgis::WkbType::Unknown,
358 bool forceMulti = false,
359 bool includeZ = false,
360 const QgsAttributeList &attributes = QgsAttributeList(),
361 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = nullptr
362#ifndef SIP_RUN
363 , QString *newLayer = nullptr );
364#else
366#endif
367
368#ifndef SIP_RUN
369
397#else
398
425#endif
426 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( QgsVectorLayer *layer,
427 const QString &fileName,
428 const QString &fileEncoding,
429 const QgsCoordinateTransform &ct,
430 const QString &driverName = "GPKG",
431 bool onlySelected = false,
432 QString *errorMessage SIP_OUT = nullptr,
433 const QStringList &datasourceOptions = QStringList(),
434 const QStringList &layerOptions = QStringList(),
435 bool skipAttributeCreation = false,
436 QString *newFilename = nullptr,
438 double symbologyScale = 1.0,
439 const QgsRectangle *filterExtent = nullptr,
440 Qgis::WkbType overrideGeometryType = Qgis::WkbType::Unknown,
441 bool forceMulti = false,
442 bool includeZ = false,
443 const QgsAttributeList &attributes = QgsAttributeList(),
444 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter = nullptr
445#ifndef SIP_RUN
446 , QString *newLayer = nullptr );
447#else
449#endif
450
588
589#ifndef SIP_RUN
590
602#else
603
614#endif
616 const QString &fileName,
618 QString *newFilename = nullptr,
619 QString *errorMessage SIP_OUT = nullptr
620#ifndef SIP_RUN
621 , QString *newLayer = nullptr );
622#else
624#endif
625
630 Q_DECL_DEPRECATED QgsVectorFileWriter( const QString &vectorFileName,
631 const QString &fileEncoding,
632 const QgsFields &fields,
633 Qgis::WkbType geometryType,
635 const QString &driverName = "GPKG",
636 const QStringList &datasourceOptions = QStringList(),
637 const QStringList &layerOptions = QStringList(),
638 QString *newFilename = nullptr,
641#ifndef SIP_RUN
642 , QString *newLayer = nullptr,
644 FieldNameSource fieldNameSource = Original
645#endif
647
673 Q_DECL_DEPRECATED QgsVectorFileWriter( const QString &vectorFileName,
674 const QString &fileEncoding,
675 const QgsFields &fields,
676 Qgis::WkbType geometryType,
678 const QString &driverName,
679 const QStringList &datasourceOptions,
680 const QStringList &layerOptions,
681 QString *newFilename,
683 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter,
684 const QString &layerName,
686 QString *newLayer = nullptr,
689 FieldNameSource fieldNameSource = Original,
690 bool includeConstraints = false,
691 bool setFieldDomains = true,
692 const QgsAbstractDatabaseProviderConnection *sourceDatabaseProviderConnection = nullptr
693 ) SIP_SKIP;
694
696 QgsVectorFileWriter &operator=( const QgsVectorFileWriter &rh ) = delete;
697
711 static QgsVectorFileWriter *create( const QString &fileName,
712 const QgsFields &fields,
713 Qgis::WkbType geometryType,
715 const QgsCoordinateTransformContext &transformContext,
718 QString *newFilename = nullptr,
719 QString *newLayer = nullptr ) SIP_FACTORY;
720
734 const QString &fileName,
735 const QgsCoordinateTransformContext &transformContext,
737 QString *newFilename = nullptr,
738 QString *newLayer = nullptr,
739 QString *errorMessage SIP_OUT = nullptr ) SIP_DEPRECATED;
740
754 const QString &fileName,
755 const QgsCoordinateTransformContext &transformContext,
757 QString *errorMessage SIP_OUT = nullptr,
758 QString *newFilename SIP_OUT = nullptr,
759 QString *newLayer SIP_OUT = nullptr );
760
765 {
767 QString driverName;
768
771
776 QStringList globs;
777 };
778
787 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
788
797 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
798
805 static bool supportsFeatureStyles( const QString &driverName );
806
811 {
813 QString longName;
814
816 QString driverName;
817 };
818
830 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
831
837 static QString driverForExtension( const QString &extension );
838
845 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
846
848 static QString filterForDriver( const QString &driverName );
849
851 static QString convertCodecNameForEncodingOption( const QString &codecName );
852
855
857 QString errorMessage() const;
858
865 QString driver() const;
866
873 QString driverLongName() const;
874
881
882 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
883
885 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
886 QString lastError() const override;
887
892
898 QMap<int, int> sourceFieldIndexToWriterFieldIndex() const { return mAttrIdxToOgrIdx; }
899
901 ~QgsVectorFileWriter() override;
902
908 static bool deleteShapeFile( const QString &fileName );
909
916
923
929 double symbologyScale() const { return mSymbologyScale; }
930
936 void setSymbologyScale( double scale );
937
938 static bool driverMetadata( const QString &driverName, MetaData &driverMetadata );
939
945 static QStringList defaultDatasetOptions( const QString &driverName );
946
952 static QStringList defaultLayerOptions( const QString &driverName );
953
960 static OGRwkbGeometryType ogrTypeFromWkbType( Qgis::WkbType type ) SIP_SKIP;
961
965 static QgsVectorFileWriter::EditionCapabilities editionCapabilities( const QString &datasetName );
966
970 static bool targetLayerExists( const QString &datasetName,
971 const QString &layerName );
972
976 static bool areThereNewFieldsToCreate( const QString &datasetName,
977 const QString &layerName,
978 QgsVectorLayer *layer,
979 const QgsAttributeList &attributes );
980
981 protected:
983 OGRGeometryH createEmptyGeometry( Qgis::WkbType wkbType ) SIP_SKIP;
984
986 OGRLayerH mLayer = nullptr;
987 OGRSpatialReferenceH mOgrRef = nullptr;
988
990
994
995 QTextCodec *mCodec = nullptr;
996
999
1001 QMap<int, int> mAttrIdxToOgrIdx;
1002
1004
1005 QMap< QgsSymbolLayer *, QString > mSymbolLayerTable;
1006
1009
1012
1015
1018
1020 bool mSetFieldDomains = true;
1021
1022 private:
1023#ifdef SIP_RUN
1025#endif
1026
1027 struct PreparedWriterDetails
1028 {
1029 std::unique_ptr< QgsFeatureRenderer > renderer;
1031 Qgis::WkbType sourceWkbType = Qgis::WkbType::Unknown;
1032 QgsFields sourceFields;
1033 QString providerType;
1034 long long featureCount = 0;
1035 QgsFeatureIds selectedFeatureIds;
1036 QString dataSourceUri;
1037 QString storageType;
1038 QgsFeatureIterator geometryTypeScanIterator;
1039 QgsExpressionContext expressionContext;
1040 QSet< int > fieldsToConvertToInt;
1041 QgsRenderContext renderContext;
1042 bool shallTransform = false;
1045 QgsAttributeList attributes;
1046 QgsFields outputFields;
1047 QgsFeatureIterator sourceFeatureIterator;
1048 QgsGeometry filterRectGeometry;
1049 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1050 QVariantMap providerUriParams;
1051 std::unique_ptr< QgsAbstractDatabaseProviderConnection > sourceDatabaseProviderConnection;
1052 };
1053
1058 static QgsVectorFileWriter::WriterError prepareWriteAsVectorFormat( QgsVectorLayer *layer,
1060 PreparedWriterDetails &details );
1061
1076 static QgsVectorFileWriter::WriterError writeAsVectorFormatV2( PreparedWriterDetails &details,
1077 const QString &fileName,
1078 const QgsCoordinateTransformContext &transformContext,
1080 QString *newFilename = nullptr,
1081 QString *newLayer = nullptr,
1082 QString *errorMessage SIP_OUT = nullptr,
1084
1090 Q_DECL_DEPRECATED static QgsVectorFileWriter::WriterError writeAsVectorFormat( PreparedWriterDetails &details,
1091 const QString &fileName,
1093 QString *newFilename = nullptr,
1094 QString *errorMessage SIP_OUT = nullptr,
1095 QString *newLayer = nullptr ) SIP_DEPRECATED;
1096
1097 void init( QString vectorFileName, QString fileEncoding, const QgsFields &fields,
1098 Qgis::WkbType geometryType, QgsCoordinateReferenceSystem srs,
1099 const QString &driverName, QStringList datasourceOptions,
1100 QStringList layerOptions, QString *newFilename,
1101 QgsVectorFileWriter::FieldValueConverter *fieldValueConverter,
1102 const QString &layerName,
1103 QgsVectorFileWriter::ActionOnExistingFile action, QString *newLayer, QgsFeatureSink::SinkFlags sinkFlags,
1104 const QgsCoordinateTransformContext &transformContext,
1105 FieldNameSource fieldNameSource,
1106 const QgsAbstractDatabaseProviderConnection *sourceDatabaseProviderConnection );
1107 void resetMap( const QgsAttributeList &attributes );
1108
1109 std::unique_ptr< QgsFeatureRenderer > mRenderer;
1110 QgsRenderContext mRenderContext;
1111
1112
1113 std::unique_ptr< QgsCoordinateTransform > mCoordinateTransform;
1114
1115 bool mUsingTransaction = false;
1116 QSet< QMetaType::Type > mSupportedListSubTypes;
1117
1118 Qgis::VectorFileWriterCapabilities mCapabilities;
1119
1120 void createSymbolLayerTable( QgsVectorLayer *vl, const QgsCoordinateTransform &ct, OGRDataSourceH ds );
1121 gdal::ogr_feature_unique_ptr createFeature( const QgsFeature &feature );
1122 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1123
1125 QgsVectorFileWriter::WriterError exportFeaturesSymbolLevels( const PreparedWriterDetails &details, QgsFeatureIterator &fit, const QgsCoordinateTransform &ct, QString *errorMessage = nullptr );
1126 double mmScaleFactor( double scale, Qgis::RenderUnit symbolUnits, Qgis::DistanceUnit mapUnits );
1127 double mapUnitScaleFactor( double scale, Qgis::RenderUnit symbolUnits, Qgis::DistanceUnit mapUnits );
1128
1129 void startRender( QgsFeatureRenderer *sourceRenderer, const QgsFields &fields );
1130 void stopRender();
1131 std::unique_ptr< QgsFeatureRenderer > createSymbologyRenderer( QgsFeatureRenderer *sourceRenderer ) const;
1133 static void addRendererAttributes( QgsFeatureRenderer *renderer, QgsRenderContext &context, const QgsFields &fields, QgsAttributeList &attList );
1134
1136 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1137
1140};
1141
1144
1145// clazy:excludeall=qstring-allocations
1146
1147#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
DistanceUnit
Units of distance.
Definition qgis.h:5013
@ Meters
Meters.
Definition qgis.h:5014
QFlags< VectorFileWriterCapability > VectorFileWriterCapabilities
Capabilities supported by a QgsVectorFileWriter object.
Definition qgis.h:1083
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Unknown
Unknown.
Definition qgis.h:278
FeatureSymbologyExport
Options for exporting features considering their symbology.
Definition qgis.h:5557
@ NoSymbology
Export only data.
Definition qgis.h:5558
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:58
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:54
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:28
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,...