QgsVectorFileWriter Class Reference
[QGIS core library]

A convenience class for writing vector files to disk. More...

#include <qgsvectorfilewriter.h>

List of all members.

Public Types

enum  WriterError {
  NoError = 0, ErrDriverNotFound, ErrCreateDataSource, ErrCreateLayer,
  ErrAttributeTypeUnsupported, ErrAttributeCreationFailed, ErrProjection, ErrFeatureWriteFailed
}

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())
 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
 ~QgsVectorFileWriter ()
 close opened shapefile for writing

Static Public Member Functions

static 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())
 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 QPair< QString, QString > nameAndGlob (QString driverName)


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 43 of file qgsvectorfilewriter.h.


Member Enumeration Documentation

Enumerator:
NoError 
ErrDriverNotFound 
ErrCreateDataSource 
ErrCreateLayer 
ErrAttributeTypeUnsupported 
ErrAttributeCreationFailed 
ErrProjection 
ErrFeatureWriteFailed 

Definition at line 47 of file qgsvectorfilewriter.h.


Constructor & Destructor Documentation

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() 
)

QgsVectorFileWriter::~QgsVectorFileWriter (  ) 

close opened shapefile for writing

Definition at line 495 of file qgsvectorfilewriter.cpp.

References mDS, and mGeom.


Member Function Documentation

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.

Note:
: deprecated. Use writeAsVectorFormat instead

Definition at line 512 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() 
) [static]

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

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

Definition at line 686 of file qgsvectorfilewriter.cpp.

References filterForDriver(), and QgsApplication::registerOgrDrivers().

Referenced by fileFilterString().

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

Returns driver list that can be used for dialogs.

Definition at line 713 of file qgsvectorfilewriter.cpp.

References nameAndGlob(), and QgsApplication::registerOgrDrivers().

QString QgsVectorFileWriter::fileFilterString (  )  [static]

Returns filter string that can be used for dialogs.

Definition at line 740 of file qgsvectorfilewriter.cpp.

References supportedFiltersAndFormats().

QString QgsVectorFileWriter::filterForDriver ( const QString &  driverName  )  [static]

Creates a filter for an OGR driver key.

Definition at line 755 of file qgsvectorfilewriter.cpp.

References nameAndGlob().

Referenced by supportedFiltersAndFormats().

QgsVectorFileWriter::WriterError QgsVectorFileWriter::hasError (  ) 

checks whether there were any errors in constructor

Definition at line 354 of file qgsvectorfilewriter.cpp.

References mError.

Referenced by writeAsVectorFormat().

QString QgsVectorFileWriter::errorMessage (  ) 

retrieves error message

Note:
added in 1.5

Definition at line 359 of file qgsvectorfilewriter.cpp.

References mErrorMessage.

Referenced by writeAsVectorFormat().

bool QgsVectorFileWriter::addFeature ( QgsFeature feature  ) 

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

References QgsDebugMsg.

Referenced by QgsVectorFileWriter().

OGRGeometryH QgsVectorFileWriter::createEmptyGeometry ( QGis::WkbType  wkbType  )  [protected]

Definition at line 348 of file qgsvectorfilewriter.cpp.

Referenced by addFeature(), and QgsVectorFileWriter().

QPair< QString, QString > QgsVectorFileWriter::nameAndGlob ( QString  driverName  )  [static, private]

Definition at line 765 of file qgsvectorfilewriter.cpp.

Referenced by filterForDriver(), and ogrDriverList().


Member Data Documentation

Definition at line 131 of file qgsvectorfilewriter.h.

Referenced by QgsVectorFileWriter(), and ~QgsVectorFileWriter().

Definition at line 132 of file qgsvectorfilewriter.h.

Referenced by addFeature(), and QgsVectorFileWriter().

Definition at line 133 of file qgsvectorfilewriter.h.

Referenced by addFeature(), QgsVectorFileWriter(), and ~QgsVectorFileWriter().

Definition at line 135 of file qgsvectorfilewriter.h.

Referenced by addFeature(), and QgsVectorFileWriter().

contains error value if construction was not successful

Definition at line 138 of file qgsvectorfilewriter.h.

Referenced by addFeature(), hasError(), and QgsVectorFileWriter().

Definition at line 139 of file qgsvectorfilewriter.h.

Referenced by addFeature(), errorMessage(), and QgsVectorFileWriter().

QTextCodec* QgsVectorFileWriter::mCodec [protected]

Definition at line 141 of file qgsvectorfilewriter.h.

Referenced by addFeature(), and QgsVectorFileWriter().

geometry type which is being used

Definition at line 144 of file qgsvectorfilewriter.h.

Referenced by addFeature(), and QgsVectorFileWriter().

QMap<int, int> QgsVectorFileWriter::mAttrIdxToOgrIdx [protected]

map attribute indizes to OGR field indexes

Definition at line 147 of file qgsvectorfilewriter.h.

Referenced by addFeature(), and QgsVectorFileWriter().


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

Generated on Sat Feb 4 19:17:57 2012 for Quantum GIS API Documentation by  doxygen 1.5.6