QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsVectorFileWriter Class Reference

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  SymbologyExport { NoSymbology = 0, FeatureSymbology, SymbolLayerSymbology }
 
enum  WriterError {
  NoError = 0, ErrDriverNotFound, ErrCreateDataSource, ErrCreateLayer,
  ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed,
  ErrInvalidLayer
}
 

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 More...
 
 ~QgsVectorFileWriter ()
 close opened shapefile for writing More...
 
bool addFeature (QgsFeature &feature, QgsFeatureRendererV2 *renderer=0, QGis::UnitType outputUnit=QGis::Meters)
 add feature to the currently opened shapefile More...
 
QMap< int, int > attrIdxToOgrIdx ()
 
QString errorMessage ()
 retrieves error message More...
 
WriterError hasError ()
 checks whether there were any errors in constructor More...
 
void setSymbologyExport (SymbologyExport symExport)
 
void setSymbologyScaleDenominator (double d)
 
SymbologyExport symbologyExport () const
 
double symbologyScaleDenominator () const
 

Static Public Member Functions

static QString convertCodecNameForEncodingOption (const QString &codecName)
 Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile. More...
 
static bool deleteShapeFile (QString theFileName)
 Delete a shapefile (and its accompanying shx / dbf / prf) More...
 
static bool driverMetadata (const QString &driverName, MetaData &driverMetadata)
 
static QString fileFilterString ()
 Returns filter string that can be used for dialogs. More...
 
static QString filterForDriver (const QString &driverName)
 Creates a filter for an OGR driver key. More...
 
static QMap< QString, QStringogrDriverList ()
 Returns driver list that can be used for dialogs. More...
 
static QMap< QString, QStringsupportedFiltersAndFormats ()
 Returns map with format filter string as key and OGR format key as value. More...
 
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, const QgsRectangle *filterExtent=0)
 Write contents of vector layer to an (OGR supported) vector formt. More...
 
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, const QgsRectangle *filterExtent=0)
 

Protected Member Functions

OGRGeometryH createEmptyGeometry (QGis::WkbType wkbType)
 

Protected Attributes

QMap< int, int > mAttrIdxToOgrIdx
 map attribute indizes to OGR field indexes More...
 
QTextCodecmCodec
 
OGRDataSourceH mDS
 
WriterError mError
 contains error value if construction was not successful More...
 
QString mErrorMessage
 
QgsFields mFields
 
OGRGeometryH mGeom
 
OGRLayerH mLayer
 
SymbologyExport mSymbologyExport
 
double mSymbologyScaleDenominator
 Scale for symbology export (e.g. More...
 
QGis::WkbType mWkbType
 geometry type which is being used More...
 

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.

Definition at line 42 of file qgsvectorfilewriter.h.

Member Enumeration Documentation

Enumerator
Set 
String 
Int 
Hidden 

Definition at line 45 of file qgsvectorfilewriter.h.

Enumerator
NoSymbology 
FeatureSymbology 
SymbolLayerSymbology 

Definition at line 156 of file qgsvectorfilewriter.h.

Enumerator
NoError 
ErrDriverNotFound 
ErrCreateDataSource 
ErrCreateLayer 
ErrAttributeTypeUnsupported 
ErrAttributeCreationFailed 
ErrProjection 
ErrFeatureWriteFailed 
ErrInvalidLayer 

Definition at line 143 of file qgsvectorfilewriter.h.

Constructor & Destructor Documentation

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 58 of file qgsvectorfilewriter.cpp.

QgsVectorFileWriter::~QgsVectorFileWriter ( )

close opened shapefile for writing

Definition at line 1799 of file qgsvectorfilewriter.cpp.

Member Function Documentation

bool QgsVectorFileWriter::addFeature ( QgsFeature feature,
QgsFeatureRendererV2 renderer = 0,
QGis::UnitType  outputUnit = QGis::Meters 
)

add feature to the currently opened shapefile

Definition at line 1564 of file qgsvectorfilewriter.cpp.

QMap<int, int> QgsVectorFileWriter::attrIdxToOgrIdx ( )
inline
Note
not available in python bindings

Definition at line 253 of file qgsvectorfilewriter.h.

QString QgsVectorFileWriter::convertCodecNameForEncodingOption ( const QString codecName)
static

Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.

Definition at line 2238 of file qgsvectorfilewriter.cpp.

OGRGeometryH QgsVectorFileWriter::createEmptyGeometry ( QGis::WkbType  wkbType)
protected
Note
not available in python bindings

Definition at line 497 of file qgsvectorfilewriter.cpp.

bool QgsVectorFileWriter::deleteShapeFile ( QString  theFileName)
static

Delete a shapefile (and its accompanying shx / dbf / prf)

Parameters
theFileName/path/to/file.shp
Returns
bool true if the file was deleted successfully

Definition at line 2086 of file qgsvectorfilewriter.cpp.

bool QgsVectorFileWriter::driverMetadata ( const QString driverName,
QgsVectorFileWriter::MetaData driverMetadata 
)
static

Definition at line 1535 of file qgsvectorfilewriter.cpp.

QString QgsVectorFileWriter::errorMessage ( )

retrieves error message

Definition at line 1559 of file qgsvectorfilewriter.cpp.

QString QgsVectorFileWriter::fileFilterString ( )
static

Returns filter string that can be used for dialogs.

Definition at line 2211 of file qgsvectorfilewriter.cpp.

QString QgsVectorFileWriter::filterForDriver ( const QString driverName)
static

Creates a filter for an OGR driver key.

Definition at line 2226 of file qgsvectorfilewriter.cpp.

QgsVectorFileWriter::WriterError QgsVectorFileWriter::hasError ( )

checks whether there were any errors in constructor

Definition at line 1554 of file qgsvectorfilewriter.cpp.

QMap< QString, QString > QgsVectorFileWriter::ogrDriverList ( )
static

Returns driver list that can be used for dialogs.

It contains all OGR drivers

  • some additional internal QGIS driver names to distinguish between more supported formats of the same OGR driver

Definition at line 2139 of file qgsvectorfilewriter.cpp.

void QgsVectorFileWriter::setSymbologyExport ( SymbologyExport  symExport)
inline

Definition at line 265 of file qgsvectorfilewriter.h.

void QgsVectorFileWriter::setSymbologyScaleDenominator ( double  d)
inline

Definition at line 268 of file qgsvectorfilewriter.h.

QMap< QString, QString > QgsVectorFileWriter::supportedFiltersAndFormats ( )
static

Returns map with format filter string as key and OGR format key as value.

Definition at line 2112 of file qgsvectorfilewriter.cpp.

SymbologyExport QgsVectorFileWriter::symbologyExport ( ) const
inline

Definition at line 264 of file qgsvectorfilewriter.h.

double QgsVectorFileWriter::symbologyScaleDenominator ( ) const
inline

Definition at line 267 of file qgsvectorfilewriter.h.

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,
SymbologyExport  symbologyExport = NoSymbology,
double  symbologyScale = 1.0,
const QgsRectangle filterExtent = 0 
)
static

Write contents of vector layer to an (OGR supported) vector formt.

Parameters
layerlayer to write
fileNamefile name to write to
fileEncodingencoding to use
destCRSpointer to CRS to reproject exported geometries to
driverNameOGR driver to use
onlySelectedwrite only selected features of layer
errorMessagepointer to buffer fo error message
datasourceOptionslist of OGR data source creation options
layerOptionslist of OGR layer creation options
skipAttributeCreationonly write geometries
newFilenameQString pointer which will contain the new file name created (in case it is different to fileName).
symbologyExportsymbology to export
symbologyScalescale of symbology
filterExtentif not a null pointer, only features intersecting the extent will be saved

Definition at line 1813 of file qgsvectorfilewriter.cpp.

QgsVectorFileWriter::WriterError QgsVectorFileWriter::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,
const QgsRectangle filterExtent = 0 
)
static
Note
added in v2.2

Definition at line 1840 of file qgsvectorfilewriter.cpp.

Member Data Documentation

QMap<int, int> QgsVectorFileWriter::mAttrIdxToOgrIdx
protected

map attribute indizes to OGR field indexes

Definition at line 292 of file qgsvectorfilewriter.h.

QTextCodec* QgsVectorFileWriter::mCodec
protected

Definition at line 286 of file qgsvectorfilewriter.h.

OGRDataSourceH QgsVectorFileWriter::mDS
protected

Definition at line 276 of file qgsvectorfilewriter.h.

WriterError QgsVectorFileWriter::mError
protected

contains error value if construction was not successful

Definition at line 283 of file qgsvectorfilewriter.h.

QString QgsVectorFileWriter::mErrorMessage
protected

Definition at line 284 of file qgsvectorfilewriter.h.

QgsFields QgsVectorFileWriter::mFields
protected

Definition at line 280 of file qgsvectorfilewriter.h.

OGRGeometryH QgsVectorFileWriter::mGeom
protected

Definition at line 278 of file qgsvectorfilewriter.h.

OGRLayerH QgsVectorFileWriter::mLayer
protected

Definition at line 277 of file qgsvectorfilewriter.h.

SymbologyExport QgsVectorFileWriter::mSymbologyExport
protected

Definition at line 294 of file qgsvectorfilewriter.h.

double QgsVectorFileWriter::mSymbologyScaleDenominator
protected

Scale for symbology export (e.g.

for symbols units in map units)

Definition at line 301 of file qgsvectorfilewriter.h.

QGis::WkbType QgsVectorFileWriter::mWkbType
protected

geometry type which is being used

Definition at line 289 of file qgsvectorfilewriter.h.


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