QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
}

Public Member Functions

 QgsVectorLayerImport (const QString &uri, const QString &provider, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *crs, bool overwrite=false, const QMap< QString, QVariant > *options=0, QProgressDialog *progress=0)
 create a empty layer and add fields to it
 ~QgsVectorLayerImport ()
 close the new created layer
bool addFeature (QgsFeature &feature)
 add feature to the new created layer
int errorCount () const
QString errorMessage ()
 retrieves error message
ImportError hasError ()
 checks whether there were any errors

Static Public Member Functions

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

Protected Member Functions

bool createSpatialIndex ()
 create index
bool flushBuffer ()
 flush the buffer writing the features to the new layer

Protected Attributes

int mAttributeCount
ImportError mError
 contains error value
int mErrorCount
QString mErrorMessage
QgsFeatureList mFeatureBuffer
QMap< int, int > mOldToNewAttrIdx
 map attribute indexes to new field indexes
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(...)

Currently supports only writing to shapefiles, but shouldn't be a problem to add capability to support other OGR-writable formats.

Definition at line 36 of file qgsvectorlayerimport.h.

Member Enumeration Documentation

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

Definition at line 40 of file qgsvectorlayerimport.h.

Constructor & Destructor Documentation

QgsVectorLayerImport::QgsVectorLayerImport ( const QString &  uri,
const QString &  provider,
const QgsFields fields,
QGis::WkbType  geometryType,
const QgsCoordinateReferenceSystem crs,
bool  overwrite = false,
const QMap< QString, QVariant > *  options = 0,
QProgressDialog *  progress = 0 
)

create a empty layer and add fields to it

Definition at line 45 of file qgsvectorlayerimport.cpp.

QgsVectorLayerImport::~QgsVectorLayerImport ( )

close the new created layer

Definition at line 116 of file qgsvectorlayerimport.cpp.

Member Function Documentation

bool QgsVectorLayerImport::addFeature ( QgsFeature feature)

add feature to the new created layer

Definition at line 134 of file qgsvectorlayerimport.cpp.

bool QgsVectorLayerImport::createSpatialIndex ( )
protected

create index

Definition at line 193 of file qgsvectorlayerimport.cpp.

int QgsVectorLayerImport::errorCount ( ) const
inline

Definition at line 85 of file qgsvectorlayerimport.h.

QString QgsVectorLayerImport::errorMessage ( )

retrieves error message

Definition at line 129 of file qgsvectorlayerimport.cpp.

bool QgsVectorLayerImport::flushBuffer ( )
protected

flush the buffer writing the features to the new layer

Definition at line 166 of file qgsvectorlayerimport.cpp.

QgsVectorLayerImport::ImportError QgsVectorLayerImport::hasError ( )

checks whether there were any errors

Definition at line 124 of file qgsvectorlayerimport.cpp.

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

Write contents of vector layer to a different datasource.

Definition at line 206 of file qgsvectorlayerimport.cpp.

Member Data Documentation

int QgsVectorLayerImport::mAttributeCount
protected

Definition at line 110 of file qgsvectorlayerimport.h.

ImportError QgsVectorLayerImport::mError
protected

contains error value

Definition at line 101 of file qgsvectorlayerimport.h.

int QgsVectorLayerImport::mErrorCount
protected

Definition at line 104 of file qgsvectorlayerimport.h.

QString QgsVectorLayerImport::mErrorMessage
protected

Definition at line 102 of file qgsvectorlayerimport.h.

QgsFeatureList QgsVectorLayerImport::mFeatureBuffer
protected

Definition at line 112 of file qgsvectorlayerimport.h.

QMap<int, int> QgsVectorLayerImport::mOldToNewAttrIdx
protected

map attribute indexes to new field indexes

Definition at line 109 of file qgsvectorlayerimport.h.

QProgressDialog* QgsVectorLayerImport::mProgress
protected

Definition at line 113 of file qgsvectorlayerimport.h.

QgsVectorDataProvider* QgsVectorLayerImport::mProvider
protected

Definition at line 106 of file qgsvectorlayerimport.h.


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