19 #ifndef QGSVECTORFILEWRITER_H
20 #define QGSVECTORFILEWRITER_H
22 #include "qgis_core.h"
63 : docString( docString )
65 virtual ~
Option() =
default;
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 );
240 CanAddNewLayer = 1 << 0,
243 CanAppendToExistingLayer = 1 << 1,
246 CanAddNewFieldsToExistingLayer = 1 << 2,
249 CanDeleteLayer = 1 << 3
255 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
273 AppendToLayerAddFields
331 const QString &fileName,
332 const QString &fileEncoding,
334 const QString &driverName =
"GPKG",
335 bool onlySelected =
false,
336 QString *errorMessage
SIP_OUT =
nullptr,
337 const QStringList &datasourceOptions = QStringList(),
338 const QStringList &layerOptions = QStringList(),
339 bool skipAttributeCreation =
false,
340 QString *newFilename =
nullptr,
342 double symbologyScale = 1.0,
345 bool forceMulti =
false,
346 bool includeZ =
false,
350 , QString *newLayer =
nullptr );
414 const QString &fileName,
415 const QString &fileEncoding,
417 const QString &driverName =
"GPKG",
418 bool onlySelected =
false,
419 QString *errorMessage
SIP_OUT =
nullptr,
420 const QStringList &datasourceOptions = QStringList(),
421 const QStringList &layerOptions = QStringList(),
422 bool skipAttributeCreation =
false,
423 QString *newFilename =
nullptr,
425 double symbologyScale = 1.0,
428 bool forceMulti =
false,
429 bool includeZ =
false,
433 , QString *newLayer =
nullptr );
469 bool onlySelectedFeatures =
false;
478 bool skipAttributeCreation =
false;
487 double symbologyScale = 1.0;
498 bool forceMulti =
false;
501 bool includeZ =
false;
542 const QString &fileName,
544 QString *newFilename =
nullptr,
545 QString *errorMessage
SIP_OUT =
nullptr
547 , QString *newLayer =
nullptr );
557 const QString &fileEncoding,
561 const QString &driverName =
"GPKG",
562 const QStringList &datasourceOptions = QStringList(),
563 const QStringList &layerOptions = QStringList(),
564 QString *newFilename =
nullptr,
566 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
568 , QString *newLayer =
nullptr,
595 const QString &fileEncoding,
599 const QString &driverName,
600 const QStringList &datasourceOptions,
601 const QStringList &layerOptions,
602 QString *newFilename,
605 const QString &layerName,
607 QString *newLayer =
nullptr,
609 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
637 QString *newFilename =
nullptr,
638 QString *newLayer =
nullptr );
653 const QString &fileName,
656 QString *newFilename =
nullptr,
657 QString *newLayer =
nullptr,
658 QString *errorMessage
SIP_OUT =
nullptr );
687 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
698 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
707 static bool supportsFeatureStyles(
const QString &driverName );
733 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
741 static QString driverForExtension(
const QString &extension );
749 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
752 static QString filterForDriver(
const QString &driverName );
755 static QString convertCodecNameForEncodingOption(
const QString &codecName );
761 QString errorMessage();
763 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
764 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
783 static bool deleteShapeFile(
const QString &fileName );
802 void setSymbologyScale(
double scale );
804 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
812 static QStringList defaultDatasetOptions(
const QString &driverName );
820 static QStringList defaultLayerOptions(
const QString &driverName );
834 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
840 static bool targetLayerExists(
const QString &datasetName,
841 const QString &layerName );
847 static bool areThereNewFieldsToCreate(
const QString &datasetName,
848 const QString &layerName,
857 OGRLayerH mLayer =
nullptr;
866 QTextCodec *mCodec =
nullptr;
891 struct PreparedWriterDetails
893 std::unique_ptr< QgsFeatureRenderer > renderer;
897 QString providerType;
898 long featureCount = 0;
900 QString dataSourceUri;
904 QSet< int > fieldsToConvertToInt;
906 bool shallTransform =
false;
913 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
914 QVariantMap providerUriParams;
923 PreparedWriterDetails &details );
939 const QString &fileName,
942 QString *newFilename =
nullptr,
943 QString *newLayer =
nullptr,
944 QString *errorMessage
SIP_OUT =
nullptr );
952 const QString &fileName,
954 QString *newFilename =
nullptr,
955 QString *errorMessage
SIP_OUT =
nullptr,
958 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
960 const QString &driverName, QStringList datasourceOptions,
961 QStringList layerOptions, QString *newFilename,
963 const QString &layerName,
974 bool mUsingTransaction = false;
975 bool supportsStringList = false;
979 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
984 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
993 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
996 friend class TestQgsVectorFileWriter;