QGIS API Documentation  2.99.0-Master (37c43df)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsVectorLayerImport Class Reference

A convenience class for writing vector files to disk. More...

#include <qgsvectorlayerimport.h>

Public Types

enum  ImportError {
  NoError = 0, ErrDriverNotFound, ErrCreateDataSource, ErrCreateLayer,
  ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed,
  ErrInvalidLayer, ErrInvalidProvider, ErrProviderUnsupportedFeature, ErrConnectionFailed,
  ErrUserCancelled
}
 

Public Member Functions

 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)
 Constructor for QgsVectorLayerImport. More...
 
 ~QgsVectorLayerImport ()
 Close the new created layer. More...
 
bool addFeature (QgsFeature &feature)
 Add feature to the new created layer. More...
 
int errorCount () const
 
QString errorMessage ()
 Retrieves error message. More...
 
ImportError hasError ()
 Checks whether there were any errors. More...
 

Static Public Member Functions

static ImportError importLayer (QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem &destCRS, bool onlySelected=false, QString *errorMessage=nullptr, bool skipAttributeCreation=false, QMap< QString, QVariant > *options=nullptr, QProgressDialog *progress=nullptr)
 Writes the contents of vector layer to a different datasource. More...
 

Protected Member Functions

bool createSpatialIndex ()
 Create index. More...
 
bool flushBuffer ()
 Flush the buffer writing the features to the new layer. More...
 

Protected Attributes

int mAttributeCount
 
ImportError mError
 Contains error value. More...
 
int mErrorCount
 
QString mErrorMessage
 
QgsFeatureList mFeatureBuffer
 
QMap< int, int > mOldToNewAttrIdx
 Map attribute indexes to new field indexes. More...
 
QProgressDialog * mProgress
 
QgsVectorDataProvidermProvider
 

Detailed Description

A convenience class for writing vector files to disk.

There are two possibilities how to use this class:

  1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer
  2. create an instance of the class and issue calls to addFeature(...)

Definition at line 35 of file qgsvectorlayerimport.h.

Member Enumeration Documentation

§ ImportError

Enumerator
NoError 
ErrDriverNotFound 
ErrCreateDataSource 
ErrCreateLayer 
ErrAttributeTypeUnsupported 
ErrAttributeCreationFailed 
ErrProjection 
ErrFeatureWriteFailed 
ErrInvalidLayer 
ErrInvalidProvider 
ErrProviderUnsupportedFeature 
ErrConnectionFailed 
ErrUserCancelled 

User cancelled the import.

Definition at line 39 of file qgsvectorlayerimport.h.

Constructor & Destructor Documentation

§ QgsVectorLayerImport()

QgsVectorLayerImport::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 
)

Constructor for QgsVectorLayerImport.

Parameters
uriURI for destination data source
providerstring key for destination data provider
fieldsfields to include in created layer
geometryTypedestination geometry type
crsdesired CRS, or an invalid (default constructed) CRS if not available
overwriteset to true to overwrite any existing data source
optionsoptional provider dataset options
progressoptional progress dialog to show progress of export

Definition at line 49 of file qgsvectorlayerimport.cpp.

§ ~QgsVectorLayerImport()

QgsVectorLayerImport::~QgsVectorLayerImport ( )

Close the new created layer.

Definition at line 120 of file qgsvectorlayerimport.cpp.

Member Function Documentation

§ addFeature()

bool QgsVectorLayerImport::addFeature ( QgsFeature feature)

Add feature to the new created layer.

Definition at line 138 of file qgsvectorlayerimport.cpp.

§ createSpatialIndex()

bool QgsVectorLayerImport::createSpatialIndex ( )
protected

Create index.

Definition at line 197 of file qgsvectorlayerimport.cpp.

§ errorCount()

int QgsVectorLayerImport::errorCount ( ) const
inline

Definition at line 108 of file qgsvectorlayerimport.h.

§ errorMessage()

QString QgsVectorLayerImport::errorMessage ( )

Retrieves error message.

Definition at line 133 of file qgsvectorlayerimport.cpp.

§ flushBuffer()

bool QgsVectorLayerImport::flushBuffer ( )
protected

Flush the buffer writing the features to the new layer.

Definition at line 170 of file qgsvectorlayerimport.cpp.

§ hasError()

QgsVectorLayerImport::ImportError QgsVectorLayerImport::hasError ( )

Checks whether there were any errors.

Definition at line 128 of file qgsvectorlayerimport.cpp.

§ importLayer()

QgsVectorLayerImport::ImportError QgsVectorLayerImport::importLayer ( QgsVectorLayer layer,
const QString &  uri,
const QString &  providerKey,
const QgsCoordinateReferenceSystem destCRS,
bool  onlySelected = false,
QString *  errorMessage = nullptr,
bool  skipAttributeCreation = false,
QMap< QString, QVariant > *  options = nullptr,
QProgressDialog *  progress = nullptr 
)
static

Writes the contents of vector layer to a different datasource.

Parameters
layersource layer
uriURI for destination data source
providerKeystring key for destination data provider
destCRSdestination CRS, or an invalid (default constructed) CRS if not available
onlySelectedset to true to export only selected features
errorMessageif non-null, will be set to any error messages
skipAttributeCreationset to true to skip exporting feature attributes
optionsoptional provider dataset options
progressoptional progress dialog to show progress of export
Returns
NoError for a successful export, or encountered error

Definition at line 210 of file qgsvectorlayerimport.cpp.

Member Data Documentation

§ mAttributeCount

int QgsVectorLayerImport::mAttributeCount
protected

Definition at line 133 of file qgsvectorlayerimport.h.

§ mError

ImportError QgsVectorLayerImport::mError
protected

Contains error value.

Definition at line 124 of file qgsvectorlayerimport.h.

§ mErrorCount

int QgsVectorLayerImport::mErrorCount
protected

Definition at line 127 of file qgsvectorlayerimport.h.

§ mErrorMessage

QString QgsVectorLayerImport::mErrorMessage
protected

Definition at line 125 of file qgsvectorlayerimport.h.

§ mFeatureBuffer

QgsFeatureList QgsVectorLayerImport::mFeatureBuffer
protected

Definition at line 135 of file qgsvectorlayerimport.h.

§ mOldToNewAttrIdx

QMap<int, int> QgsVectorLayerImport::mOldToNewAttrIdx
protected

Map attribute indexes to new field indexes.

Definition at line 132 of file qgsvectorlayerimport.h.

§ mProgress

QProgressDialog* QgsVectorLayerImport::mProgress
protected

Definition at line 136 of file qgsvectorlayerimport.h.

§ mProvider

QgsVectorDataProvider* QgsVectorLayerImport::mProvider
protected

Definition at line 129 of file qgsvectorlayerimport.h.


The documentation for this class was generated from the following files: