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 )
207 SortRecommended = 1 << 1,
208 SkipNonSpatialFormats = 1 << 2,
210 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
238 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
253 CanAddNewLayer = 1 << 0,
256 CanAppendToExistingLayer = 1 << 1,
259 CanAddNewFieldsToExistingLayer = 1 << 2,
262 CanDeleteLayer = 1 << 3
269 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
287 AppendToLayerAddFields
345 const QString &fileName,
346 const QString &fileEncoding,
348 const QString &driverName =
"GPKG",
349 bool onlySelected =
false,
350 QString *errorMessage
SIP_OUT =
nullptr,
351 const QStringList &datasourceOptions = QStringList(),
352 const QStringList &layerOptions = QStringList(),
353 bool skipAttributeCreation =
false,
354 QString *newFilename =
nullptr,
356 double symbologyScale = 1.0,
359 bool forceMulti =
false,
360 bool includeZ =
false,
364 , QString *newLayer =
nullptr );
428 const QString &fileName,
429 const QString &fileEncoding,
431 const QString &driverName =
"GPKG",
432 bool onlySelected =
false,
433 QString *errorMessage
SIP_OUT =
nullptr,
434 const QStringList &datasourceOptions = QStringList(),
435 const QStringList &layerOptions = QStringList(),
436 bool skipAttributeCreation =
false,
437 QString *newFilename =
nullptr,
439 double symbologyScale = 1.0,
442 bool forceMulti =
false,
443 bool includeZ =
false,
447 , QString *newLayer =
nullptr );
484 bool onlySelectedFeatures =
false;
493 bool skipAttributeCreation =
false;
505 double symbologyScale = 1.0;
517 bool forceMulti =
false;
520 bool includeZ =
false;
546 bool saveMetadata =
false;
584 const QString &fileName,
586 QString *newFilename =
nullptr,
587 QString *errorMessage
SIP_OUT =
nullptr
589 , QString *newLayer =
nullptr );
599 const QString &fileEncoding,
603 const QString &driverName =
"GPKG",
604 const QStringList &datasourceOptions = QStringList(),
605 const QStringList &layerOptions = QStringList(),
606 QString *newFilename =
nullptr,
608 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
610 , QString *newLayer =
nullptr,
639 const QString &fileEncoding,
643 const QString &driverName,
644 const QStringList &datasourceOptions,
645 const QStringList &layerOptions,
646 QString *newFilename,
649 const QString &layerName,
651 QString *newLayer =
nullptr,
653 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
681 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
682 QString *newFilename =
nullptr,
698 const QString &fileName,
701 QString *newFilename =
nullptr,
702 QString *newLayer =
nullptr,
718 const QString &fileName,
721 QString *errorMessage
SIP_OUT =
nullptr,
722 QString *newFilename
SIP_OUT =
nullptr,
723 QString *newLayer
SIP_OUT =
nullptr );
752 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
763 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
772 static bool supportsFeatureStyles(
const QString &driverName );
798 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
806 static QString driverForExtension(
const QString &extension );
814 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
817 static QString filterForDriver(
const QString &driverName );
820 static QString convertCodecNameForEncodingOption(
const QString &codecName );
826 QString errorMessage()
const;
828 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
849 static bool deleteShapeFile(
const QString &fileName );
868 void setSymbologyScale(
double scale );
870 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
878 static QStringList defaultDatasetOptions(
const QString &driverName );
886 static QStringList defaultLayerOptions(
const QString &driverName );
900 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
906 static bool targetLayerExists(
const QString &datasetName,
907 const QString &layerName );
913 static bool areThereNewFieldsToCreate(
const QString &datasetName,
914 const QString &layerName,
923 OGRLayerH mLayer =
nullptr;
932 QTextCodec *mCodec =
nullptr;
957 struct PreparedWriterDetails
959 std::unique_ptr< QgsFeatureRenderer > renderer;
963 QString providerType;
964 long long featureCount = 0;
966 QString dataSourceUri;
970 QSet< int > fieldsToConvertToInt;
972 bool shallTransform =
false;
979 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
980 QVariantMap providerUriParams;
989 PreparedWriterDetails &details );
1005 const QString &fileName,
1008 QString *newFilename =
nullptr,
1009 QString *newLayer =
nullptr,
1010 QString *errorMessage
SIP_OUT =
nullptr );
1018 const QString &fileName,
1020 QString *newFilename =
nullptr,
1021 QString *errorMessage
SIP_OUT =
nullptr,
1024 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1026 const QString &driverName, QStringList datasourceOptions,
1027 QStringList layerOptions, QString *newFilename,
1029 const QString &layerName,
1032 FieldNameSource fieldNameSource );
1041 bool mUsingTransaction = false;
1042 QSet< QVariant::Type > mSupportedListSubTypes;
1046 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1050 double mmScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1051 double mapUnitScaleFactor(
double scale,
Qgis::RenderUnit symbolUnits,
Qgis::DistanceUnit mapUnits );
1060 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1063 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.
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.
QgsVectorFileWriter(const QgsVectorFileWriter &rh)=delete
QgsVectorFileWriter cannot be copied.
double symbologyScale() const
Returns the reference scale for output.
SymbologyExport mSymbologyExport
VectorFormatOption
Options for sorting and filtering vector formats.
void setSymbologyExport(QgsVectorFileWriter::SymbologyExport symExport)
WriterError mError
Contains error value if construction was not successful.
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...
QgsVectorFileWriter::SymbologyExport symbologyExport() const
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.