QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsvectorlayerexporter.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerexporter.h
3 -------------------
4 begin : Thu Aug 25 2011
5 copyright : (C) 2011 by Giuseppe Sucameli
6 email : brush.tyler at gmail.com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSVECTORLAYEREXPORTER_H
19#define QGSVECTORLAYEREXPORTER_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgis.h"
24#include "qgsfeature.h"
25#include "qgsfeaturesink.h"
26#include "qgstaskmanager.h"
27#include "qgsfeedback.h"
28#include "qgsvectorlayer.h"
29
30#include <QPointer>
31
32class QProgressDialog;
34class QgsFields;
35
48class CORE_EXPORT QgsVectorLayerExporter : public QgsFeatureSink
49{
50 public:
51
52
66 static Qgis::VectorExportResult exportLayer( QgsVectorLayer *layer,
67 const QString &uri,
68 const QString &providerKey,
69 const QgsCoordinateReferenceSystem &destCRS,
70 bool onlySelected = false,
71 QString *errorMessage SIP_OUT = nullptr,
72 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
73 QgsFeedback *feedback = nullptr );
74
87 QgsVectorLayerExporter( const QString &uri,
88 const QString &provider,
89 const QgsFields &fields,
90 Qgis::WkbType geometryType,
92 bool overwrite = false,
93 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
95
100
106 Qgis::VectorExportResult errorCode() const;
107
113 QString errorMessage() const;
114
120 int errorCount() const { return mErrorCount; }
121
127 Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities() const;
128
129 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
130 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
131 QString lastError() const override;
132
136 ~QgsVectorLayerExporter() override;
137
138 bool flushBuffer() override;
139
140 private:
141
143 bool createSpatialIndex();
144
147 QString mErrorMessage;
148
149 int mErrorCount;
150
151 QgsVectorDataProvider *mProvider = nullptr;
152
154 QMap<int, int> mOldToNewAttrIdx;
155 int mAttributeCount;
156
157 QgsFeatureList mFeatureBuffer;
158 int mFeatureBufferMemoryUsage = 0;
159
160 bool mCreateSpatialIndex = true;
161
162#ifdef SIP_RUN
164#endif
165
166};
167
168
178class CORE_EXPORT QgsVectorLayerExporterTask : public QgsTask
179{
180 Q_OBJECT
181
182 public:
183
191 const QString &uri,
192 const QString &providerKey,
193 const QgsCoordinateReferenceSystem &destinationCrs,
194 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
195 bool ownsLayer = false );
196
203 static QgsVectorLayerExporterTask *withLayerOwnership( QgsVectorLayer *layer SIP_TRANSFER,
204 const QString &uri,
205 const QString &providerKey,
206 const QgsCoordinateReferenceSystem &destinationCrs,
207 const QMap<QString, QVariant> &options = QMap<QString, QVariant>() ) SIP_FACTORY;
208
209 void cancel() override;
210
211 signals:
212
217
222 void errorOccurred( Qgis::VectorExportResult error, const QString &errorMessage );
223
224 protected:
225
226 bool run() override;
227 void finished( bool result ) override;
228
229 private:
230
231 QPointer< QgsVectorLayer > mLayer = nullptr;
232 bool mOwnsLayer = false;
233
234 QString mDestUri;
235 QString mDestProviderKey;
237 QMap<QString, QVariant> mOptions;
238
239 std::unique_ptr< QgsFeedback > mOwnedFeedback;
240
242 QString mErrorMessage;
243
244};
245
246#endif // QGSVECTORLAYEREXPORTER_H
VectorExportResult
Vector layer export result codes.
Definition qgis.h:803
@ Success
No errors were encountered.
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:412
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
This class represents a coordinate reference system (CRS).
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
virtual bool flushBuffer()
Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to...
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.
QFlags< Flag > Flags
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:46
Abstract base class for long running background tasks.
This is the base class for vector data providers.
QgsTask task which performs a QgsVectorLayerExporter layer export operation as a background task.
void exportComplete()
Emitted when exporting the layer is successfully completed.
void errorOccurred(Qgis::VectorExportResult error, const QString &errorMessage)
Emitted when an error occurs which prevented the layer being exported (or if the task is canceled).
A convenience class for exporting vector layers to a destination data provider.
QgsVectorLayerExporter & operator=(const QgsVectorLayerExporter &rh)=delete
QgsVectorLayerExporter cannot be copied.
int errorCount() const
Returns the number of error messages encountered during the export.
QgsVectorLayerExporter(const QgsVectorLayerExporter &rh)=delete
QgsVectorLayerExporter cannot be copied.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
QList< QgsFeature > QgsFeatureList
const QgsCoordinateReferenceSystem & crs