19 #ifndef QGSVECTORFILEWRITER_H
20 #define QGSVECTORFILEWRITER_H
22 #include "qgis_core.h"
63 : docString( docString )
77 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
79 , values( qgis::listToSet( values ) )
80 , defaultValue( defaultValue )
81 , allowNone( allowNone )
95 StringOption(
const QString &docString,
const QString &defaultValue = QString() )
96 :
Option( docString, String )
97 , defaultValue( defaultValue )
110 :
Option( docString, Int )
111 , defaultValue( defaultValue )
124 :
SetOption( docString, QStringList() << QStringLiteral(
"YES" ) << QStringLiteral(
"NO" ), defaultValue ?
"YES" :
"NO" )
135 :
Option( QString(), Hidden )
147 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() )
148 : longName( longName )
149 , trLongName( trLongName )
152 , driverOptions( driverOptions )
153 , layerOptions( layerOptions )
154 , compulsoryEncoding( compulsoryEncoding )
195 SortRecommended = 1 << 1,
196 SkipNonSpatialFormats = 1 << 2,
198 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
226 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
241 CanAddNewLayer = 1 << 0,
244 CanAppendToExistingLayer = 1 << 1,
247 CanAddNewFieldsToExistingLayer = 1 << 2,
250 CanDeleteLayer = 1 << 3
257 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
275 AppendToLayerAddFields
333 const QString &fileName,
334 const QString &fileEncoding,
336 const QString &driverName =
"GPKG",
337 bool onlySelected =
false,
338 QString *errorMessage
SIP_OUT =
nullptr,
339 const QStringList &datasourceOptions = QStringList(),
340 const QStringList &layerOptions = QStringList(),
341 bool skipAttributeCreation =
false,
342 QString *newFilename =
nullptr,
344 double symbologyScale = 1.0,
347 bool forceMulti =
false,
348 bool includeZ =
false,
352 , 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 );
472 bool onlySelectedFeatures =
false;
481 bool skipAttributeCreation =
false;
490 double symbologyScale = 1.0;
502 bool forceMulti =
false;
505 bool includeZ =
false;
546 const QString &fileName,
548 QString *newFilename =
nullptr,
549 QString *errorMessage
SIP_OUT =
nullptr
551 , QString *newLayer =
nullptr );
561 const QString &fileEncoding,
565 const QString &driverName =
"GPKG",
566 const QStringList &datasourceOptions = QStringList(),
567 const QStringList &layerOptions = QStringList(),
568 QString *newFilename =
nullptr,
570 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
572 , QString *newLayer =
nullptr,
599 const QString &fileEncoding,
603 const QString &driverName,
604 const QStringList &datasourceOptions,
605 const QStringList &layerOptions,
606 QString *newFilename,
609 const QString &layerName,
611 QString *newLayer =
nullptr,
613 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
641 QString *newFilename =
nullptr,
657 const QString &fileName,
660 QString *newFilename =
nullptr,
661 QString *newLayer =
nullptr,
662 QString *errorMessage
SIP_OUT =
nullptr );
691 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
702 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
711 static bool supportsFeatureStyles(
const QString &driverName );
737 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
745 static QString driverForExtension(
const QString &extension );
753 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
756 static QString filterForDriver(
const QString &driverName );
759 static QString convertCodecNameForEncodingOption(
const QString &codecName );
765 QString errorMessage();
767 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
768 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
769 QString lastError()
const override;
788 static bool deleteShapeFile(
const QString &fileName );
807 void setSymbologyScale(
double scale );
809 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
817 static QStringList defaultDatasetOptions(
const QString &driverName );
825 static QStringList defaultLayerOptions(
const QString &driverName );
839 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
845 static bool targetLayerExists(
const QString &datasetName,
846 const QString &layerName );
852 static bool areThereNewFieldsToCreate(
const QString &datasetName,
853 const QString &layerName,
862 OGRLayerH mLayer =
nullptr;
871 QTextCodec *mCodec =
nullptr;
896 struct PreparedWriterDetails
898 std::unique_ptr< QgsFeatureRenderer > renderer;
902 QString providerType;
903 long featureCount = 0;
905 QString dataSourceUri;
909 QSet< int > fieldsToConvertToInt;
911 bool shallTransform =
false;
918 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
919 QVariantMap providerUriParams;
928 PreparedWriterDetails &details );
944 const QString &fileName,
947 QString *newFilename =
nullptr,
948 QString *newLayer =
nullptr,
949 QString *errorMessage
SIP_OUT =
nullptr );
957 const QString &fileName,
959 QString *newFilename =
nullptr,
960 QString *errorMessage
SIP_OUT =
nullptr,
963 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
965 const QString &driverName, QStringList datasourceOptions,
966 QStringList layerOptions, QString *newFilename,
968 const QString &layerName,
979 bool mUsingTransaction = false;
980 bool supportsStringList = false;
984 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
989 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
998 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1001 friend class TestQgsVectorFileWriter;