2011-09-12 21:08:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
There are two possibilities how to use this class:
|
|
|
|
1. static call to QgsVectorLayerImport::importLayer(...) which saves the whole vector layer
|
|
|
|
2. create an instance of the class and issue calls to addFeature(...)
|
|
|
|
*/
|
|
|
|
class QgsVectorLayerImport
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsvectorlayerimport.h>
|
|
|
|
#include <qgsfield.h>
|
2013-01-07 00:30:30 +01:00
|
|
|
class QProgressDialog;
|
2011-09-12 21:08:13 +02:00
|
|
|
%End
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
|
|
|
|
2011-09-12 21:08:13 +02:00
|
|
|
enum ImportError
|
|
|
|
{
|
|
|
|
NoError = 0,
|
|
|
|
ErrDriverNotFound,
|
|
|
|
ErrCreateDataSource,
|
|
|
|
ErrCreateLayer,
|
|
|
|
ErrAttributeTypeUnsupported,
|
|
|
|
ErrAttributeCreationFailed,
|
|
|
|
ErrProjection,
|
|
|
|
ErrFeatureWriteFailed,
|
2012-09-24 02:28:15 +02:00
|
|
|
ErrInvalidLayer,
|
2011-09-12 21:08:13 +02:00
|
|
|
ErrInvalidProvider,
|
|
|
|
ErrProviderUnsupportedFeature,
|
|
|
|
ErrConnectionFailed
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Write contents of vector layer to a different datasource */
|
|
|
|
static ImportError importLayer( QgsVectorLayer* layer,
|
|
|
|
const QString& uri,
|
|
|
|
const QString& providerKey,
|
|
|
|
const QgsCoordinateReferenceSystem *destCRS,
|
2012-09-24 02:28:15 +02:00
|
|
|
bool onlySelected = false,
|
2011-09-12 21:08:13 +02:00
|
|
|
QString *errorMessage /Out/ = 0,
|
2012-09-24 02:28:15 +02:00
|
|
|
bool skipAttributeCreation = false,
|
2013-01-07 00:30:30 +01:00
|
|
|
QMap<QString, QVariant> *options = 0,
|
|
|
|
QProgressDialog *progress = 0
|
2011-09-12 21:08:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/** create a empty layer and add fields to it */
|
|
|
|
QgsVectorLayerImport( const QString &uri,
|
|
|
|
const QString &provider,
|
2012-10-20 22:19:55 +02:00
|
|
|
const QgsFields &fields,
|
2011-09-12 21:08:13 +02:00
|
|
|
QGis::WkbType geometryType,
|
|
|
|
const QgsCoordinateReferenceSystem* crs,
|
|
|
|
bool overwrite = false,
|
2013-01-07 00:30:30 +01:00
|
|
|
const QMap<QString, QVariant> *options = 0,
|
|
|
|
QProgressDialog *progress = 0
|
2011-09-12 21:08:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/** checks whether there were any errors */
|
|
|
|
ImportError hasError();
|
|
|
|
|
|
|
|
/** retrieves error message */
|
|
|
|
QString errorMessage();
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
int errorCount() const;
|
|
|
|
|
2011-09-12 21:08:13 +02:00
|
|
|
/** add feature to the new created layer */
|
|
|
|
bool addFeature( QgsFeature& feature );
|
|
|
|
|
|
|
|
/** close the new created layer */
|
|
|
|
~QgsVectorLayerImport();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** flush the buffer writing the features to the new layer */
|
|
|
|
bool flushBuffer();
|
|
|
|
|
2013-01-28 01:39:58 +01:00
|
|
|
/** create index */
|
|
|
|
bool createSpatialIndex();
|
2011-09-12 21:08:13 +02:00
|
|
|
};
|
|
|
|
|