19#ifndef QGSVECTORFILEWRITER_H
20#define QGSVECTORFILEWRITER_H
66 : docString( docString )
81 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
83 , values( values.begin(), values.end() )
84 , defaultValue( defaultValue )
85 , allowNone( allowNone )
81 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false ) {
…}
100 StringOption(
const QString &docString,
const QString &defaultValue = QString() )
101 :
Option( docString, String )
102 , defaultValue( defaultValue )
100 StringOption(
const QString &docString,
const QString &defaultValue = QString() ) {
…}
116 :
Option( docString, Int )
117 , defaultValue( defaultValue )
131 :
SetOption( docString, QStringList() << QStringLiteral(
"YES" ) << QStringLiteral(
"NO" ), defaultValue ?
"YES" :
"NO" )
143 :
Option( QString(), Hidden )
155 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() )
156 : longName( longName )
157 , trLongName( trLongName )
160 , driverOptions( driverOptions )
161 , layerOptions( layerOptions )
162 , compulsoryEncoding( compulsoryEncoding )
155 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() ) {
…}
206 SortRecommended = 1 << 1,
207 SkipNonSpatialFormats = 1 << 2,
208 SupportsMultipleLayers = 1 << 3,
237 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
251 CanAddNewLayer = 1 << 0,
254 CanAppendToExistingLayer = 1 << 1,
257 CanAddNewFieldsToExistingLayer = 1 << 2,
260 CanDeleteLayer = 1 << 3
283 AppendToLayerAddFields
341 const QString &fileName,
342 const QString &fileEncoding,
344 const QString &driverName =
"GPKG",
345 bool onlySelected =
false,
346 QString *errorMessage
SIP_OUT =
nullptr,
347 const QStringList &datasourceOptions = QStringList(),
348 const QStringList &layerOptions = QStringList(),
349 bool skipAttributeCreation =
false,
350 QString *newFilename =
nullptr,
352 double symbologyScale = 1.0,
355 bool forceMulti =
false,
356 bool includeZ =
false,
360 , QString *newLayer =
nullptr );
422 const QString &fileName,
423 const QString &fileEncoding,
425 const QString &driverName =
"GPKG",
426 bool onlySelected =
false,
427 QString *errorMessage
SIP_OUT =
nullptr,
428 const QStringList &datasourceOptions = QStringList(),
429 const QStringList &layerOptions = QStringList(),
430 bool skipAttributeCreation =
false,
431 QString *newFilename =
nullptr,
433 double symbologyScale = 1.0,
436 bool forceMulti =
false,
437 bool includeZ =
false,
441 , QString *newLayer =
nullptr );
477 bool onlySelectedFeatures =
false;
486 bool skipAttributeCreation =
false;
498 double symbologyScale = 1.0;
510 bool forceMulti =
false;
513 bool includeZ =
false;
539 bool saveMetadata =
false;
556 bool includeConstraints =
false;
566 bool setFieldDomains =
true;
604 const QString &fileName,
606 QString *newFilename =
nullptr,
607 QString *errorMessage
SIP_OUT =
nullptr
609 , QString *newLayer =
nullptr );
619 const QString &fileEncoding,
623 const QString &driverName =
"GPKG",
624 const QStringList &datasourceOptions = QStringList(),
625 const QStringList &layerOptions = QStringList(),
626 QString *newFilename =
nullptr,
630 , QString *newLayer =
nullptr,
662 const QString &fileEncoding,
666 const QString &driverName,
667 const QStringList &datasourceOptions,
668 const QStringList &layerOptions,
669 QString *newFilename,
672 const QString &layerName,
674 QString *newLayer =
nullptr,
678 bool includeConstraints =
false,
679 bool setFieldDomains =
true,
701 Qgis::WkbType geometryType,
706 QString *newFilename =
nullptr,
722 const QString &fileName,
725 QString *newFilename =
nullptr,
726 QString *newLayer =
nullptr,
742 const QString &fileName,
745 QString *errorMessage
SIP_OUT =
nullptr,
746 QString *newFilename
SIP_OUT =
nullptr,
747 QString *newLayer
SIP_OUT =
nullptr );
775 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats(
VectorFormatOptions options = SortRecommended );
785 static QStringList supportedFormatExtensions(
VectorFormatOptions options = SortRecommended );
793 static bool supportsFeatureStyles(
const QString &driverName );
818 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(
VectorFormatOptions options = SortRecommended );
825 static QString driverForExtension(
const QString &extension );
836 static QString filterForDriver(
const QString &driverName );
839 static QString convertCodecNameForEncodingOption(
const QString &codecName );
845 QString errorMessage()
const;
853 QString driver()
const;
861 QString driverLongName()
const;
890 static bool deleteShapeFile(
const QString &fileName );
918 void setSymbologyScale(
double scale );
920 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
927 static QStringList defaultDatasetOptions(
const QString &driverName );
934 static QStringList defaultLayerOptions(
const QString &driverName );
952 static bool targetLayerExists(
const QString &datasetName,
953 const QString &layerName );
958 static bool areThereNewFieldsToCreate(
const QString &datasetName,
959 const QString &layerName,
968 OGRLayerH mLayer =
nullptr;
969 OGRSpatialReferenceH mOgrRef =
nullptr;
977 QTextCodec *mCodec =
nullptr;
999 bool mIncludeConstraints =
false;
1002 bool mSetFieldDomains =
true;
1009 struct PreparedWriterDetails
1011 std::unique_ptr< QgsFeatureRenderer > renderer;
1015 QString providerType;
1016 long long featureCount = 0;
1018 QString dataSourceUri;
1019 QString storageType;
1022 QSet< int > fieldsToConvertToInt;
1024 bool shallTransform =
false;
1031 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1032 QVariantMap providerUriParams;
1033 std::unique_ptr< QgsAbstractDatabaseProviderConnection > sourceDatabaseProviderConnection;
1042 PreparedWriterDetails &details );
1059 const QString &fileName,
1062 QString *newFilename =
nullptr,
1063 QString *newLayer =
nullptr,
1064 QString *errorMessage
SIP_OUT =
nullptr,
1073 const QString &fileName,
1075 QString *newFilename =
nullptr,
1076 QString *errorMessage
SIP_OUT =
nullptr,
1079 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1081 const QString &driverName, QStringList datasourceOptions,
1082 QStringList layerOptions, QString *newFilename,
1084 const QString &layerName,
1087 FieldNameSource fieldNameSource,
1097 bool mUsingTransaction = false;
1098 QSet< QMetaType::Type > mSupportedListSubTypes;
1100 Qgis::VectorFileWriterCapabilities mCapabilities;
1103 gdal::ogr_feature_unique_ptr createFeature( const
QgsFeature &feature );
1104 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1108 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1109 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1118 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1121 friend class TestQgsVectorFileWriter;
Provides global constants and enumerations for use throughout the application.
DistanceUnit
Units of distance.
QFlags< VectorFileWriterCapability > VectorFileWriterCapabilities
Capabilities supported by a QgsVectorFileWriter object.
WkbType
The WKB type describes the number of dimensions a geometry has.
FeatureSymbologyExport
Options for exporting features considering their symbology.
@ NoSymbology
Export only data.
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.
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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Abstract base class for symbol layers.
QgsTask task which performs a QgsVectorFileWriter layer saving operation as a background task.
An available option for configuring file writing for a particular output format, presenting an boolea...
BoolOption(const QString &docString, bool defaultValue)
Interface to convert raw field values to their user-friendly values.
FieldValueConverter()=default
virtual ~FieldValueConverter()=default
A hidden option for file writing for a particular output format.
HiddenOption(const QString &value)
An available option for configuring file writing for a particular output format, presenting an intege...
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().
QString fileEncoding
Encoding to use.
QString driverName
OGR driver to use.
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.
QStringList layerOptions
List of OGR layer creation options.
QgsAttributeList attributes
Attributes to export (empty means all unless skipAttributeCreation is set)
virtual ~SaveVectorOptions()=default
QStringList datasourceOptions
List of OGR data source creation options.
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)
An available option for configuring file writing for a particular output format, presenting a freefor...
StringOption(const QString &docString, const QString &defaultValue=QString())
A convenience class for writing vector layers to disk based formats (e.g.
EditionCapability
Edition capability flags.
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 > attrIdxToOgrIdx() const
QMap< int, int > mAttrIdxToOgrIdx
Map attribute indizes to OGR field indexes.
@ ErrAttributeTypeUnsupported
@ Canceled
Writing was interrupted by manual cancellation.
@ ErrAttributeCreationFailed
@ ErrSavingMetadata
Metadata saving failed.
gdal::ogr_datasource_unique_ptr mDS
QString mOgrDriverLongName
QFlags< EditionCapability > EditionCapabilities
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
double symbologyScale() const
Returns the reference scale for output.
VectorFormatOption
Options for sorting and filtering vector formats.
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.
void setSymbologyExport(Qgis::FeatureSymbologyExport symExport)
Sets the feature symbology export handling for the writer.
QMap< QgsSymbolLayer *, QString > mSymbolLayerTable
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.
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_ENUM_BASETYPE(type)
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & outputCrs
Details of available driver formats.
QString longName
Descriptive, user friendly name for the driver.
QString driverName
Unique driver name.