19 #ifndef QGSVECTORFILEWRITER_H
20 #define QGSVECTORFILEWRITER_H
22 #include "qgis_core.h"
65 : docString( docString )
67 virtual ~
Option() =
default;
79 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
81 , values( qgis::listToSet( values ) )
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 )
208 SortRecommended = 1 << 1,
209 SkipNonSpatialFormats = 1 << 2,
211 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
239 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
254 CanAddNewLayer = 1 << 0,
257 CanAppendToExistingLayer = 1 << 1,
260 CanAddNewFieldsToExistingLayer = 1 << 2,
263 CanDeleteLayer = 1 << 3
270 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
288 AppendToLayerAddFields
346 const QString &fileName,
347 const QString &fileEncoding,
349 const QString &driverName =
"GPKG",
350 bool onlySelected =
false,
351 QString *errorMessage
SIP_OUT =
nullptr,
352 const QStringList &datasourceOptions = QStringList(),
353 const QStringList &layerOptions = QStringList(),
354 bool skipAttributeCreation =
false,
355 QString *newFilename =
nullptr,
357 double symbologyScale = 1.0,
360 bool forceMulti =
false,
361 bool includeZ =
false,
365 , QString *newLayer =
nullptr );
429 const QString &fileName,
430 const QString &fileEncoding,
432 const QString &driverName =
"GPKG",
433 bool onlySelected =
false,
434 QString *errorMessage
SIP_OUT =
nullptr,
435 const QStringList &datasourceOptions = QStringList(),
436 const QStringList &layerOptions = QStringList(),
437 bool skipAttributeCreation =
false,
438 QString *newFilename =
nullptr,
440 double symbologyScale = 1.0,
443 bool forceMulti =
false,
444 bool includeZ =
false,
448 , QString *newLayer =
nullptr );
485 bool onlySelectedFeatures =
false;
494 bool skipAttributeCreation =
false;
506 double symbologyScale = 1.0;
518 bool forceMulti =
false;
521 bool includeZ =
false;
547 bool saveMetadata =
false;
585 const QString &fileName,
587 QString *newFilename =
nullptr,
588 QString *errorMessage
SIP_OUT =
nullptr
590 , QString *newLayer =
nullptr );
600 const QString &fileEncoding,
604 const QString &driverName =
"GPKG",
605 const QStringList &datasourceOptions = QStringList(),
606 const QStringList &layerOptions = QStringList(),
607 QString *newFilename =
nullptr,
609 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
611 , QString *newLayer =
nullptr,
640 const QString &fileEncoding,
644 const QString &driverName,
645 const QStringList &datasourceOptions,
646 const QStringList &layerOptions,
647 QString *newFilename,
650 const QString &layerName,
652 QString *newLayer =
nullptr,
654 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
682 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
683 QString *newFilename =
nullptr,
699 const QString &fileName,
702 QString *newFilename =
nullptr,
703 QString *newLayer =
nullptr,
719 const QString &fileName,
722 QString *errorMessage
SIP_OUT =
nullptr,
723 QString *newFilename
SIP_OUT =
nullptr,
724 QString *newLayer
SIP_OUT =
nullptr );
753 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
764 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
773 static bool supportsFeatureStyles(
const QString &driverName );
799 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
807 static QString driverForExtension(
const QString &extension );
815 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
818 static QString filterForDriver(
const QString &driverName );
821 static QString convertCodecNameForEncodingOption(
const QString &codecName );
827 QString errorMessage()
const;
829 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
830 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
831 QString lastError()
const override;
850 static bool deleteShapeFile(
const QString &fileName );
869 void setSymbologyScale(
double scale );
871 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
879 static QStringList defaultDatasetOptions(
const QString &driverName );
887 static QStringList defaultLayerOptions(
const QString &driverName );
901 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
907 static bool targetLayerExists(
const QString &datasetName,
908 const QString &layerName );
914 static bool areThereNewFieldsToCreate(
const QString &datasetName,
915 const QString &layerName,
924 OGRLayerH mLayer =
nullptr;
933 QTextCodec *mCodec =
nullptr;
958 struct PreparedWriterDetails
960 std::unique_ptr< QgsFeatureRenderer > renderer;
964 QString providerType;
965 long long featureCount = 0;
967 QString dataSourceUri;
971 QSet< int > fieldsToConvertToInt;
973 bool shallTransform =
false;
980 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
981 QVariantMap providerUriParams;
990 PreparedWriterDetails &details );
1006 const QString &fileName,
1009 QString *newFilename =
nullptr,
1010 QString *newLayer =
nullptr,
1011 QString *errorMessage
SIP_OUT =
nullptr );
1019 const QString &fileName,
1021 QString *newFilename =
nullptr,
1022 QString *errorMessage
SIP_OUT =
nullptr,
1025 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1027 const QString &driverName, QStringList datasourceOptions,
1028 QStringList layerOptions, QString *newFilename,
1030 const QString &layerName,
1033 FieldNameSource fieldNameSource );
1042 bool mUsingTransaction = false;
1043 QSet< QVariant::Type > mSupportedListSubTypes;
1047 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1052 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
1061 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1064 friend class TestQgsVectorFileWriter;