19 #ifndef QGSVECTORFILEWRITER_H
20 #define QGSVECTORFILEWRITER_H
22 #include "qgis_core.h"
63 : docString( docString )
77 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
79 , values( qgis::listToSet( values ) )
80 , defaultValue( defaultValue )
81 , allowNone( allowNone )
95 StringOption(
const QString &docString,
const QString &defaultValue = QString() )
96 :
Option( docString, String )
97 , defaultValue( defaultValue )
110 :
Option( docString, Int )
111 , defaultValue( defaultValue )
124 :
SetOption( docString, QStringList() << QStringLiteral(
"YES" ) << QStringLiteral(
"NO" ), defaultValue ?
"YES" :
"NO" )
135 :
Option( QString(), Hidden )
147 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() )
148 : longName( longName )
149 , trLongName( trLongName )
152 , driverOptions( driverOptions )
153 , layerOptions( layerOptions )
154 , compulsoryEncoding( compulsoryEncoding )
205 SortRecommended = 1 << 1,
206 SkipNonSpatialFormats = 1 << 2,
208 Q_DECLARE_FLAGS( VectorFormatOptions, VectorFormatOption )
236 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
251 CanAddNewLayer = 1 << 0,
254 CanAppendToExistingLayer = 1 << 1,
257 CanAddNewFieldsToExistingLayer = 1 << 2,
260 CanDeleteLayer = 1 << 3
267 Q_DECLARE_FLAGS( EditionCapabilities, EditionCapability )
285 AppendToLayerAddFields
343 const QString &fileName,
344 const QString &fileEncoding,
346 const QString &driverName =
"GPKG",
347 bool onlySelected =
false,
348 QString *errorMessage
SIP_OUT =
nullptr,
349 const QStringList &datasourceOptions = QStringList(),
350 const QStringList &layerOptions = QStringList(),
351 bool skipAttributeCreation =
false,
352 QString *newFilename =
nullptr,
354 double symbologyScale = 1.0,
357 bool forceMulti =
false,
358 bool includeZ =
false,
362 , QString *newLayer =
nullptr );
426 const QString &fileName,
427 const QString &fileEncoding,
429 const QString &driverName =
"GPKG",
430 bool onlySelected =
false,
431 QString *errorMessage
SIP_OUT =
nullptr,
432 const QStringList &datasourceOptions = QStringList(),
433 const QStringList &layerOptions = QStringList(),
434 bool skipAttributeCreation =
false,
435 QString *newFilename =
nullptr,
437 double symbologyScale = 1.0,
440 bool forceMulti =
false,
441 bool includeZ =
false,
445 , QString *newLayer =
nullptr );
482 bool onlySelectedFeatures =
false;
491 bool skipAttributeCreation =
false;
500 double symbologyScale = 1.0;
512 bool forceMulti =
false;
515 bool includeZ =
false;
563 const QString &fileName,
565 QString *newFilename =
nullptr,
566 QString *errorMessage
SIP_OUT =
nullptr
568 , QString *newLayer =
nullptr );
578 const QString &fileEncoding,
582 const QString &driverName =
"GPKG",
583 const QStringList &datasourceOptions = QStringList(),
584 const QStringList &layerOptions = QStringList(),
585 QString *newFilename =
nullptr,
587 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
589 , QString *newLayer =
nullptr,
618 const QString &fileEncoding,
622 const QString &driverName,
623 const QStringList &datasourceOptions,
624 const QStringList &layerOptions,
625 QString *newFilename,
628 const QString &layerName,
630 QString *newLayer =
nullptr,
632 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
660 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
661 QString *newFilename =
nullptr,
677 const QString &fileName,
680 QString *newFilename =
nullptr,
681 QString *newLayer =
nullptr,
682 QString *errorMessage
SIP_OUT =
nullptr );
711 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
722 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
731 static bool supportsFeatureStyles(
const QString &driverName );
757 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
765 static QString driverForExtension(
const QString &extension );
773 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
776 static QString filterForDriver(
const QString &driverName );
779 static QString convertCodecNameForEncodingOption(
const QString &codecName );
785 QString errorMessage();
787 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() )
override;
808 static bool deleteShapeFile(
const QString &fileName );
827 void setSymbologyScale(
double scale );
829 static bool driverMetadata(
const QString &driverName, MetaData &driverMetadata );
837 static QStringList defaultDatasetOptions(
const QString &driverName );
845 static QStringList defaultLayerOptions(
const QString &driverName );
859 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
865 static bool targetLayerExists(
const QString &datasetName,
866 const QString &layerName );
872 static bool areThereNewFieldsToCreate(
const QString &datasetName,
873 const QString &layerName,
882 OGRLayerH mLayer =
nullptr;
891 QTextCodec *mCodec =
nullptr;
916 struct PreparedWriterDetails
918 std::unique_ptr< QgsFeatureRenderer > renderer;
922 QString providerType;
923 long featureCount = 0;
925 QString dataSourceUri;
929 QSet< int > fieldsToConvertToInt;
931 bool shallTransform =
false;
938 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
939 QVariantMap providerUriParams;
948 PreparedWriterDetails &details );
964 const QString &fileName,
967 QString *newFilename =
nullptr,
968 QString *newLayer =
nullptr,
969 QString *errorMessage
SIP_OUT =
nullptr );
977 const QString &fileName,
979 QString *newFilename =
nullptr,
980 QString *errorMessage
SIP_OUT =
nullptr,
983 void init( QString vectorFileName, QString fileEncoding, const
QgsFields &fields,
985 const QString &driverName, QStringList datasourceOptions,
986 QStringList layerOptions, QString *newFilename,
988 const QString &layerName,
991 FieldNameSource fieldNameSource );
1000 bool mUsingTransaction = false;
1001 bool supportsStringList = false;
1005 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
1010 double mapUnitScaleFactor(
double scale,
QgsUnitTypes::RenderUnit symbolUnits,
QgsUnitTypes::DistanceUnit mapUnits );
1019 static QStringList concatenateOptions( const QMap<QString, Option *> &options );
1022 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 id, geometry and a list of field/values...
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.
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 files to disk.
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
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.