QGIS/python/core/qgsvectorlayerimport.sip

105 lines
3.8 KiB
Plaintext
Raw Normal View History

/**
There are two possibilities how to use this class:
2013-06-23 16:00:16 +02:00
1. static call to QgsVectorFileWriter::writeAsShapefile(...) 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>
class QProgressDialog;
%End
public:
enum ImportError
{
2014-06-02 21:00:51 +02:00
NoError,
ErrDriverNotFound,
ErrCreateDataSource,
ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed,
ErrProjection,
ErrFeatureWriteFailed,
ErrInvalidLayer,
ErrInvalidProvider,
ErrProviderUnsupportedFeature,
ErrConnectionFailed,
ErrUserCancelled, /*!< User cancelled the import*/
};
/**
* Writes the contents of vector layer to a different datasource.
* @param layer source layer
* @param uri URI for destination data source
* @param providerKey string key for destination data provider
* @param destCRS destination CRS, or an invalid (default constructed) CRS if
* not available
* @param onlySelected set to true to export only selected features
* @param errorMessage if non-null, will be set to any error messages
* @param skipAttributeCreation set to true to skip exporting feature attributes
* @param options optional provider dataset options
* @param progress optional progress dialog to show progress of export
* @returns NoError for a successful export, or encountered error
*/
static ImportError importLayer( QgsVectorLayer* layer,
const QString& uri,
const QString& providerKey,
const QgsCoordinateReferenceSystem& destCRS,
bool onlySelected = false,
QString *errorMessage /Out/ = nullptr,
bool skipAttributeCreation = false,
QMap<QString, QVariant> *options = nullptr,
QProgressDialog *progress = nullptr
);
/** Constructor for QgsVectorLayerImport.
* @param uri URI for destination data source
* @param provider string key for destination data provider
* @param fields fields to include in created layer
* @param geometryType destination geometry type
* @param crs desired CRS, or an invalid (default constructed) CRS if
* not available
* @param overwrite set to true to overwrite any existing data source
* @param options optional provider dataset options
* @param progress optional progress dialog to show progress of export
*/
QgsVectorLayerImport( const QString &uri,
const QString &provider,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem& crs,
bool overwrite = false,
const QMap<QString, QVariant> *options = nullptr,
QProgressDialog *progress = nullptr
);
2015-07-29 11:52:14 +02:00
/** Checks whether there were any errors */
ImportError hasError();
2015-07-29 11:52:14 +02:00
/** Retrieves error message */
QString errorMessage();
int errorCount() const;
2015-07-29 11:52:14 +02:00
/** Add feature to the new created layer */
bool addFeature( QgsFeature& feature );
2015-07-29 11:52:14 +02:00
/** Close the new created layer */
~QgsVectorLayerImport();
protected:
2015-07-29 11:52:14 +02:00
/** Flush the buffer writing the features to the new layer */
bool flushBuffer();
2015-07-29 11:52:14 +02:00
/** Create index */
bool createSpatialIndex();
private:
QgsVectorLayerImport( const QgsVectorLayerImport& rh );
};