QGIS API Documentation
2.2.0-Valmiera
|
A convenience class for writing vector files to disk. More...
#include <qgsvectorfilewriter.h>
Classes | |
class | BoolOption |
class | HiddenOption |
class | IntOption |
struct | MetaData |
class | Option |
class | SetOption |
class | StringOption |
Public Types | |
enum | OptionType { Set, String, Int, Hidden } |
enum | WriterError { NoError = 0, ErrDriverNotFound, ErrCreateDataSource, ErrCreateLayer, ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed, ErrInvalidLayer } |
enum | SymbologyExport { NoSymbology = 0, FeatureSymbology, SymbolLayerSymbology } |
Public Member Functions | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *srs, const QString &driverName="ESRI Shapefile", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=0, SymbologyExport symbologyExport=NoSymbology) | |
create shapefile and initialize it | |
WriterError | hasError () |
checks whether there were any errors in constructor | |
QString | errorMessage () |
retrieves error message | |
bool | addFeature (QgsFeature &feature, QgsFeatureRendererV2 *renderer=0, QGis::UnitType outputUnit=QGis::Meters) |
add feature to the currently opened shapefile | |
QMap< int, int > | attrIdxToOgrIdx () |
~QgsVectorFileWriter () | |
close opened shapefile for writing | |
SymbologyExport | symbologyExport () const |
void | setSymbologyExport (SymbologyExport symExport) |
double | symbologyScaleDenominator () const |
void | setSymbologyScaleDenominator (double d) |
Static Public Member Functions | |
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, SymbologyExport symbologyExport=NoSymbology, double symbologyScale=1.0) |
Write contents of vector layer to an (OGR supported) vector formt. | |
static WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateTransform *ct, 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, SymbologyExport symbologyExport=NoSymbology, double symbologyScale=1.0) |
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 QString | convertCodecNameForEncodingOption (const QString &codecName) |
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile. | |
static bool | deleteShapeFile (QString theFileName) |
Delete a shapefile (and its accompanying shx / dbf / prf) | |
static bool | driverMetadata (const QString &driverName, MetaData &driverMetadata) |
Protected Member Functions | |
OGRGeometryH | createEmptyGeometry (QGis::WkbType wkbType) |
Protected Attributes | |
OGRDataSourceH | mDS |
OGRLayerH | mLayer |
OGRGeometryH | mGeom |
QgsFields | 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 | |
SymbologyExport | mSymbologyExport |
double | mSymbologyScaleDenominator |
Scale for symbology export (e.g. |
Private Member Functions | |
void | createSymbolLayerTable (QgsVectorLayer *vl, const QgsCoordinateTransform *ct, OGRDataSourceH ds) |
OGRFeatureH | createFeature (QgsFeature &feature) |
bool | writeFeature (OGRLayerH layer, OGRFeatureH feature) |
WriterError | exportFeaturesSymbolLevels (QgsVectorLayer *layer, QgsFeatureIterator &fit, const QgsCoordinateTransform *ct, QString *errorMessage=0) |
Writes features considering symbol level order. | |
double | mmScaleFactor (double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits) |
double | mapUnitScaleFactor (double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits) |
QgsRenderContext | renderContext () const |
void | startRender (QgsVectorLayer *vl) const |
void | stopRender (QgsVectorLayer *vl) const |
QgsFeatureRendererV2 * | symbologyRenderer (QgsVectorLayer *vl) const |
void | addRendererAttributes (QgsVectorLayer *vl, QgsAttributeList &attList) |
Adds attributes needed for classification. |
Static Private Member Functions | |
static QMap< QString, MetaData > | initMetaData () |
static bool | driverMetadata (QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext) |
Static Private Attributes | |
static QMap< QString, MetaData > | sDriverMetadata |
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 42 of file qgsvectorfilewriter.h.
Definition at line 45 of file qgsvectorfilewriter.h.
Definition at line 157 of file qgsvectorfilewriter.h.
NoError | |
ErrDriverNotFound | |
ErrCreateDataSource | |
ErrCreateLayer | |
ErrAttributeTypeUnsupported | |
ErrAttributeCreationFailed | |
ErrProjection | |
ErrFeatureWriteFailed | |
ErrInvalidLayer |
Definition at line 143 of file qgsvectorfilewriter.h.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFields & | fields, | ||
QGis::WkbType | geometryType, | ||
const QgsCoordinateReferenceSystem * | srs, | ||
const QString & | driverName = "ESRI Shapefile" , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() , |
||
QString * | newFilename = 0 , |
||
SymbologyExport | symbologyExport = NoSymbology |
||
) |
create shapefile and initialize it
Definition at line 57 of file qgsvectorfilewriter.cpp.
References convertCodecNameForEncodingOption(), QgsFields::count(), createEmptyGeometry(), deleteShapeFile(), driverMetadata(), ErrAttributeCreationFailed, ErrAttributeTypeUnsupported, ErrCreateDataSource, ErrCreateLayer, ErrDriverNotFound, QgsField::length(), QgsMessageLog::logMessage(), mAttrIdxToOgrIdx, mCodec, mDS, mError, mErrorMessage, mFields, mGeom, mLayer, mWkbType, QgsField::name(), QgsField::precision(), QgsDebugMsg, QgsApplication::registerOgrDrivers(), QgsFields::size(), TO8F, QgsCoordinateReferenceSystem::toWkt(), tr, QgsField::type(), and QGis::WKBNoGeometry.
Referenced by writeAsVectorFormat().
QgsVectorFileWriter::~QgsVectorFileWriter | ( | ) |
close opened shapefile for writing
Definition at line 1768 of file qgsvectorfilewriter.cpp.
bool QgsVectorFileWriter::addFeature | ( | QgsFeature & | feature, |
QgsFeatureRendererV2 * | renderer = 0 , |
||
QGis::UnitType | outputUnit = QGis::Meters |
||
) |
add feature to the currently opened shapefile
Definition at line 1547 of file qgsvectorfilewriter.cpp.
References createFeature(), FeatureSymbology, mapUnitScaleFactor(), mLayer, mmScaleFactor(), mSymbologyExport, mSymbologyScaleDenominator, NoSymbology, SymbolLayerSymbology, QgsFeatureRendererV2::symbolsForFeature(), and writeFeature().
Referenced by QgsGeometryAnalyzer::addEventLayerFeature(), QgsPointSample::addSamplePoints(), QgsGeometryAnalyzer::bufferFeature(), QgsGeometryAnalyzer::centroidFeature(), QgsTransectSample::createSample(), QgsOverlayAnalyzer::intersectFeature(), QgsGeometryAnalyzer::simplifyFeature(), and writeAsVectorFormat().
|
private |
Adds attributes needed for classification.
Definition at line 2629 of file qgsvectorfilewriter.cpp.
References QgsVectorLayer::fieldNameIndex(), index, symbologyRenderer(), and QgsFeatureRendererV2::usedAttributes().
Referenced by writeAsVectorFormat().
|
inline |
Definition at line 253 of file qgsvectorfilewriter.h.
|
static |
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.
Definition at line 2166 of file qgsvectorfilewriter.cpp.
Referenced by QgsVectorFileWriter().
|
protected |
Definition at line 483 of file qgsvectorfilewriter.cpp.
Referenced by createFeature(), and QgsVectorFileWriter().
|
private |
Definition at line 1611 of file qgsvectorfilewriter.cpp.
References QgsGeometry::asWkb(), QgsFeature::attribute(), QgsGeometry::convertToMultiType(), QgsFields::count(), createEmptyGeometry(), ErrFeatureWriteFailed, FID_TO_NUMBER, QgsFeature::geometry(), QgsFeature::id(), QgsMessageLog::logMessage(), mAttrIdxToOgrIdx, MathUtils::max(), mCodec, mError, mErrorMessage, mFields, mGeom, mLayer, mWkbType, QgsDebugMsg, QGis::singleType(), tr, QGis::WKBNoGeometry, QgsGeometry::wkbSize(), and QgsGeometry::wkbType().
Referenced by addFeature(), and exportFeaturesSymbolLevels().
|
private |
Definition at line 2363 of file qgsvectorfilewriter.cpp.
References QgsMapLayer::crs(), QgsCoordinateTransform::destCRS(), QgsCoordinateReferenceSystem::mapUnits(), mapUnitScaleFactor(), mmScaleFactor(), mSymbologyScaleDenominator, QgsVectorLayer::rendererV2(), and QgsFeatureRendererV2::symbols().
|
static |
Delete a shapefile (and its accompanying shx / dbf / prf)
theFileName | /path/to/file.shp |
Definition at line 2015 of file qgsvectorfilewriter.cpp.
References file, and QgsDebugMsg.
Referenced by QgsPointSample::createRandomPoints(), and QgsVectorFileWriter().
|
static |
Definition at line 1518 of file qgsvectorfilewriter.cpp.
References initMetaData(), and sDriverMetadata.
Referenced by filterForDriver(), initMetaData(), ogrDriverList(), and QgsVectorFileWriter().
|
staticprivate |
QString QgsVectorFileWriter::errorMessage | ( | ) |
retrieves error message
Definition at line 1542 of file qgsvectorfilewriter.cpp.
References mErrorMessage.
Referenced by writeAsVectorFormat().
|
private |
Writes features considering symbol level order.
Definition at line 2410 of file qgsvectorfilewriter.cpp.
References createFeature(), QgsMapLayer::crs(), QgsCoordinateTransform::destCRS(), ErrFeatureWriteFailed, ErrProjection, QgsFeature::geometry(), QgsSymbolV2LevelItem::layer(), QgsCoordinateReferenceSystem::mapUnits(), mapUnitScaleFactor(), mLayer, mmScaleFactor(), mSymbologyScaleDenominator, QgsFeatureIterator::nextFeature(), NoError, QgsVectorLayer::rendererV2(), QgsSymbolLayerV2::renderingPass(), startRender(), stopRender(), QgsSymbolV2LevelItem::symbol(), QgsFeatureRendererV2::symbolForFeature(), QgsSymbolV2::symbolLayer(), QgsSymbolV2::symbolLayerCount(), QgsFeatureRendererV2::symbols(), tr, QgsGeometry::transform(), QgsLogger::warning(), QgsException::what(), and writeFeature().
Referenced by writeAsVectorFormat().
|
static |
Returns filter string that can be used for dialogs.
Definition at line 2139 of file qgsvectorfilewriter.cpp.
References supportedFiltersAndFormats().
|
static |
Creates a filter for an OGR driver key.
Definition at line 2154 of file qgsvectorfilewriter.cpp.
References driverMetadata().
Referenced by supportedFiltersAndFormats().
QgsVectorFileWriter::WriterError QgsVectorFileWriter::hasError | ( | ) |
checks whether there were any errors in constructor
Definition at line 1537 of file qgsvectorfilewriter.cpp.
References mError.
Referenced by QgsPointSample::createRandomPoints(), QgsTransectSample::createSample(), and writeAsVectorFormat().
|
staticprivate |
Definition at line 488 of file qgsvectorfilewriter.cpp.
References driverMetadata(), and tr.
Referenced by driverMetadata().
|
private |
Definition at line 2568 of file qgsvectorfilewriter.cpp.
References QgsSymbolV2::MapUnit, QGis::Meters, and QgsSymbolV2::MM.
Referenced by addFeature(), createSymbolLayerTable(), and exportFeaturesSymbolLevels().
|
private |
Definition at line 2550 of file qgsvectorfilewriter.cpp.
References QGis::Meters, and QgsSymbolV2::MM.
Referenced by addFeature(), createSymbolLayerTable(), and exportFeaturesSymbolLevels().
|
static |
Returns driver list that can be used for dialogs.
It contains all OGR drivers
Definition at line 2067 of file qgsvectorfilewriter.cpp.
References driverMetadata(), QgsApplication::registerOgrDrivers(), and TO8F.
|
private |
Definition at line 2584 of file qgsvectorfilewriter.cpp.
References mSymbologyScaleDenominator, and QgsRenderContext::setRendererScale().
Referenced by startRender(), and stopRender().
|
inline |
Definition at line 265 of file qgsvectorfilewriter.h.
|
inline |
Definition at line 268 of file qgsvectorfilewriter.h.
Referenced by writeAsVectorFormat().
|
private |
Definition at line 2591 of file qgsvectorfilewriter.cpp.
References renderContext(), QgsFeatureRendererV2::startRender(), and symbologyRenderer().
Referenced by exportFeaturesSymbolLevels(), and writeAsVectorFormat().
|
private |
Definition at line 2603 of file qgsvectorfilewriter.cpp.
References renderContext(), QgsFeatureRendererV2::stopRender(), and symbologyRenderer().
Referenced by exportFeaturesSymbolLevels(), and writeAsVectorFormat().
|
static |
Returns map with format filter string as key and OGR format key as value.
Definition at line 2040 of file qgsvectorfilewriter.cpp.
References filterForDriver(), and QgsApplication::registerOgrDrivers().
Referenced by fileFilterString().
|
inline |
Definition at line 264 of file qgsvectorfilewriter.h.
Referenced by writeAsVectorFormat().
|
private |
Definition at line 2615 of file qgsvectorfilewriter.cpp.
References mSymbologyExport, NoSymbology, and QgsVectorLayer::rendererV2().
Referenced by addRendererAttributes(), startRender(), and stopRender().
|
inline |
Definition at line 267 of file qgsvectorfilewriter.h.
|
static |
Write contents of vector layer to an (OGR supported) vector formt.
@note: this method was added in version 1.5
layer | layer to write |
fileName | file name to write to |
fileEncoding | encoding to use |
destCRS | pointer to CRS to reproject exported geometries to |
driverName | OGR driver to use |
onlySelected | write only selected features of layer |
errorMessage | pointer to buffer fo error message |
datasourceOptions | list of OGR data source creation options |
layerOptions | list of OGR layer creation options |
skipAttributeCreation | only write geometries |
newFilename | QString pointer which will contain the new file name created (in case it is different to fileName). |
symbologyExport | symbology to export |
symbologyScale | scale of symbology |
Definition at line 1782 of file qgsvectorfilewriter.cpp.
References QgsMapLayer::crs().
|
static |
Definition at line 1808 of file qgsvectorfilewriter.cpp.
References addFeature(), addRendererAttributes(), QgsFeatureRendererV2::capabilities(), QgsMapLayer::crs(), QgsVectorLayer::dataProvider(), QgsDataProvider::dataSourceUri(), QgsCoordinateTransform::destCRS(), ErrCreateDataSource, ErrFeatureWriteFailed, ErrInvalidLayer, errorMessage(), ErrProjection, exportFeaturesSymbolLevels(), QgsFeature::geometry(), QgsVectorLayer::getFeatures(), hasError(), QgsFeature::id(), QgsFeature::initAttributes(), QgsCoordinateReferenceSystem::mapUnits(), mLayer, QgsFeatureIterator::nextFeature(), NoError, QgsFeatureRequest::NoGeometry, NoSymbology, QgsVectorLayer::pendingAllAttributesList(), QgsVectorLayer::pendingFields(), QgsVectorLayer::providerType(), QgsDebugMsg, QgsVectorFileWriter(), QgsVectorLayer::rendererV2(), QgsVectorLayer::selectedFeaturesIds(), QgsFeatureRequest::setFlags(), QgsFeatureRequest::setSubsetOfAttributes(), setSymbologyScaleDenominator(), startRender(), stopRender(), SymbolLayerSymbology, QgsFeatureRendererV2::SymbolLevels, symbologyExport(), tr, QgsGeometry::transform(), QgsFeatureRendererV2::usingSymbolLevels(), QgsLogger::warning(), QgsException::what(), QGis::WKBNoGeometry, and QgsVectorLayer::wkbType().
|
private |
Definition at line 1755 of file qgsvectorfilewriter.cpp.
References ErrFeatureWriteFailed, QgsMessageLog::logMessage(), mError, mErrorMessage, and tr.
Referenced by addFeature(), and exportFeaturesSymbolLevels().
|
protected |
map attribute indizes to OGR field indexes
Definition at line 292 of file qgsvectorfilewriter.h.
Referenced by createFeature(), and QgsVectorFileWriter().
|
protected |
Definition at line 286 of file qgsvectorfilewriter.h.
Referenced by createFeature(), and QgsVectorFileWriter().
|
protected |
Definition at line 276 of file qgsvectorfilewriter.h.
Referenced by QgsVectorFileWriter(), and ~QgsVectorFileWriter().
|
protected |
contains error value if construction was not successful
Definition at line 283 of file qgsvectorfilewriter.h.
Referenced by createFeature(), hasError(), QgsVectorFileWriter(), and writeFeature().
|
protected |
Definition at line 284 of file qgsvectorfilewriter.h.
Referenced by createFeature(), errorMessage(), QgsVectorFileWriter(), and writeFeature().
|
protected |
Definition at line 280 of file qgsvectorfilewriter.h.
Referenced by createFeature(), and QgsVectorFileWriter().
|
protected |
Definition at line 278 of file qgsvectorfilewriter.h.
Referenced by createFeature(), QgsVectorFileWriter(), and ~QgsVectorFileWriter().
|
protected |
Definition at line 277 of file qgsvectorfilewriter.h.
Referenced by addFeature(), createFeature(), exportFeaturesSymbolLevels(), QgsVectorFileWriter(), and writeAsVectorFormat().
|
protected |
Definition at line 294 of file qgsvectorfilewriter.h.
Referenced by addFeature(), and symbologyRenderer().
|
protected |
Scale for symbology export (e.g.
for symbols units in map units)
Definition at line 301 of file qgsvectorfilewriter.h.
Referenced by addFeature(), createSymbolLayerTable(), exportFeaturesSymbolLevels(), and renderContext().
|
protected |
geometry type which is being used
Definition at line 289 of file qgsvectorfilewriter.h.
Referenced by createFeature(), and QgsVectorFileWriter().
|
staticprivate |
Definition at line 323 of file qgsvectorfilewriter.h.
Referenced by driverMetadata().