Quantum GIS API Documentation
1.8
|
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 QgsFieldMap &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *crs, bool overwrite=false, const QMap< QString, QVariant > *options=0) | |
create a empty layer and add fields to it | |
ImportError | hasError () |
checks whether there were any errors | |
QString | errorMessage () |
retrieves error message | |
int | errorCount () const |
bool | addFeature (QgsFeature &feature) |
add feature to the new created layer | |
~QgsVectorLayerImport () | |
close the new created layer | |
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) |
Write contents of vector layer to a different datasource. | |
Protected Member Functions | |
bool | flushBuffer () |
flush the buffer writing the features to the new layer | |
Protected Attributes | |
ImportError | mError |
contains error value | |
QString | mErrorMessage |
int | mErrorCount |
QgsVectorDataProvider * | mProvider |
QMap< int, int > | mOldToNewAttrIdx |
map attribute indexes to new field indexes | |
QgsFeatureList | mFeatureBuffer |
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 34 of file qgsvectorlayerimport.h.
Definition at line 38 of file qgsvectorlayerimport.h.
QgsVectorLayerImport::QgsVectorLayerImport | ( | const QString & | uri, |
const QString & | provider, | ||
const QgsFieldMap & | fields, | ||
QGis::WkbType | geometryType, | ||
const QgsCoordinateReferenceSystem * | crs, | ||
bool | overwrite = false , |
||
const QMap< QString, QVariant > * | options = 0 |
||
) |
create a empty layer and add fields to it
Definition at line 42 of file qgsvectorlayerimport.cpp.
References cast_to_fptr, ErrInvalidLayer, ErrInvalidProvider, ErrProviderUnsupportedFeature, hasError(), QgsProviderRegistry::instance(), QgsDataProvider::isValid(), mError, mErrorMessage, mOldToNewAttrIdx, mProvider, NoError, QgsProviderRegistry::provider(), QgsProviderRegistry::providerLibrary(), and QgsDebugMsg.
Referenced by importLayer().
close the new created layer
Definition at line 101 of file qgsvectorlayerimport.cpp.
References flushBuffer(), and mProvider.
bool QgsVectorLayerImport::addFeature | ( | QgsFeature & | feature | ) |
add feature to the new created layer
Definition at line 119 of file qgsvectorlayerimport.cpp.
References QgsFeature::attributeMap(), FEATURE_BUFFER_SIZE, flushBuffer(), mFeatureBuffer, mOldToNewAttrIdx, QgsDebugMsgLevel, and QgsFeature::setAttributeMap().
Referenced by importLayer().
int QgsVectorLayerImport::errorCount | ( | ) | const [inline] |
Definition at line 82 of file qgsvectorlayerimport.h.
Referenced by importLayer().
QString QgsVectorLayerImport::errorMessage | ( | ) |
retrieves error message
Definition at line 114 of file qgsvectorlayerimport.cpp.
References mErrorMessage.
Referenced by importLayer().
bool QgsVectorLayerImport::flushBuffer | ( | ) | [protected] |
flush the buffer writing the features to the new layer
Definition at line 149 of file qgsvectorlayerimport.cpp.
References QgsVectorDataProvider::addFeatures(), QgsVectorDataProvider::clearErrors(), ErrFeatureWriteFailed, QgsVectorDataProvider::errors(), mError, mErrorCount, mErrorMessage, mFeatureBuffer, mProvider, and QgsDebugMsg.
Referenced by addFeature(), importLayer(), and ~QgsVectorLayerImport().
checks whether there were any errors
Definition at line 109 of file qgsvectorlayerimport.cpp.
References mError.
Referenced by importLayer(), and QgsVectorLayerImport().
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 |
||
) | [static] |
Write contents of vector layer to a different datasource.
Definition at line 178 of file qgsvectorlayerimport.cpp.
References addFeature(), QgsFeature::clearAttributeMap(), QgsMapLayer::crs(), ErrFeatureWriteFailed, ErrInvalidLayer, errorCount(), errorMessage(), ErrProjection, flushBuffer(), QgsFeature::geometry(), hasError(), QgsFeature::id(), QgsCoordinateReferenceSystem::isValid(), QgsMessageLog::logMessage(), QgsVectorLayer::nextFeature(), NoError, QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::pendingFields(), QgsVectorLayer::providerType(), QgsVectorLayerImport(), QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), QgsVectorLayer::storageType(), QgsGeometry::transform(), QgsFeature::typeName(), QgsException::what(), QGis::WKBNoGeometry, and QgsVectorLayer::wkbType().
ImportError QgsVectorLayerImport::mError [protected] |
contains error value
Definition at line 95 of file qgsvectorlayerimport.h.
Referenced by flushBuffer(), hasError(), and QgsVectorLayerImport().
int QgsVectorLayerImport::mErrorCount [protected] |
Definition at line 98 of file qgsvectorlayerimport.h.
Referenced by flushBuffer().
QString QgsVectorLayerImport::mErrorMessage [protected] |
Definition at line 96 of file qgsvectorlayerimport.h.
Referenced by errorMessage(), flushBuffer(), and QgsVectorLayerImport().
QgsFeatureList QgsVectorLayerImport::mFeatureBuffer [protected] |
Definition at line 105 of file qgsvectorlayerimport.h.
Referenced by addFeature(), and flushBuffer().
QMap<int, int> QgsVectorLayerImport::mOldToNewAttrIdx [protected] |
map attribute indexes to new field indexes
Definition at line 103 of file qgsvectorlayerimport.h.
Referenced by addFeature(), and QgsVectorLayerImport().
QgsVectorDataProvider* QgsVectorLayerImport::mProvider [protected] |
Definition at line 100 of file qgsvectorlayerimport.h.
Referenced by flushBuffer(), QgsVectorLayerImport(), and ~QgsVectorLayerImport().