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( 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 )
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
329 const QString &fileName,
330 const QString &fileEncoding,
332 const QString &driverName =
"GPKG",
333 bool onlySelected =
false,
334 QString *errorMessage
SIP_OUT =
nullptr,
335 const QStringList &datasourceOptions = QStringList(),
336 const QStringList &layerOptions = QStringList(),
337 bool skipAttributeCreation =
false,
338 QString *newFilename =
nullptr,
340 double symbologyScale = 1.0,
343 bool forceMulti =
false,
344 bool includeZ =
false,
348 , QString *newLayer =
nullptr );
410 const QString &fileName,
411 const QString &fileEncoding,
413 const QString &driverName =
"GPKG",
414 bool onlySelected =
false,
415 QString *errorMessage
SIP_OUT =
nullptr,
416 const QStringList &datasourceOptions = QStringList(),
417 const QStringList &layerOptions = QStringList(),
418 bool skipAttributeCreation =
false,
419 QString *newFilename =
nullptr,
421 double symbologyScale = 1.0,
424 bool forceMulti =
false,
425 bool includeZ =
false,
429 , QString *newLayer =
nullptr );
465 bool onlySelectedFeatures =
false;
474 bool skipAttributeCreation =
false;
483 double symbologyScale = 1.0;
494 bool forceMulti =
false;
497 bool includeZ =
false;
536 const QString &fileName,
538 QString *newFilename =
nullptr,
539 QString *errorMessage
SIP_OUT =
nullptr 541 , QString *newLayer =
nullptr );
548 const QString &fileEncoding,
552 const QString &driverName =
"GPKG",
553 const QStringList &datasourceOptions = QStringList(),
554 const QStringList &layerOptions = QStringList(),
555 QString *newFilename =
nullptr,
557 QgsFeatureSink::SinkFlags sinkFlags =
nullptr 559 , QString *newLayer =
nullptr 582 const QString &fileEncoding,
586 const QString &driverName,
587 const QStringList &datasourceOptions,
588 const QStringList &layerOptions,
589 QString *newFilename,
592 const QString &layerName,
594 QString *newLayer =
nullptr 629 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
640 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
649 static bool supportsFeatureStyles(
const QString &driverName );
675 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
683 static QString driverForExtension(
const QString &extension );
691 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
694 static QString filterForDriver(
const QString &driverName );
697 static QString convertCodecNameForEncodingOption(
const QString &codecName );
703 QString errorMessage();
705 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags =
nullptr )
override;
706 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags =
nullptr )
override;
725 static bool deleteShapeFile(
const QString &fileName );
744 void setSymbologyScale(
double scale );
746 static bool driverMetadata(
const QString &driverName,
MetaData &driverMetadata );
754 static QStringList defaultDatasetOptions(
const QString &driverName );
762 static QStringList defaultLayerOptions(
const QString &driverName );
776 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
782 static bool targetLayerExists(
const QString &datasetName,
783 const QString &layerName );
789 static bool areThereNewFieldsToCreate(
const QString &datasetName,
790 const QString &layerName,
799 OGRLayerH mLayer =
nullptr;
808 QTextCodec *mCodec =
nullptr;
833 struct PreparedWriterDetails
835 std::unique_ptr< QgsFeatureRenderer > renderer;
839 QString providerType;
840 long featureCount = 0;
842 QString dataSourceUri;
846 QSet< int > fieldsToConvertToInt;
848 bool shallTransform =
false;
855 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
856 QVariantMap providerUriParams;
865 PreparedWriterDetails &details );
872 const QString &fileName,
874 QString *newFilename =
nullptr,
875 QString *errorMessage
SIP_OUT =
nullptr,
876 QString *newLayer =
nullptr );
878 void init( QString vectorFileName, QString fileEncoding,
const QgsFields &fields,
880 const QString &driverName, QStringList datasourceOptions,
881 QStringList layerOptions, QString *newFilename,
883 const QString &layerName,
887 std::unique_ptr< QgsFeatureRenderer > mRenderer;
890 bool mUsingTransaction =
false;
891 bool supportsStringList =
false;
895 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
904 std::unique_ptr< QgsFeatureRenderer > createSymbologyRenderer(
QgsFeatureRenderer *sourceRenderer )
const;
907 static QMap<QString, MetaData> sDriverMetadata;
910 static QStringList concatenateOptions(
const QMap<QString, Option *> &options );
913 friend class TestQgsVectorFileWriter;
916 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorFileWriter::EditionCapabilities )
917 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)
QSet< QgsFeatureId > QgsFeatureIds
QMap< int, int > attrIdxToOgrIdx()
WriterError mError
Contains error value if construction was not successful.
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 cancellation 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.
std::unique_ptr< std::remove_pointer< OGRFeatureH >::type, OGRFeatureDeleter > ogr_feature_unique_ptr
Scoped OGR feature.
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).
const QgsCoordinateReferenceSystem & outputCrs
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.
std::unique_ptr< std::remove_pointer< OGRDataSourceH >::type, OGRDataSourceDeleter > ogr_datasource_unique_ptr
Scoped OGR data source.
Represents a vector layer which manages a vector based data sets.
Writing was interrupted by manual cancellation.
QgsWkbTypes::Type mWkbType
Geometry type which is being used.
RenderUnit
Rendering size units.
QString longName
Descriptive, user friendly name for the driver.
void * OGRSpatialReferenceH