19 #ifndef QGSVECTORFILEWRITER_H 
   20 #define QGSVECTORFILEWRITER_H 
   22 #include "qgis_core.h" 
   65           : docString( docString )
 
   79         SetOption( 
const QString &docString, 
const QStringList &values, 
const QString &defaultValue, 
bool allowNone = 
false )
 
   81           , values( qgis::listToSet( values ) )
 
   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;
 
  503         double symbologyScale = 1.0;
 
  515         bool forceMulti = 
false;
 
  518         bool includeZ = 
false;
 
  544         bool saveMetadata = 
false;
 
  582         const QString &fileName,
 
  584         QString *newFilename = 
nullptr,
 
  585         QString *errorMessage 
SIP_OUT = 
nullptr 
  587                                         , QString *newLayer = 
nullptr );
 
  597                                            const QString &fileEncoding,
 
  601                                            const QString &driverName = 
"GPKG",
 
  602                                            const QStringList &datasourceOptions = QStringList(),
 
  603                                            const QStringList &layerOptions = QStringList(),
 
  604                                            QString *newFilename = 
nullptr,
 
  606                                            QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags()
 
  608                                                , QString *newLayer = 
nullptr,
 
  637                                            const QString &fileEncoding,
 
  641                                            const QString &driverName,
 
  642                                            const QStringList &datasourceOptions,
 
  643                                            const QStringList &layerOptions,
 
  644                                            QString *newFilename,
 
  647                                            const QString &layerName,
 
  649                                            QString *newLayer = 
nullptr,
 
  651                                            QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
 
  679                                         QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
 
  680                                         QString *newFilename = 
nullptr,
 
  696         const QString &fileName,
 
  699         QString *newFilename = 
nullptr,
 
  700         QString *newLayer = 
nullptr,
 
  716         const QString &fileName,
 
  719         QString *errorMessage 
SIP_OUT = 
nullptr,
 
  720         QString *newFilename 
SIP_OUT = 
nullptr,
 
  721         QString *newLayer 
SIP_OUT = 
nullptr );
 
  750     static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
 
  761     static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
 
  770     static bool supportsFeatureStyles( 
const QString &driverName );
 
  796     static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
 
  804     static QString driverForExtension( 
const QString &extension );
 
  812     static QString fileFilterString( VectorFormatOptions options = SortRecommended );
 
  815     static QString filterForDriver( 
const QString &driverName );
 
  818     static QString convertCodecNameForEncodingOption( 
const QString &codecName );
 
  824     QString errorMessage();
 
  826     bool addFeature( 
QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) 
override;
 
  847     static bool deleteShapeFile( 
const QString &fileName );
 
  866     void setSymbologyScale( 
double scale );
 
  868     static bool driverMetadata( 
const QString &driverName, MetaData &driverMetadata );
 
  876     static QStringList defaultDatasetOptions( 
const QString &driverName );
 
  884     static QStringList defaultLayerOptions( 
const QString &driverName );
 
  898     static QgsVectorFileWriter::EditionCapabilities editionCapabilities( 
const QString &datasetName );
 
  904     static bool targetLayerExists( 
const QString &datasetName,
 
  905                                    const QString &layerName );
 
  911     static bool areThereNewFieldsToCreate( 
const QString &datasetName,
 
  912                                            const QString &layerName,
 
  921     OGRLayerH mLayer = 
nullptr;
 
  930     QTextCodec *mCodec = 
nullptr;
 
  955     struct PreparedWriterDetails
 
  957       std::unique_ptr< QgsFeatureRenderer > renderer;
 
  961       QString providerType;
 
  962       long long featureCount = 0;
 
  964       QString dataSourceUri;
 
  968       QSet< int > fieldsToConvertToInt;
 
  970       bool shallTransform = 
false;
 
  977       std::unique_ptr< QgsGeometryEngine  > filterRectEngine;
 
  978       QVariantMap providerUriParams;
 
  987         PreparedWriterDetails &details );
 
 1003         const QString &fileName,
 
 1006         QString *newFilename = 
nullptr,
 
 1007         QString *newLayer = 
nullptr,
 
 1008         QString *errorMessage 
SIP_OUT = 
nullptr );
 
 1016         const QString &fileName,
 
 1018         QString *newFilename = 
nullptr,
 
 1019         QString *errorMessage 
SIP_OUT = 
nullptr,
 
 1022     void init( QString vectorFileName, QString fileEncoding, const 
QgsFields &fields,
 
 1024                const QString &driverName, QStringList datasourceOptions,
 
 1025                QStringList layerOptions, QString *newFilename,
 
 1027                const QString &layerName,
 
 1030                FieldNameSource fieldNameSource );
 
 1039     bool mUsingTransaction = false;
 
 1040     QSet< QVariant::Type > mSupportedListSubTypes;
 
 1044     bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
 
 1049     double mapUnitScaleFactor( 
double scale, 
QgsUnitTypes::RenderUnit symbolUnits, 
QgsUnitTypes::DistanceUnit mapUnits );
 
 1058     static QStringList concatenateOptions( const QMap<QString, Option *> &options );
 
 1061     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.