19#ifndef QGSVECTORFILEWRITER_H
20#define QGSVECTORFILEWRITER_H
65 : docString( docString )
79 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
81 , values( values.begin(), values.end() )
82 , defaultValue( defaultValue )
83 , allowNone( allowNone )
97 StringOption(
const QString &docString,
const QString &defaultValue = QString() )
98 :
Option( docString, String )
99 , defaultValue( defaultValue )
112 :
Option( docString, Int )
113 , defaultValue( defaultValue )
126 :
SetOption( docString, QStringList() << QStringLiteral(
"YES" ) << QStringLiteral(
"NO" ), defaultValue ?
"YES" :
"NO" )
137 :
Option( QString(), Hidden )
149 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() )
150 : longName( longName )
151 , trLongName( trLongName )
154 , driverOptions( driverOptions )
155 , layerOptions( layerOptions )
156 , compulsoryEncoding( compulsoryEncoding )
200 SortRecommended = 1 << 1,
201 SkipNonSpatialFormats = 1 << 2,
202 SupportsMultipleLayers = 1 << 3,
231 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
245 CanAddNewLayer = 1 << 0,
248 CanAppendToExistingLayer = 1 << 1,
251 CanAddNewFieldsToExistingLayer = 1 << 2,
254 CanDeleteLayer = 1 << 3
277 AppendToLayerAddFields
335 const QString &fileName,
336 const QString &fileEncoding,
338 const QString &driverName =
"GPKG",
339 bool onlySelected =
false,
340 QString *errorMessage
SIP_OUT =
nullptr,
341 const QStringList &datasourceOptions = QStringList(),
342 const QStringList &layerOptions = QStringList(),
343 bool skipAttributeCreation =
false,
344 QString *newFilename =
nullptr,
346 double symbologyScale = 1.0,
349 bool forceMulti =
false,
350 bool includeZ =
false,
354 , QString *newLayer =
nullptr );
416 const QString &fileName,
417 const QString &fileEncoding,
419 const QString &driverName =
"GPKG",
420 bool onlySelected =
false,
421 QString *errorMessage
SIP_OUT =
nullptr,
422 const QStringList &datasourceOptions = QStringList(),
423 const QStringList &layerOptions = QStringList(),
424 bool skipAttributeCreation =
false,
425 QString *newFilename =
nullptr,
427 double symbologyScale = 1.0,
430 bool forceMulti =
false,
431 bool includeZ =
false,
435 , QString *newLayer =
nullptr );
471 bool onlySelectedFeatures =
false;
480 bool skipAttributeCreation =
false;
492 double symbologyScale = 1.0;
504 bool forceMulti =
false;
507 bool includeZ =
false;
533 bool saveMetadata =
false;
550 bool includeConstraints =
false;
560 bool setFieldDomains =
true;
598 const QString &fileName,
600 QString *newFilename =
nullptr,
601 QString *errorMessage
SIP_OUT =
nullptr
603 , QString *newLayer =
nullptr );
613 const QString &fileEncoding,
617 const QString &driverName =
"GPKG",
618 const QStringList &datasourceOptions = QStringList(),
619 const QStringList &layerOptions = QStringList(),
620 QString *newFilename =
nullptr,
624 , QString *newLayer =
nullptr,
656 const QString &fileEncoding,
660 const QString &driverName,
661 const QStringList &datasourceOptions,
662 const QStringList &layerOptions,
663 QString *newFilename,
666 const QString &layerName,
668 QString *newLayer =
nullptr,
672 bool includeConstraints =
false,
673 bool setFieldDomains =
true,
697 Qgis::WkbType geometryType,
702 QString *newFilename =
nullptr,
718 const QString &fileName,
721 QString *newFilename =
nullptr,
722 QString *newLayer =
nullptr,
738 const QString &fileName,
741 QString *errorMessage
SIP_OUT =
nullptr,
742 QString *newFilename
SIP_OUT =
nullptr,
743 QString *newLayer
SIP_OUT =
nullptr );
771 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats(
VectorFormatOptions options = SortRecommended );
781 static QStringList supportedFormatExtensions(
VectorFormatOptions options = SortRecommended );
789 static bool supportsFeatureStyles(
const QString &driverName );
814 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(
VectorFormatOptions options = SortRecommended );
821 static QString driverForExtension(
const QString &extension );
832 static QString filterForDriver(
const QString &driverName );
835 static QString convertCodecNameForEncodingOption(
const QString &codecName );
841 QString errorMessage()
const;
849 QString driver()
const;
857 QString driverLongName()
const;
886 static bool deleteShapeFile(
const QString &fileName );
914 void setSymbologyScale(
double scale );
916 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
923 static QStringList defaultDatasetOptions(
const QString &driverName );
930 static QStringList defaultLayerOptions(
const QString &driverName );
948 static bool targetLayerExists(
const QString &datasetName,
949 const QString &layerName );
954 static bool areThereNewFieldsToCreate(
const QString &datasetName,
955 const QString &layerName,
964 OGRLayerH mLayer =
nullptr;
973 QTextCodec *mCodec =
nullptr;
995 bool mIncludeConstraints =
false;
998 bool mSetFieldDomains =
true;
1005 struct PreparedWriterDetails
1007 std::unique_ptr< QgsFeatureRenderer > renderer;
1011 QString providerType;
1012 long long featureCount = 0;
1014 QString dataSourceUri;
1015 QString storageType;
1018 QSet< int > fieldsToConvertToInt;
1020 bool shallTransform =
false;
1027 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1028 QVariantMap providerUriParams;
1029 std::unique_ptr< QgsAbstractDatabaseProviderConnection > sourceDatabaseProviderConnection;
1038 PreparedWriterDetails &details );
1054 const QString &fileName,
1057 QString *newFilename =
nullptr,
1058 QString *newLayer =
nullptr,
1059 QString *errorMessage
SIP_OUT =
nullptr );
1067 const QString &fileName,
1069 QString *newFilename =
nullptr,
1070 QString *errorMessage
SIP_OUT =
nullptr,
1073 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1075 const QString &driverName, QStringList datasourceOptions,
1076 QStringList layerOptions, QString *newFilename,
1078 const QString &layerName,
1081 FieldNameSource fieldNameSource,
1091 bool mUsingTransaction = false;
1092 QSet< QMetaType::Type > mSupportedListSubTypes;
1094 Qgis::VectorFileWriterCapabilities mCapabilities;
1097 gdal::ogr_feature_unique_ptr createFeature( const
QgsFeature &feature );
1098 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1102 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1103 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1112 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1115 friend class TestQgsVectorFileWriter;
The Qgis class provides global constants 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.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
This class 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.
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.
QgsTask task which performs a QgsVectorFileWriter layer saving operation as a background task.
BoolOption(const QString &docString, bool defaultValue)
Interface to convert raw field values to their user-friendly value.
FieldValueConverter()=default
Constructor.
virtual ~FieldValueConverter()=default
HiddenOption(const QString &value)
IntOption(const QString &docString, int defaultValue)
Option(const QString &docString, QgsVectorFileWriter::OptionType type)
QgsVectorFileWriter::OptionType type
virtual ~Option()=default
Options to pass to 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.
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.
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...
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 data sets.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
#define SIP_ENUM_BASETYPE(type)
void * OGRSpatialReferenceH
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.