19#ifndef QGSVECTORFILEWRITER_H
20#define QGSVECTORFILEWRITER_H
64 : docString( docString )
78 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
80 , values( values.begin(), values.end() )
81 , defaultValue( defaultValue )
82 , allowNone( allowNone )
96 StringOption(
const QString &docString,
const QString &defaultValue = QString() )
97 :
Option( docString, String )
98 , defaultValue( defaultValue )
111 :
Option( docString, Int )
112 , defaultValue( defaultValue )
125 :
SetOption( docString, QStringList() << QStringLiteral(
"YES" ) << QStringLiteral(
"NO" ), defaultValue ?
"YES" :
"NO" )
136 :
Option( QString(), Hidden )
148 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() )
149 : longName( longName )
150 , trLongName( trLongName )
153 , driverOptions( driverOptions )
154 , layerOptions( layerOptions )
155 , compulsoryEncoding( compulsoryEncoding )
200 SortRecommended = 1 << 1,
201 SkipNonSpatialFormats = 1 << 2,
202 SupportsMultipleLayers = 1 << 3,
204 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
232 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
247 CanAddNewLayer = 1 << 0,
250 CanAppendToExistingLayer = 1 << 1,
253 CanAddNewFieldsToExistingLayer = 1 << 2,
256 CanDeleteLayer = 1 << 3
263 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
281 AppendToLayerAddFields
339 const QString &fileName,
340 const QString &fileEncoding,
342 const QString &driverName =
"GPKG",
343 bool onlySelected =
false,
344 QString *errorMessage
SIP_OUT =
nullptr,
345 const QStringList &datasourceOptions = QStringList(),
346 const QStringList &layerOptions = QStringList(),
347 bool skipAttributeCreation =
false,
348 QString *newFilename =
nullptr,
350 double symbologyScale = 1.0,
353 bool forceMulti =
false,
354 bool includeZ =
false,
358 , 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 );
478 bool onlySelectedFeatures =
false;
487 bool skipAttributeCreation =
false;
499 double symbologyScale = 1.0;
511 bool forceMulti =
false;
514 bool includeZ =
false;
540 bool saveMetadata =
false;
557 bool includeConstraints =
false;
587 const QString &fileName,
589 QString *newFilename =
nullptr,
590 QString *errorMessage
SIP_OUT =
nullptr
592 , QString *newLayer =
nullptr );
602 const QString &fileEncoding,
606 const QString &driverName =
"GPKG",
607 const QStringList &datasourceOptions = QStringList(),
608 const QStringList &layerOptions = QStringList(),
609 QString *newFilename =
nullptr,
611 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
613 , QString *newLayer =
nullptr,
643 const QString &fileEncoding,
647 const QString &driverName,
648 const QStringList &datasourceOptions,
649 const QStringList &layerOptions,
650 QString *newFilename,
653 const QString &layerName,
655 QString *newLayer =
nullptr,
657 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
659 bool includeConstraints =
false
682 Qgis::WkbType geometryType,
687 QString *newFilename =
nullptr,
703 const QString &fileName,
706 QString *newFilename =
nullptr,
707 QString *newLayer =
nullptr,
723 const QString &fileName,
726 QString *errorMessage
SIP_OUT =
nullptr,
727 QString *newFilename
SIP_OUT =
nullptr,
728 QString *newLayer
SIP_OUT =
nullptr );
757 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
768 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
777 static bool supportsFeatureStyles(
const QString &driverName );
803 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
811 static QString driverForExtension(
const QString &extension );
819 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
822 static QString filterForDriver(
const QString &driverName );
825 static QString convertCodecNameForEncodingOption(
const QString &codecName );
831 QString errorMessage()
const;
839 QString driver()
const;
847 QString driverLongName()
const;
854 Qgis::VectorFileWriterCapabilities capabilities()
const;
856 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
877 static bool deleteShapeFile(
const QString &fileName );
907 void setSymbologyScale(
double scale );
909 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
917 static QStringList defaultDatasetOptions(
const QString &driverName );
925 static QStringList defaultLayerOptions(
const QString &driverName );
939 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
945 static bool targetLayerExists(
const QString &datasetName,
946 const QString &layerName );
952 static bool areThereNewFieldsToCreate(
const QString &datasetName,
953 const QString &layerName,
962 OGRLayerH mLayer =
nullptr;
971 QTextCodec *mCodec =
nullptr;
993 bool mIncludeConstraints =
false;
1000 struct PreparedWriterDetails
1002 std::unique_ptr< QgsFeatureRenderer > renderer;
1006 QString providerType;
1007 long long featureCount = 0;
1009 QString dataSourceUri;
1010 QString storageType;
1013 QSet< int > fieldsToConvertToInt;
1015 bool shallTransform =
false;
1022 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1023 QVariantMap providerUriParams;
1032 PreparedWriterDetails &details );
1048 const QString &fileName,
1051 QString *newFilename =
nullptr,
1052 QString *newLayer =
nullptr,
1053 QString *errorMessage
SIP_OUT =
nullptr );
1061 const QString &fileName,
1063 QString *newFilename =
nullptr,
1064 QString *errorMessage
SIP_OUT =
nullptr,
1067 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1069 const QString &driverName, QStringList datasourceOptions,
1070 QStringList layerOptions, QString *newFilename,
1072 const QString &layerName,
1075 FieldNameSource fieldNameSource );
1084 bool mUsingTransaction = false;
1085 QSet< QVariant::Type > mSupportedListSubTypes;
1087 Qgis::VectorFileWriterCapabilities mCapabilities;
1090 gdal::ogr_feature_unique_ptr createFeature( const
QgsFeature &feature );
1091 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1095 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1096 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1105 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1108 friend class TestQgsVectorFileWriter;
The Qgis class provides global constants for use throughout the application.
DistanceUnit
Units of distance.
WkbType
The WKB type describes the number of dimensions a geometry has.
FeatureSymbologyExport
Options for exporting features considering their symbology.
@ NoSymbology
Export only data.
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.
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
double symbologyScale() const
Returns the reference scale for output.
VectorFormatOption
Options for sorting and filtering vector formats.
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
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
@ 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.
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.