Quantum GIS API Documentation
1.8
|
A convenience class for writing vector files to disk. More...
#include <qgsvectorfilewriter.h>
Public Types | |
enum | WriterError { NoError = 0, ErrDriverNotFound, ErrCreateDataSource, ErrCreateLayer, ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed, ErrInvalidLayer } |
Public Member Functions | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFieldMap &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *srs, const QString &driverName="ESRI Shapefile", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=0) | |
create shapefile and initialize it | |
WriterError | hasError () |
checks whether there were any errors in constructor | |
QString | errorMessage () |
retrieves error message | |
bool | addFeature (QgsFeature &feature) |
add feature to the currently opened shapefile | |
QMap< int, int > | attrIdxToOgrIdx () |
~QgsVectorFileWriter () | |
close opened shapefile for writing | |
Static Public Member Functions | |
static Q_DECL_DEPRECATED WriterError | writeAsShapefile (QgsVectorLayer *layer, const QString &shapefileName, const QString &fileEncoding, const QgsCoordinateReferenceSystem *destCRS, bool onlySelected=false, QString *errorMessage=0, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) |
Write contents of vector layer to a shapefile. | |
static WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateReferenceSystem *destCRS, const QString &driverName="ESRI Shapefile", bool onlySelected=false, QString *errorMessage=0, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=0) |
Write contents of vector layer to an (OGR supported) vector formt. | |
static QMap< QString, QString > | supportedFiltersAndFormats () |
Returns map with format filter string as key and OGR format key as value. | |
static QMap< QString, QString > | ogrDriverList () |
Returns driver list that can be used for dialogs. | |
static QString | fileFilterString () |
Returns filter string that can be used for dialogs. | |
static QString | filterForDriver (const QString &driverName) |
Creates a filter for an OGR driver key. | |
static bool | deleteShapeFile (QString theFileName) |
Delete a shapefile (and its accompanying shx / dbf / prf) | |
Protected Member Functions | |
OGRGeometryH | createEmptyGeometry (QGis::WkbType wkbType) |
Protected Attributes | |
OGRDataSourceH | mDS |
OGRLayerH | mLayer |
OGRGeometryH | mGeom |
QgsFieldMap | mFields |
WriterError | mError |
contains error value if construction was not successful | |
QString | mErrorMessage |
QTextCodec * | mCodec |
QGis::WkbType | mWkbType |
geometry type which is being used | |
QMap< int, int > | mAttrIdxToOgrIdx |
map attribute indizes to OGR field indexes | |
Static Private Member Functions | |
static bool | driverMetadata (QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext) |
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 42 of file qgsvectorfilewriter.h.
NoError | |
ErrDriverNotFound | |
ErrCreateDataSource | |
ErrCreateLayer | |
ErrAttributeTypeUnsupported | |
ErrAttributeCreationFailed | |
ErrProjection | |
ErrFeatureWriteFailed | |
ErrInvalidLayer |
Definition at line 46 of file qgsvectorfilewriter.h.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFieldMap & | fields, | ||
QGis::WkbType | geometryType, | ||
const QgsCoordinateReferenceSystem * | srs, | ||
const QString & | driverName = "ESRI Shapefile" , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() , |
||
QString * | newFilename = 0 |
||
) |
create shapefile and initialize it
Definition at line 55 of file qgsvectorfilewriter.cpp.
References createEmptyGeometry(), deleteShapeFile(), driverMetadata(), ErrAttributeCreationFailed, ErrAttributeTypeUnsupported, ErrCreateDataSource, ErrCreateLayer, ErrDriverNotFound, QgsField::length(), mAttrIdxToOgrIdx, mCodec, mDS, mError, mErrorMessage, mFields, mGeom, mLayer, mWkbType, QgsField::name(), QgsDebugMsg, QgsApplication::registerOgrDrivers(), TO8, TO8F, QgsCoordinateReferenceSystem::toWkt(), QgsField::type(), and QGis::WKBNoGeometry.
Referenced by writeAsVectorFormat().
close opened shapefile for writing
Definition at line 557 of file qgsvectorfilewriter.cpp.
bool QgsVectorFileWriter::addFeature | ( | QgsFeature & | feature | ) |
add feature to the currently opened shapefile
Definition at line 413 of file qgsvectorfilewriter.cpp.
References QgsGeometry::asWkb(), QgsFeature::attributeMap(), createEmptyGeometry(), ErrFeatureWriteFailed, FID_TO_NUMBER, QgsFeature::geometry(), QgsFeature::id(), QgsMessageLog::logMessage(), mAttrIdxToOgrIdx, MathUtils::max(), mCodec, mError, mErrorMessage, mFields, mGeom, mLayer, mWkbType, QgsDebugMsg, QGis::WKBNoGeometry, QgsGeometry::wkbSize(), and QgsGeometry::wkbType().
Referenced by QgsGeometryAnalyzer::addEventLayerFeature(), QgsGeometryAnalyzer::bufferFeature(), QgsGeometryAnalyzer::centroidFeature(), QgsOverlayAnalyzer::intersectFeature(), QgsGeometryAnalyzer::simplifyFeature(), and writeAsVectorFormat().
QMap<int, int> QgsVectorFileWriter::attrIdxToOgrIdx | ( | ) | [inline] |
Definition at line 121 of file qgsvectorfilewriter.h.
OGRGeometryH QgsVectorFileWriter::createEmptyGeometry | ( | QGis::WkbType | wkbType | ) | [protected] |
Definition at line 397 of file qgsvectorfilewriter.cpp.
Referenced by addFeature(), and QgsVectorFileWriter().
bool QgsVectorFileWriter::deleteShapeFile | ( | QString | theFileName | ) | [static] |
Delete a shapefile (and its accompanying shx / dbf / prf)
theFileName | /path/to/file.shp |
Definition at line 734 of file qgsvectorfilewriter.cpp.
References file, and QgsDebugMsg.
Referenced by QgsVectorFileWriter().
bool QgsVectorFileWriter::driverMetadata | ( | QString | driverName, |
QString & | longName, | ||
QString & | trLongName, | ||
QString & | glob, | ||
QString & | ext | ||
) | [static, private] |
Definition at line 843 of file qgsvectorfilewriter.cpp.
Referenced by filterForDriver(), ogrDriverList(), and QgsVectorFileWriter().
QString QgsVectorFileWriter::errorMessage | ( | ) |
retrieves error message
Definition at line 408 of file qgsvectorfilewriter.cpp.
References mErrorMessage.
Referenced by writeAsVectorFormat().
QString QgsVectorFileWriter::fileFilterString | ( | ) | [static] |
Returns filter string that can be used for dialogs.
Definition at line 816 of file qgsvectorfilewriter.cpp.
References supportedFiltersAndFormats().
QString QgsVectorFileWriter::filterForDriver | ( | const QString & | driverName | ) | [static] |
Creates a filter for an OGR driver key.
Definition at line 831 of file qgsvectorfilewriter.cpp.
References driverMetadata().
Referenced by supportedFiltersAndFormats().
checks whether there were any errors in constructor
Definition at line 403 of file qgsvectorfilewriter.cpp.
References mError.
Referenced by writeAsVectorFormat().
QMap< QString, QString > QgsVectorFileWriter::ogrDriverList | ( | ) | [static] |
Returns driver list that can be used for dialogs.
Definition at line 786 of file qgsvectorfilewriter.cpp.
References driverMetadata(), and QgsApplication::registerOgrDrivers().
QMap< QString, QString > QgsVectorFileWriter::supportedFiltersAndFormats | ( | ) | [static] |
Returns map with format filter string as key and OGR format key as value.
Definition at line 759 of file qgsvectorfilewriter.cpp.
References filterForDriver(), and QgsApplication::registerOgrDrivers().
Referenced by fileFilterString().
QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsShapefile | ( | QgsVectorLayer * | layer, |
const QString & | shapefileName, | ||
const QString & | fileEncoding, | ||
const QgsCoordinateReferenceSystem * | destCRS, | ||
bool | onlySelected = false , |
||
QString * | errorMessage = 0 , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() |
||
) | [static] |
Write contents of vector layer to a shapefile.
Definition at line 574 of file qgsvectorfilewriter.cpp.
References writeAsVectorFormat().
QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat | ( | QgsVectorLayer * | layer, |
const QString & | fileName, | ||
const QString & | fileEncoding, | ||
const QgsCoordinateReferenceSystem * | destCRS, | ||
const QString & | driverName = "ESRI Shapefile" , |
||
bool | onlySelected = false , |
||
QString * | errorMessage = 0 , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() , |
||
bool | skipAttributeCreation = false , |
||
QString * | newFilename = 0 |
||
) | [static] |
Write contents of vector layer to an (OGR supported) vector formt.
Definition at line 587 of file qgsvectorfilewriter.cpp.
References addFeature(), QgsFeature::clearAttributeMap(), QgsMapLayer::crs(), ErrFeatureWriteFailed, ErrInvalidLayer, errorMessage(), ErrProjection, QgsFeature::geometry(), hasError(), QgsFeature::id(), QgsCoordinateReferenceSystem::isValid(), QgsVectorLayer::nextFeature(), NoError, QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::pendingFields(), QgsVectorFileWriter(), QgsVectorLayer::select(), QgsVectorLayer::selectedFeaturesIds(), QgsGeometry::transform(), QgsFeature::typeName(), QgsLogger::warning(), QgsException::what(), QGis::WKBNoGeometry, and QgsVectorLayer::wkbType().
Referenced by writeAsShapefile().
QMap<int, int> QgsVectorFileWriter::mAttrIdxToOgrIdx [protected] |
map attribute indizes to OGR field indexes
Definition at line 152 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and QgsVectorFileWriter().
QTextCodec* QgsVectorFileWriter::mCodec [protected] |
Definition at line 146 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and QgsVectorFileWriter().
OGRDataSourceH QgsVectorFileWriter::mDS [protected] |
Definition at line 136 of file qgsvectorfilewriter.h.
Referenced by QgsVectorFileWriter(), and ~QgsVectorFileWriter().
WriterError QgsVectorFileWriter::mError [protected] |
contains error value if construction was not successful
Definition at line 143 of file qgsvectorfilewriter.h.
Referenced by addFeature(), hasError(), and QgsVectorFileWriter().
QString QgsVectorFileWriter::mErrorMessage [protected] |
Definition at line 144 of file qgsvectorfilewriter.h.
Referenced by addFeature(), errorMessage(), and QgsVectorFileWriter().
QgsFieldMap QgsVectorFileWriter::mFields [protected] |
Definition at line 140 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and QgsVectorFileWriter().
OGRGeometryH QgsVectorFileWriter::mGeom [protected] |
Definition at line 138 of file qgsvectorfilewriter.h.
Referenced by addFeature(), QgsVectorFileWriter(), and ~QgsVectorFileWriter().
OGRLayerH QgsVectorFileWriter::mLayer [protected] |
Definition at line 137 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and QgsVectorFileWriter().
QGis::WkbType QgsVectorFileWriter::mWkbType [protected] |
geometry type which is being used
Definition at line 149 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and QgsVectorFileWriter().