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,
536 static QList< QgsVectorFileWriter::FilterFormatDetails > supportedFiltersAndFormats( VectorFormatOptions options = SortRecommended );
547 static QStringList supportedFormatExtensions( VectorFormatOptions options = SortRecommended );
556 static bool supportsFeatureStyles(
const QString &driverName );
582 static QList< QgsVectorFileWriter::DriverDetails > ogrDriverList( VectorFormatOptions options = SortRecommended );
590 static QString driverForExtension(
const QString &extension );
598 static QString fileFilterString( VectorFormatOptions options = SortRecommended );
601 static QString filterForDriver(
const QString &driverName );
604 static QString convertCodecNameForEncodingOption(
const QString &codecName );
610 QString errorMessage();
612 bool addFeature(
QgsFeature &feature, QgsFeatureSink::Flags flags =
nullptr )
override;
613 bool addFeatures(
QgsFeatureList &features, QgsFeatureSink::Flags flags =
nullptr )
override;
632 static bool deleteShapeFile(
const QString &fileName );
651 void setSymbologyScale(
double scale );
653 static bool driverMetadata(
const QString &driverName,
MetaData &driverMetadata );
661 static QStringList defaultDatasetOptions(
const QString &driverName );
669 static QStringList defaultLayerOptions(
const QString &driverName );
683 static QgsVectorFileWriter::EditionCapabilities editionCapabilities(
const QString &datasetName );
689 static bool targetLayerExists(
const QString &datasetName,
690 const QString &layerName );
696 static bool areThereNewFieldsToCreate(
const QString &datasetName,
697 const QString &layerName,
706 OGRLayerH mLayer =
nullptr;
715 QTextCodec *mCodec =
nullptr;
740 struct PreparedWriterDetails
742 std::unique_ptr< QgsFeatureRenderer > renderer;
746 QString providerType;
747 long featureCount = 0;
749 QString dataSourceUri;
753 QSet< int > fieldsToConvertToInt;
755 bool shallTransform =
false;
762 std::unique_ptr< QgsGeometryEngine > filterRectEngine;
771 PreparedWriterDetails &details );
778 const QString &fileName,
780 QString *newFilename =
nullptr,
781 QString *errorMessage
SIP_OUT =
nullptr );
783 void init( QString vectorFileName, QString fileEncoding,
const QgsFields &fields,
785 const QString &driverName, QStringList datasourceOptions,
786 QStringList layerOptions, QString *newFilename,
788 const QString &layerName,
792 std::unique_ptr< QgsFeatureRenderer > mRenderer;
795 bool mUsingTransaction =
false;
799 bool writeFeature( OGRLayerH layer, OGRFeatureH feature );
808 std::unique_ptr< QgsFeatureRenderer > createSymbologyRenderer(
QgsFeatureRenderer *sourceRenderer )
const;
811 static QMap<QString, MetaData> sDriverMetadata;
814 static QStringList concatenateOptions(
const QMap<QString, Option *> &options );
819 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorFileWriter::EditionCapabilities )
820 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.
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).
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 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