19 #ifndef QGSVECTORFILEWRITER_H
20 #define QGSVECTORFILEWRITER_H
22 #include "qgis_core.h"
64 : docString( docString )
78 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
80 , values( qgis::listToSet( values ) )
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;
502 double symbologyScale = 1.0;
514 bool forceMulti =
false;
517 bool includeZ =
false;
543 bool saveMetadata =
false;
581 const QString &fileName,
583 QString *newFilename =
nullptr,
584 QString *errorMessage
SIP_OUT =
nullptr
586 , QString *newLayer =
nullptr );
596 const QString &fileEncoding,
600 const QString &driverName =
"GPKG",
601 const QStringList &datasourceOptions = QStringList(),
602 const QStringList &layerOptions = QStringList(),
603 QString *newFilename =
nullptr,
605 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
607 , QString *newLayer =
nullptr,
636 const QString &fileEncoding,
640 const QString &driverName,
641 const QStringList &datasourceOptions,
642 const QStringList &layerOptions,
643 QString *newFilename,
646 const QString &layerName,
648 QString *newLayer =
nullptr,
650 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
678 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
679 QString *newFilename =
nullptr,
695 const QString &fileName,
698 QString *newFilename =
nullptr,
699 QString *newLayer =
nullptr,
715 const QString &fileName,
718 QString *errorMessage
SIP_OUT =
nullptr,
719 QString *newFilename
SIP_OUT =
nullptr,
720 QString *newLayer
SIP_OUT =
nullptr );
749 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
760 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
769 static bool supportsFeatureStyles(
const QString &driverName );
795 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
803 static QString driverForExtension(
const QString &extension );
811 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
814 static QString filterForDriver(
const QString &driverName );
817 static QString convertCodecNameForEncodingOption(
const QString &codecName );
823 QString errorMessage();
825 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
846 static bool deleteShapeFile(
const QString &fileName );
865 void setSymbologyScale(
double scale );
867 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
875 static QStringList defaultDatasetOptions(
const QString &driverName );
883 static QStringList defaultLayerOptions(
const QString &driverName );
897 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
903 static bool targetLayerExists(
const QString &datasetName,
904 const QString &layerName );
910 static bool areThereNewFieldsToCreate(
const QString &datasetName,
911 const QString &layerName,
920 OGRLayerH mLayer =
nullptr;
929 QTextCodec *mCodec =
nullptr;
954 struct PreparedWriterDetails
956 std::unique_ptr< QgsFeatureRenderer > renderer;
960 QString providerType;
961 long long featureCount = 0;
963 QString dataSourceUri;
967 QSet< int > fieldsToConvertToInt;
969 bool shallTransform =
false;
976 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
977 QVariantMap providerUriParams;
986 PreparedWriterDetails &details );
1002 const QString &fileName,
1005 QString *newFilename =
nullptr,
1006 QString *newLayer =
nullptr,
1007 QString *errorMessage
SIP_OUT =
nullptr );
1015 const QString &fileName,
1017 QString *newFilename =
nullptr,
1018 QString *errorMessage
SIP_OUT =
nullptr,
1021 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
1023 const QString &driverName, QStringList datasourceOptions,
1024 QStringList layerOptions, QString *newFilename,
1026 const QString &layerName,
1029 FieldNameSource fieldNameSource );
1038 bool mUsingTransaction = false;
1039 QSet< QVariant::Type > mSupportedListSubTypes;
1043 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1048 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
1057 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1060 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.
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 > 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(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)
QMap< int, int > attrIdxToOgrIdx()
QgsVectorFileWriter & operator=(const QgsVectorFileWriter &rh)=delete
QgsVectorFileWriter cannot be copied.
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.