QGIS API Documentation  2.99.0-Master (314842d)
qgsvectorlayerimport.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerimport.cpp
3  vector layer importer
4  -------------------
5  begin : Thu Aug 25 2011
6  copyright : (C) 2011 by Giuseppe Sucameli
7  email : brush.tyler at gmail.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #ifndef QGSVECTORLAYERIMPORT_H
20 #define QGSVECTORLAYERIMPORT_H
21 
22 #include "qgis_core.h"
23 #include "qgsfeature.h"
24 
25 class QProgressDialog;
27 class QgsVectorLayer;
28 class QgsFields;
29 
36 class CORE_EXPORT QgsVectorLayerImport
37 {
38  public:
39 
41  {
42  NoError = 0,
55  };
56 
71  static ImportError importLayer( QgsVectorLayer *layer,
72  const QString &uri,
73  const QString &providerKey,
74  const QgsCoordinateReferenceSystem &destCRS,
75  bool onlySelected = false,
76  QString *errorMessage = nullptr,
77  bool skipAttributeCreation = false,
78  QMap<QString, QVariant> *options = nullptr,
79  QProgressDialog *progress = nullptr
80  );
81 
93  QgsVectorLayerImport( const QString &uri,
94  const QString &provider,
95  const QgsFields &fields,
96  QgsWkbTypes::Type geometryType,
98  bool overwrite = false,
99  const QMap<QString, QVariant> *options = nullptr,
100  QProgressDialog *progress = nullptr
101  );
102 
104  QgsVectorLayerImport( const QgsVectorLayerImport &rh ) = delete;
106  QgsVectorLayerImport &operator=( const QgsVectorLayerImport &rh ) = delete;
107 
109  ImportError hasError();
110 
112  QString errorMessage();
113 
114  int errorCount() const { return mErrorCount; }
115 
117  bool addFeature( QgsFeature &feature );
118 
121 
122  protected:
124  bool flushBuffer();
125 
127  bool createSpatialIndex();
128 
131  QString mErrorMessage;
132 
134 
135  QgsVectorDataProvider *mProvider = nullptr;
136 
138  QMap<int, int> mOldToNewAttrIdx;
140 
142  QProgressDialog *mProgress = nullptr;
143 
144 };
145 
146 #endif
QMap< int, int > mOldToNewAttrIdx
Map attribute indexes to new field indexes.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:363
Container of fields for a vector layer.
Definition: qgsfields.h:39
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:65
A convenience class for writing vector files to disk.
ImportError mError
Contains error value.
This class represents a coordinate reference system (CRS).
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.