19#ifndef QGSVECTORFILEWRITER_H
20#define QGSVECTORFILEWRITER_H
65 : docString( docString )
79 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
81 , values( values.begin(), values.end() )
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 )
200 SortRecommended = 1 << 1,
201 SkipNonSpatialFormats = 1 << 2,
202 SupportsMultipleLayers = 1 << 3,
231 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
245 CanAddNewLayer = 1 << 0,
248 CanAppendToExistingLayer = 1 << 1,
251 CanAddNewFieldsToExistingLayer = 1 << 2,
254 CanDeleteLayer = 1 << 3
277 AppendToLayerAddFields
335 const QString &fileName,
336 const QString &fileEncoding,
338 const QString &driverName =
"GPKG",
339 bool onlySelected =
false,
340 QString *errorMessage
SIP_OUT =
nullptr,
341 const QStringList &datasourceOptions = QStringList(),
342 const QStringList &layerOptions = QStringList(),
343 bool skipAttributeCreation =
false,
344 QString *newFilename =
nullptr,
346 double symbologyScale = 1.0,
349 bool forceMulti =
false,
350 bool includeZ =
false,
354 , 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 );
471 bool onlySelectedFeatures =
false;
480 bool skipAttributeCreation =
false;
492 double symbologyScale = 1.0;
504 bool forceMulti =
false;
507 bool includeZ =
false;
533 bool saveMetadata =
false;
550 bool includeConstraints =
false;
560 bool setFieldDomains =
true;
598 const QString &fileName,
600 QString *newFilename =
nullptr,
601 QString *errorMessage
SIP_OUT =
nullptr
603 , QString *newLayer =
nullptr );
613 const QString &fileEncoding,
617 const QString &driverName =
"GPKG",
618 const QStringList &datasourceOptions = QStringList(),
619 const QStringList &layerOptions = QStringList(),
620 QString *newFilename =
nullptr,
624 , QString *newLayer =
nullptr,
656 const QString &fileEncoding,
660 const QString &driverName,
661 const QStringList &datasourceOptions,
662 const QStringList &layerOptions,
663 QString *newFilename,
666 const QString &layerName,
668 QString *newLayer =
nullptr,
672 bool includeConstraints =
false,
673 bool setFieldDomains =
true,
695 Qgis::WkbType geometryType,
700 QString *newFilename =
nullptr,
716 const QString &fileName,
719 QString *newFilename =
nullptr,
720 QString *newLayer =
nullptr,
736 const QString &fileName,
739 QString *errorMessage
SIP_OUT =
nullptr,
740 QString *newFilename
SIP_OUT =
nullptr,
741 QString *newLayer
SIP_OUT =
nullptr );
769 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats(
VectorFormatOptions options = SortRecommended );
779 static QStringList supportedFormatExtensions(
VectorFormatOptions options = SortRecommended );
787 static bool supportsFeatureStyles(
const QString &driverName );
812 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList(
VectorFormatOptions options = SortRecommended );
819 static QString driverForExtension(
const QString &extension );
830 static QString filterForDriver(
const QString &driverName );
833 static QString convertCodecNameForEncodingOption(
const QString &codecName );
839 QString errorMessage()
const;
847 QString driver()
const;
855 QString driverLongName()
const;
884 static bool deleteShapeFile(
const QString &fileName );
912 void setSymbologyScale(
double scale );
914 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
921 static QStringList defaultDatasetOptions(
const QString &driverName );
928 static QStringList defaultLayerOptions(
const QString &driverName );
946 static bool targetLayerExists(
const QString &datasetName,
947 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;
996 bool mSetFieldDomains =
true;
1003 struct PreparedWriterDetails
1005 std::unique_ptr< QgsFeatureRenderer > renderer;
1009 QString providerType;
1010 long long featureCount = 0;
1012 QString dataSourceUri;
1013 QString storageType;
1016 QSet< int > fieldsToConvertToInt;
1018 bool shallTransform =
false;
1025 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
1026 QVariantMap providerUriParams;
1027 std::unique_ptr< QgsAbstractDatabaseProviderConnection > sourceDatabaseProviderConnection;
1036 PreparedWriterDetails &details );
1053 const QString &fileName,
1056 QString *newFilename =
nullptr,
1057 QString *newLayer =
nullptr,
1058 QString *errorMessage
SIP_OUT =
nullptr,
1067 const QString &fileName,
1069 QString *newFilename =
nullptr,
1070 QString *errorMessage
SIP_OUT =
nullptr,
1073 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1075 const QString &driverName, QStringList datasourceOptions,
1076 QStringList layerOptions, QString *newFilename,
1078 const QString &layerName,
1081 FieldNameSource fieldNameSource,
1091 bool mUsingTransaction = false;
1092 QSet< QMetaType::Type > mSupportedListSubTypes;
1094 Qgis::VectorFileWriterCapabilities mCapabilities;
1097 gdal::ogr_feature_unique_ptr createFeature( const
QgsFeature &feature );
1098 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1102 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1103 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1112 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1115 friend class TestQgsVectorFileWriter;
The Qgis class provides global constants for use throughout the application.
DistanceUnit
Units of distance.
QFlags< VectorFileWriterCapability > VectorFileWriterCapabilities
Capabilities supported by a QgsVectorFileWriter object.
WkbType
The WKB type describes the number of dimensions a geometry has.
FeatureSymbologyExport
Options for exporting features considering their symbology.
@ NoSymbology
Export only data.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
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.
Abstract base class for all 2D vector feature renderers.
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
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
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
QFlags< EditionCapability > EditionCapabilities
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
double symbologyScale() const
Returns the reference scale for output.
VectorFormatOption
Options for sorting and filtering vector formats.
QFlags< VectorFormatOption > VectorFormatOptions
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
Enumeration to describe how to handle existing files.
@ 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.
#define SIP_ENUM_BASETYPE(type)
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.