QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 More...
 
ImportError hasError ()
 checks whether there were any errors More...
 
QString errorMessage ()
 retrieves error message More...
 
int errorCount () const
 
bool addFeature (QgsFeature &feature)
 add feature to the new created layer More...
 
 ~QgsVectorLayerImport ()
 close the new created layer More...
 

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. More...
 

Protected Member Functions

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

Protected Attributes

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

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.

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

QgsVectorLayerImport::~QgsVectorLayerImport ( )

close the new created layer

Member Function Documentation

bool QgsVectorLayerImport::addFeature ( QgsFeature feature)

add feature to the new created layer

bool QgsVectorLayerImport::createSpatialIndex ( )
protected

create index

int QgsVectorLayerImport::errorCount ( ) const
inline
QString QgsVectorLayerImport::errorMessage ( )

retrieves error message

bool QgsVectorLayerImport::flushBuffer ( )
protected

flush the buffer writing the features to the new layer

QgsVectorLayerImport::ImportError QgsVectorLayerImport::hasError ( )

checks whether there were any errors

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.

Member Data Documentation

int QgsVectorLayerImport::mAttributeCount
protected
ImportError QgsVectorLayerImport::mError
protected

contains error value

int QgsVectorLayerImport::mErrorCount
protected
QString QgsVectorLayerImport::mErrorMessage
protected
QgsFeatureList QgsVectorLayerImport::mFeatureBuffer
protected
QMap<int, int> QgsVectorLayerImport::mOldToNewAttrIdx
protected

map attribute indexes to new field indexes

QProgressDialog* QgsVectorLayerImport::mProgress
protected
QgsVectorDataProvider* QgsVectorLayerImport::mProvider
protected

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