QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
98
104 Qgis::VectorExportResult errorCode() const;
105
111 QString errorMessage() const;
112
118 int errorCount() const { return mErrorCount; }
119
125 Qgis::VectorDataProviderAttributeEditCapabilities attributeEditCapabilities() const;
126
127 bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
128 bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
129 QString lastError() const override;
130
134 ~QgsVectorLayerExporter() override;
135
136 bool flushBuffer() override;
137
138 private:
139
141 bool createSpatialIndex();
142
145 QString mErrorMessage;
146
147 int mErrorCount;
148
149 QgsVectorDataProvider *mProvider = nullptr;
150
152 QMap<int, int> mOldToNewAttrIdx;
153 int mAttributeCount;
154
155 QgsFeatureList mFeatureBuffer;
156 int mFeatureBufferMemoryUsage = 0;
157
158 bool mCreateSpatialIndex = true;
159
160#ifdef SIP_RUN
162#endif
163
164};
165
166
176class CORE_EXPORT QgsVectorLayerExporterTask : public QgsTask
177{
178 Q_OBJECT
179
180 public:
181
189 const QString &uri,
190 const QString &providerKey,
191 const QgsCoordinateReferenceSystem &destinationCrs,
192 const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
193 bool ownsLayer = false );
194
201 static QgsVectorLayerExporterTask *withLayerOwnership( QgsVectorLayer *layer SIP_TRANSFER,
202 const QString &uri,
203 const QString &providerKey,
204 const QgsCoordinateReferenceSystem &destinationCrs,
205 const QMap<QString, QVariant> &options = QMap<QString, QVariant>() ) SIP_FACTORY;
206
207 void cancel() override;
208
209 signals:
210
215
220 void errorOccurred( Qgis::VectorExportResult error, const QString &errorMessage );
221
222 protected:
223
224 bool run() override;
225 void finished( bool result ) override;
226
227 private:
228
229 QPointer< QgsVectorLayer > mLayer = nullptr;
230 bool mOwnsLayer = false;
231
232 QString mDestUri;
233 QString mDestProviderKey;
235 QMap<QString, QVariant> mOptions;
236
237 std::unique_ptr< QgsFeedback > mOwnedFeedback;
238
240 QString mErrorMessage;
241
242};
243
244#endif // QGSVECTORLAYEREXPORTER_H
VectorExportResult
Vector layer export result codes.
Definition qgis.h:983
@ Success
No errors were encountered.
QFlags< VectorDataProviderAttributeEditCapability > VectorDataProviderAttributeEditCapabilities
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:566
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
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
int errorCount() const
Returns the number of error messages encountered during the export.
QgsVectorLayerExporter(const QgsVectorLayerExporter &rh)=delete
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