QGIS API Documentation
2.0.1-Dufour
|
A convenience class for writing vector files to disk. More...
#include <qgsvectorlayerimport.h>
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 | |
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, QProgressDialog *progress=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 | |
bool | createSpatialIndex () |
create index |
Protected Attributes | |
ImportError | mError |
contains error value | |
QString | mErrorMessage |
int | mErrorCount |
QgsVectorDataProvider * | mProvider |
QMap< int, int > | mOldToNewAttrIdx |
map attribute indexes to new field indexes | |
int | mAttributeCount |
QgsFeatureList | mFeatureBuffer |
QProgressDialog * | mProgress |
A convenience class for writing vector files to disk.
There are two possibilities how to use this class:
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.
Definition at line 40 of file qgsvectorlayerimport.h.
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.
References QgsVectorDataProvider::AddFeatures, QgsVectorDataProvider::capabilities(), cast_to_fptr, ErrInvalidLayer, ErrInvalidProvider, ErrProviderUnsupportedFeature, hasError(), QgsProviderRegistry::instance(), QgsDataProvider::isValid(), mAttributeCount, mError, mErrorMessage, mOldToNewAttrIdx, mProvider, NoError, QgsProviderRegistry::provider(), QgsProviderRegistry::providerLibrary(), QgsDebugMsg, and tr.
Referenced by importLayer().
QgsVectorLayerImport::~QgsVectorLayerImport | ( | ) |
close the new created layer
Definition at line 116 of file qgsvectorlayerimport.cpp.
References flushBuffer(), and mProvider.
bool QgsVectorLayerImport::addFeature | ( | QgsFeature & | feature | ) |
add feature to the new created layer
Definition at line 134 of file qgsvectorlayerimport.cpp.
References QgsFeature::attributes(), FEATURE_BUFFER_SIZE, flushBuffer(), QgsFeature::geometry(), QgsFeature::initAttributes(), mAttributeCount, mFeatureBuffer, mOldToNewAttrIdx, QgsDebugMsgLevel, QgsFeature::setAttribute(), and QgsFeature::setGeometry().
Referenced by importLayer().
|
protected |
create index
Definition at line 193 of file qgsvectorlayerimport.cpp.
References QgsVectorDataProvider::capabilities(), QgsVectorDataProvider::CreateSpatialIndex, QgsVectorDataProvider::createSpatialIndex(), and mProvider.
Referenced by importLayer().
|
inline |
Definition at line 85 of file qgsvectorlayerimport.h.
Referenced by importLayer().
QString QgsVectorLayerImport::errorMessage | ( | ) |
retrieves error message
Definition at line 129 of file qgsvectorlayerimport.cpp.
References mErrorMessage.
Referenced by importLayer().
|
protected |
flush the buffer writing the features to the new layer
Definition at line 166 of file qgsvectorlayerimport.cpp.
References QgsVectorDataProvider::addFeatures(), QgsVectorDataProvider::clearErrors(), ErrFeatureWriteFailed, QgsVectorDataProvider::errors(), mError, mErrorCount, mErrorMessage, mFeatureBuffer, mProvider, QgsDebugMsg, and tr.
Referenced by addFeature(), importLayer(), and ~QgsVectorLayerImport().
QgsVectorLayerImport::ImportError QgsVectorLayerImport::hasError | ( | ) |
checks whether there were any errors
Definition at line 124 of file qgsvectorlayerimport.cpp.
References mError.
Referenced by importLayer(), and QgsVectorLayerImport().
|
static |
Write contents of vector layer to a different datasource.
Definition at line 206 of file qgsvectorlayerimport.cpp.
References addFeature(), QgsFields::count(), createSpatialIndex(), QgsMapLayer::crs(), ErrFeatureWriteFailed, ErrInvalidLayer, errorCount(), errorMessage(), ErrProjection, QgsVectorLayer::featureCount(), flushBuffer(), QgsFeature::geometry(), QgsVectorLayer::getFeatures(), hasError(), QgsFeature::id(), QgsFeature::initAttributes(), QgsCoordinateReferenceSystem::isValid(), QgsMessageLog::logMessage(), QgsFeatureIterator::nextFeature(), NoError, QgsFeatureRequest::NoGeometry, QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::pendingFields(), QgsVectorLayer::providerType(), QgsVectorLayerImport(), QgsVectorLayer::selectedFeaturesIds(), QgsFeatureRequest::setFlags(), QgsFeatureRequest::setSubsetOfAttributes(), QgsVectorLayer::storageType(), tr, QgsGeometry::transform(), QgsException::what(), QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBNoGeometry, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, and QgsVectorLayer::wkbType().
|
protected |
Definition at line 110 of file qgsvectorlayerimport.h.
Referenced by addFeature(), and QgsVectorLayerImport().
|
protected |
contains error value
Definition at line 101 of file qgsvectorlayerimport.h.
Referenced by flushBuffer(), hasError(), and QgsVectorLayerImport().
|
protected |
Definition at line 104 of file qgsvectorlayerimport.h.
Referenced by flushBuffer().
|
protected |
Definition at line 102 of file qgsvectorlayerimport.h.
Referenced by errorMessage(), flushBuffer(), and QgsVectorLayerImport().
|
protected |
Definition at line 112 of file qgsvectorlayerimport.h.
Referenced by addFeature(), and flushBuffer().
|
protected |
map attribute indexes to new field indexes
Definition at line 109 of file qgsvectorlayerimport.h.
Referenced by addFeature(), and QgsVectorLayerImport().
|
protected |
Definition at line 113 of file qgsvectorlayerimport.h.
|
protected |
Definition at line 106 of file qgsvectorlayerimport.h.
Referenced by createSpatialIndex(), flushBuffer(), QgsVectorLayerImport(), and ~QgsVectorLayerImport().