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;
578 const QString &fileName,
580 QString *newFilename =
nullptr,
581 QString *errorMessage
SIP_OUT =
nullptr
583 , QString *newLayer =
nullptr );
593 const QString &fileEncoding,
597 const QString &driverName =
"GPKG",
598 const QStringList &datasourceOptions = QStringList(),
599 const QStringList &layerOptions = QStringList(),
600 QString *newFilename =
nullptr,
602 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
604 , QString *newLayer =
nullptr,
633 const QString &fileEncoding,
637 const QString &driverName,
638 const QStringList &datasourceOptions,
639 const QStringList &layerOptions,
640 QString *newFilename,
643 const QString &layerName,
645 QString *newLayer =
nullptr,
647 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
675 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
676 QString *newFilename =
nullptr,
692 const QString &fileName,
695 QString *newFilename =
nullptr,
696 QString *newLayer =
nullptr,
712 const QString &fileName,
715 QString *errorMessage
SIP_OUT =
nullptr,
716 QString *newFilename
SIP_OUT =
nullptr,
717 QString *newLayer
SIP_OUT =
nullptr );
746 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
757 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
766 static bool supportsFeatureStyles(
const QString &driverName );
792 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
800 static QString driverForExtension(
const QString &extension );
808 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
811 static QString filterForDriver(
const QString &driverName );
814 static QString convertCodecNameForEncodingOption(
const QString &codecName );
820 QString errorMessage()
const;
828 QString driver()
const;
836 QString driverLongName()
const;
843 Qgis::VectorFileWriterCapabilities capabilities()
const;
845 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
866 static bool deleteShapeFile(
const QString &fileName );
896 void setSymbologyScale(
double scale );
898 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
906 static QStringList defaultDatasetOptions(
const QString &driverName );
914 static QStringList defaultLayerOptions(
const QString &driverName );
928 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
934 static bool targetLayerExists(
const QString &datasetName,
935 const QString &layerName );
941 static bool areThereNewFieldsToCreate(
const QString &datasetName,
942 const QString &layerName,
951 OGRLayerH mLayer =
nullptr;
960 QTextCodec *mCodec =
nullptr;
986 struct PreparedWriterDetails
988 std::unique_ptr< QgsFeatureRenderer > renderer;
992 QString providerType;
993 long long featureCount = 0;
995 QString dataSourceUri;
999 QSet< int > fieldsToConvertToInt;
1001 bool shallTransform =
false;
1008 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1009 QVariantMap providerUriParams;
1018 PreparedWriterDetails &details );
1034 const QString &fileName,
1037 QString *newFilename =
nullptr,
1038 QString *newLayer =
nullptr,
1039 QString *errorMessage
SIP_OUT =
nullptr );
1047 const QString &fileName,
1049 QString *newFilename =
nullptr,
1050 QString *errorMessage
SIP_OUT =
nullptr,
1053 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1055 const QString &driverName, QStringList datasourceOptions,
1056 QStringList layerOptions, QString *newFilename,
1058 const QString &layerName,
1061 FieldNameSource fieldNameSource );
1070 bool mUsingTransaction = false;
1071 QSet< QVariant::Type > mSupportedListSubTypes;
1073 Qgis::VectorFileWriterCapabilities mCapabilities;
1077 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1081 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1082 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1091 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1094 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
QgsVectorFileWriter & operator=(const QgsVectorFileWriter &rh)=delete
QgsVectorFileWriter cannot be copied.
QString mOgrDriverLongName
QgsVectorFileWriter(const QgsVectorFileWriter &rh)=delete
QgsVectorFileWriter cannot be copied.
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< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
void * OGRSpatialReferenceH
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
const QgsCoordinateReferenceSystem & outputCrs
Details of available driver formats.
QString longName
Descriptive, user friendly name for the driver.
QString driverName
Unique driver name.