QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
49class CORE_EXPORT QgsVectorLayerExporter : public QgsFeatureSink
50{
51 public:
52
53
67 static Qgis::VectorExportResult exportLayer( QgsVectorLayer *layer,
68 const QString &uri,
69 const QString &providerKey,
70 const QgsCoordinateReferenceSystem &destCRS,
71 bool onlySelected = false,
72 QString *errorMessage SIP_OUT = nullptr,
73 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
74 QgsFeedback *feedback = nullptr );
75
88 QgsVectorLayerExporter( const QString &uri,
89 const QString &provider,
90 const QgsFields &fields,
91 Qgis::WkbType geometryType,
93 bool overwrite = false,
94 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
95 QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags() );
96
101
107 Qgis::VectorExportResult errorCode() const;
108
114 QString errorMessage() const;
115
121 int errorCount() const { return mErrorCount; }
122
128 Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities() const;
129
130 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
131 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
132 QString lastError() const override;
133
137 ~QgsVectorLayerExporter() override;
138
139 bool flushBuffer() override;
140
141 private:
142
144 bool createSpatialIndex();
145
148 QString mErrorMessage;
149
150 int mErrorCount;
151
152 QgsVectorDataProvider *mProvider = nullptr;
153
155 QMap<int, int> mOldToNewAttrIdx;
156 int mAttributeCount;
157
158 QgsFeatureList mFeatureBuffer;
159 int mFeatureBufferMemoryUsage = 0;
160
161 bool mCreateSpatialIndex = true;
162
163#ifdef SIP_RUN
165#endif
166
167};
168
169
180class CORE_EXPORT QgsVectorLayerExporterTask : public QgsTask
181{
182 Q_OBJECT
183
184 public:
185
193 const QString &uri,
194 const QString &providerKey,
195 const QgsCoordinateReferenceSystem &destinationCrs,
196 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
197 bool ownsLayer = false );
198
205 static QgsVectorLayerExporterTask *withLayerOwnership( QgsVectorLayer *layer SIP_TRANSFER,
206 const QString &uri,
207 const QString &providerKey,
208 const QgsCoordinateReferenceSystem &destinationCrs,
209 const QMap<QString, QVariant> &options = QMap<QString, QVariant>() ) SIP_FACTORY;
210
211 void cancel() override;
212
213 signals:
214
219
224 void errorOccurred( Qgis::VectorExportResult error, const QString &errorMessage );
225
226 protected:
227
228 bool run() override;
229 void finished( bool result ) override;
230
231 private:
232
233 QPointer< QgsVectorLayer > mLayer = nullptr;
234 bool mOwnsLayer = false;
235
236 QString mDestUri;
237 QString mDestProviderKey;
239 QMap<QString, QVariant> mOptions;
240
241 std::unique_ptr< QgsFeedback > mOwnedFeedback;
242
244 QString mErrorMessage;
245
246};
247
248#endif // QGSVECTORLAYEREXPORTER_H
VectorExportResult
Vector layer export result codes.
Definition qgis.h:708
@ Success
No errors were encountered.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
This class represents a coordinate reference system (CRS).
An interface for objects which accept features via addFeature(s) methods.
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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:45
Container of fields for a vector layer.
Definition qgsfields.h:45
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
Definition qgsfeature.h:920
const QgsCoordinateReferenceSystem & crs