19 #ifndef QGSVECTORFILEWRITER_H 20 #define QGSVECTORFILEWRITER_H 22 #include "qgis_core.h" 63 : docString( docString )
65 virtual ~
Option() =
default;
77 SetOption(
const QString &docString,
const QStringList &values,
const QString &defaultValue,
bool allowNone =
false )
79 , values( values.toSet() )
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( QLatin1String(
"" ), 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 )
195 SortRecommended = 1 << 1,
196 SkipNonSpatialFormats = 1 << 2,
209 FieldValueConverter() =
default;
211 virtual ~FieldValueConverter() =
default;
226 virtual QVariant convert(
int fieldIdxInLayer,
const QVariant &value );
240 CanAddNewLayer = 1 << 0,
243 CanAppendToExistingLayer = 1 << 1,
246 CanAddNewFieldsToExistingLayer = 1 << 2,
249 CanDeleteLayer = 1 << 3
273 AppendToLayerAddFields
300 const QString &fileName,
301 const QString &fileEncoding,
303 const QString &driverName =
"GPKG",
304 bool onlySelected =
false,
305 QString *errorMessage
SIP_OUT =
nullptr,
306 const QStringList &datasourceOptions = QStringList(),
307 const QStringList &layerOptions = QStringList(),
308 bool skipAttributeCreation =
false,
309 QString *newFilename =
nullptr,
311 double symbologyScale = 1.0,
314 bool forceMulti =
false,
315 bool includeZ =
false,
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,
398 bool onlySelectedFeatures =
false;
407 bool skipAttributeCreation =
false;
416 double symbologyScale = 1.0;
427 bool forceMulti =
false;
430 bool includeZ =
false;
454 const QString &fileName,
456 QString *newFilename =
nullptr,
457 QString *errorMessage
SIP_OUT =
nullptr );
461 const QString &fileEncoding,
465 const QString &driverName =
"GPKG",
466 const QStringList &datasourceOptions = QStringList(),
467 const QStringList &layerOptions = QStringList(),
468 QString *newFilename =
nullptr,
490 const QString &fileEncoding,
494 const QString &driverName,
495 const QStringList &datasourceOptions,
496 const QStringList &layerOptions,
497 QString *newFilename,
500 const QString &layerName,
530 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
541 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
550 static bool supportsFeatureStyles(
const QString &driverName );
576 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
584 static QString driverForExtension(
const QString &extension );
592 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
595 static QString filterForDriver(
const QString &driverName );
598 static QString convertCodecNameForEncodingOption(
const QString &codecName );
604 QString errorMessage();
606 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags =
nullptr )
override;
607 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags =
nullptr )
override;
626 static bool deleteShapeFile(
const QString &fileName );
645 void setSymbologyScale(
double scale );
647 static bool driverMetadata(
const QString &driverName,
MetaData &driverMetadata );
655 static QStringList defaultDatasetOptions(
const QString &driverName );
663 static QStringList defaultLayerOptions(
const QString &driverName );
677 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
683 static bool targetLayerExists(
const QString &datasetName,
684 const QString &layerName );
690 static bool areThereNewFieldsToCreate(
const QString &datasetName,
691 const QString &layerName,
700 OGRLayerH mLayer =
nullptr;
709 QTextCodec *mCodec =
nullptr;
734 struct PreparedWriterDetails
736 std::unique_ptr< QgsFeatureRenderer > renderer;
740 QString providerType;
741 long featureCount = 0;
743 QString dataSourceUri;
747 QSet< int > fieldsToConvertToInt;
749 bool shallTransform =
false;
756 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
765 PreparedWriterDetails &details );
772 const QString &fileName,
774 QString *newFilename =
nullptr,
775 QString *errorMessage
SIP_OUT =
nullptr );
777 void init( QString vectorFileName, QString fileEncoding,
const QgsFields &fields,
779 const QString &driverName, QStringList datasourceOptions,
780 QStringList layerOptions, QString *newFilename,
782 const QString &layerName,
786 std::unique_ptr< QgsFeatureRenderer > mRenderer;
789 bool mUsingTransaction =
false;
791 static QMap<QString, MetaData> initMetaData();
794 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
803 std::unique_ptr< QgsFeatureRenderer > createSymbologyRenderer(
QgsFeatureRenderer *sourceRenderer )
const;
806 static QMap<QString, MetaData> sDriverMetadata;
809 static QStringList concatenateOptions(
const QMap<QString, Option *> &options );
814 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorFileWriter::EditionCapabilities )
815 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorFileWriter::VectorFormatOptions )
Append features to existing layer, but do not create new fields.
Wrapper for iterator of features from vector data provider or vector layer.
BoolOption(const QString &docString, bool defaultValue)
A rectangle specified with double values.
QgsVectorFileWriter::OptionType type
Details of available driver formats.
void setSymbologyExport(QgsVectorFileWriter::SymbologyExport symExport)
QMap< int, int > attrIdxToOgrIdx()
WriterError mError
Contains error value if construction was not successful.
QSet< QgsFeatureId > QgsFeatureIds
QList< QgsFeature > QgsFeatureList
SymbologyExport mSymbologyExport
QgsAttributeList attributes
Attributes to export (empty means all unless skipAttributeCreation is set)
An interface for objects which accept features via addFeature(s) methods.
QMap< QgsSymbolLayer *, QString > mSymbolLayerTable
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
StringOption(const QString &docString, const QString &defaultValue=QString())
QStringList layerOptions
List of OGR layer creation options.
A convenience class for writing vector files to disk.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
gdal::ogr_datasource_unique_ptr mDS
Create or overwrite file.
QgsVectorFileWriter::SymbologyExport symbologyExport() const
Base class for feedback objects to be used for cancelation of something running in a worker thread...
IntOption(const QString &docString, int defaultValue)
Options to pass to writeAsVectorFormat()
Option(const QString &docString, QgsVectorFileWriter::OptionType type)
Type
The WKB type describes the number of dimensions a geometry has.
QString driverName
Unique driver name.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QStringList datasourceOptions
List of OGR data source creation options.
SetOption(const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone=false)
Create or overwrite layer.
ActionOnExistingFile
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteL...
QString driverName
OGR driver to use.
Encapsulate a field in an attribute table or data source.
QMap< int, int > mAttrIdxToOgrIdx
Map attribute indizes to OGR field indexes.
QgsRectangle filterExtent
If not empty, only features intersecting the extent will be saved.
double symbologyScale() const
Returns the reference scale for output.
DistanceUnit
Units of distance.
Contains information about the context of a rendering operation.
QString fileEncoding
Encoding to use.
HiddenOption(const QString &value)
EditionCapability
Edition capability flags.
double mSymbologyScale
Scale for symbology export (e.g. for symbols units in map units)
This class represents a coordinate reference system (CRS).
std::unique_ptr< void, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
QgsCoordinateTransform ct
Transform to reproject exported geometries with, or invalid transform for no transformation.
VectorFormatOption
Options for sorting and filtering vector formats.
Interface to convert raw field values to their user-friendly value.
QgsTask task which performs a QgsVectorFileWriter layer saving operation as a background task...
QList< int > QgsAttributeList
QString layerName
Layer name. If let empty, it will be derived from the filename.
Represents a vector layer which manages a vector based data sets.
Writing was interrupted by manual cancelation.
QgsWkbTypes::Type mWkbType
Geometry type which is being used.
RenderUnit
Rendering size units.
QString longName
Descriptive, user friendly name for the driver.
void * OGRSpatialReferenceH
std::unique_ptr< void, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.