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 )
208 SortRecommended = 1 << 1,
209 SkipNonSpatialFormats = 1 << 2,
211 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
239 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
254 CanAddNewLayer = 1 << 0,
257 CanAppendToExistingLayer = 1 << 1,
260 CanAddNewFieldsToExistingLayer = 1 << 2,
263 CanDeleteLayer = 1 << 3
270 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
288 AppendToLayerAddFields
346 const QString &fileName,
347 const QString &fileEncoding,
349 const QString &driverName =
"GPKG",
350 bool onlySelected =
false,
351 QString *errorMessage
SIP_OUT =
nullptr,
352 const QStringList &datasourceOptions = QStringList(),
353 const QStringList &layerOptions = QStringList(),
354 bool skipAttributeCreation =
false,
355 QString *newFilename =
nullptr,
357 double symbologyScale = 1.0,
360 bool forceMulti =
false,
361 bool includeZ =
false,
365 , QString *newLayer =
nullptr );
429 const QString &fileName,
430 const QString &fileEncoding,
432 const QString &driverName =
"GPKG",
433 bool onlySelected =
false,
434 QString *errorMessage
SIP_OUT =
nullptr,
435 const QStringList &datasourceOptions = QStringList(),
436 const QStringList &layerOptions = QStringList(),
437 bool skipAttributeCreation =
false,
438 QString *newFilename =
nullptr,
440 double symbologyScale = 1.0,
443 bool forceMulti =
false,
444 bool includeZ =
false,
448 , QString *newLayer =
nullptr );
485 bool onlySelectedFeatures =
false;
494 bool skipAttributeCreation =
false;
506 double symbologyScale = 1.0;
518 bool forceMulti =
false;
521 bool includeZ =
false;
547 bool saveMetadata =
false;
585 const QString &fileName,
587 QString *newFilename =
nullptr,
588 QString *errorMessage
SIP_OUT =
nullptr
590 , QString *newLayer =
nullptr );
600 const QString &fileEncoding,
604 const QString &driverName =
"GPKG",
605 const QStringList &datasourceOptions = QStringList(),
606 const QStringList &layerOptions = QStringList(),
607 QString *newFilename =
nullptr,
609 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
611 , QString *newLayer =
nullptr,
640 const QString &fileEncoding,
644 const QString &driverName,
645 const QStringList &datasourceOptions,
646 const QStringList &layerOptions,
647 QString *newFilename,
650 const QString &layerName,
652 QString *newLayer =
nullptr,
654 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
682 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
683 QString *newFilename =
nullptr,
699 const QString &fileName,
702 QString *newFilename =
nullptr,
703 QString *newLayer =
nullptr,
719 const QString &fileName,
722 QString *errorMessage
SIP_OUT =
nullptr,
723 QString *newFilename
SIP_OUT =
nullptr,
724 QString *newLayer
SIP_OUT =
nullptr );
753 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
764 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
773 static bool supportsFeatureStyles(
const QString &driverName );
799 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
807 static QString driverForExtension(
const QString &extension );
815 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
818 static QString filterForDriver(
const QString &driverName );
821 static QString convertCodecNameForEncodingOption(
const QString &codecName );
827 QString errorMessage()
const;
829 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
850 static bool deleteShapeFile(
const QString &fileName );
869 void setSymbologyScale(
double scale );
871 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
879 static QStringList defaultDatasetOptions(
const QString &driverName );
887 static QStringList defaultLayerOptions(
const QString &driverName );
901 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
907 static bool targetLayerExists(
const QString &datasetName,
908 const QString &layerName );
914 static bool areThereNewFieldsToCreate(
const QString &datasetName,
915 const QString &layerName,
924 OGRLayerH mLayer =
nullptr;
933 QTextCodec *mCodec =
nullptr;
958 struct PreparedWriterDetails
960 std::unique_ptr< QgsFeatureRenderer > renderer;
964 QString providerType;
965 long long featureCount = 0;
967 QString dataSourceUri;
971 QSet< int > fieldsToConvertToInt;
973 bool shallTransform =
false;
980 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
981 QVariantMap providerUriParams;
990 PreparedWriterDetails &details );
1006 const QString &fileName,
1009 QString *newFilename =
nullptr,
1010 QString *newLayer =
nullptr,
1011 QString *errorMessage
SIP_OUT =
nullptr );
1019 const QString &fileName,
1021 QString *newFilename =
nullptr,
1022 QString *errorMessage
SIP_OUT =
nullptr,
1025 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1027 const QString &driverName, QStringList datasourceOptions,
1028 QStringList layerOptions, QString *newFilename,
1030 const QString &layerName,
1033 FieldNameSource fieldNameSource );
1042 bool mUsingTransaction = false;
1043 QSet< QVariant::Type > mSupportedListSubTypes;
1047 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1052 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
1061 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1064 friend class TestQgsVectorFileWriter;
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.
Helper functions for various unit types.
DistanceUnit
Units of distance.
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.
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
QgsWkbTypes::Type mWkbType
Geometry type which is being used.
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.
Handles storage of information regarding WKB types and their properties.
Type
The WKB type describes the number of dimensions a geometry has.
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.