QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
A convenience class for writing vector files to disk. More...
#include <qgsvectorfilewriter.h>
Classes | |
class | BoolOption |
class | FieldValueConverter |
Interface to convert raw field values to their user-friendly value. More... | |
class | HiddenOption |
class | IntOption |
struct | MetaData |
class | Option |
class | SaveVectorOptions |
Options to pass to writeAsVectorFormat() More... | |
class | SetOption |
class | StringOption |
Public Types | |
enum | ActionOnExistingFile { CreateOrOverwriteFile, CreateOrOverwriteLayer, AppendToLayerNoNewFields, AppendToLayerAddFields } |
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteLayer. More... | |
enum | EditionCapability { CanAddNewLayer = 1 << 0, CanAppendToExistingLayer = 1 << 1, CanAddNewFieldsToExistingLayer = 1 << 2, CanDeleteLayer = 1 << 3 } |
Edition capability flags. More... | |
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=nullptr, SymbologyExport symbologyExport=NoSymbology) | |
Create a new vector file writer. More... | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QgsWKBTypes::Type geometryType, const QgsCoordinateReferenceSystem *srs, const QString &driverName="ESRI Shapefile", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=nullptr, SymbologyExport symbologyExport=NoSymbology) | |
Create a new vector file writer. More... | |
QgsVectorFileWriter (const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QgsWKBTypes::Type geometryType, const QgsCoordinateReferenceSystem *srs, const QString &driverName, const QStringList &datasourceOptions, const QStringList &layerOptions, QString *newFilename, SymbologyExport symbologyExport, FieldValueConverter *fieldValueConverter, const QString &layerName, ActionOnExistingFile action) | |
Create a new vector file writer. More... | |
~QgsVectorFileWriter () | |
Close opened shapefile for writing. More... | |
bool | addFeature (QgsFeature &feature, QgsFeatureRendererV2 *renderer=nullptr, QGis::UnitType outputUnit=QGis::Meters) |
Add feature to the currently opened data source. 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 bool | areThereNewFieldsToCreate (const QString &datasetName, const QString &layerName, QgsVectorLayer *layer, const QgsAttributeList &attributes) |
Returns whether there are among the attributes specified some that do not exist yet in the layer. More... | |
static QString | convertCodecNameForEncodingOption (const QString &codecName) |
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile. More... | |
static bool | deleteShapeFile (const QString &theFileName) |
Delete a shapefile (and its accompanying shx / dbf / prf) More... | |
static bool | driverMetadata (const QString &driverName, MetaData &driverMetadata) |
static EditionCapabilities | editionCapabilities (const QString &datasetName) |
Return edition capabilites for an existing dataset name. More... | |
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, QString > | ogrDriverList () |
Returns driver list that can be used for dialogs. More... | |
static OGRwkbGeometryType | ogrTypeFromWkbType (QgsWKBTypes::Type type) |
Get the ogr geometry type from an internal QGIS wkb type enum. More... | |
static QMap< QString, QString > | supportedFiltersAndFormats () |
Returns map with format filter string as key and OGR format key as value. More... | |
static bool | targetLayerExists (const QString &datasetName, const QString &layerName) |
Returns whether the target layer already exists. 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=nullptr, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=nullptr, SymbologyExport symbologyExport=NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, QgsWKBTypes::Type overrideGeometryType=QgsWKBTypes::Unknown, bool forceMulti=false, bool includeZ=false, QgsAttributeList attributes=QgsAttributeList(), FieldValueConverter *fieldValueConverter=nullptr) |
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=nullptr, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=nullptr, SymbologyExport symbologyExport=NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=nullptr, QgsWKBTypes::Type overrideGeometryType=QgsWKBTypes::Unknown, bool forceMulti=false, bool includeZ=false, QgsAttributeList attributes=QgsAttributeList(), FieldValueConverter *fieldValueConverter=nullptr) |
Writes a layer out to a vector file. More... | |
static WriterError | writeAsVectorFormat (QgsVectorLayer *layer, const QString &fileName, const SaveVectorOptions &options, QString *newFilename=nullptr, QString *errorMessage=nullptr) |
Writes a layer out to a vector file. More... | |
Protected Member Functions | |
OGRGeometryH | createEmptyGeometry (QgsWKBTypes::Type wkbType) |
Protected Attributes | |
QMap< int, int > | mAttrIdxToOgrIdx |
Map attribute indizes to OGR field indexes. More... | |
QTextCodec * | mCodec |
OGRDataSourceH | mDS |
WriterError | mError |
Contains error value if construction was not successful. More... | |
QString | mErrorMessage |
QgsFields | mFields |
FieldValueConverter * | mFieldValueConverter |
Field value converter. More... | |
OGRLayerH | mLayer |
QString | mOgrDriverName |
OGRSpatialReferenceH | mOgrRef |
SymbologyExport | mSymbologyExport |
double | mSymbologyScaleDenominator |
Scale for symbology export (e.g. More... | |
QgsWKBTypes::Type | mWkbType |
Geometry type which is being used. More... | |
A convenience class for writing vector files to disk.
There are two possibilities how to use this class:
Definition at line 39 of file qgsvectorfilewriter.h.
Combination of CanAddNewLayer, CanAppendToExistingLayer, CanAddNewFieldsToExistingLayer or CanDeleteLayer.
Definition at line 226 of file qgsvectorfilewriter.h.
Edition capability flags.
Definition at line 204 of file qgsvectorfilewriter.h.
Enumerator | |
---|---|
Set | |
String | |
Int | |
Hidden |
Definition at line 42 of file qgsvectorfilewriter.h.
Enumerator | |
---|---|
NoSymbology | |
FeatureSymbology | |
SymbolLayerSymbology |
Definition at line 168 of file qgsvectorfilewriter.h.
Enumerator | |
---|---|
NoError | |
ErrDriverNotFound | |
ErrCreateDataSource | |
ErrCreateLayer | |
ErrAttributeTypeUnsupported | |
ErrAttributeCreationFailed | |
ErrProjection | |
ErrFeatureWriteFailed | |
ErrInvalidLayer |
Definition at line 155 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 = nullptr , |
||
SymbologyExport | symbologyExport = NoSymbology |
||
) |
Create a new vector file writer.
Definition at line 76 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFields & | fields, | ||
QgsWKBTypes::Type | geometryType, | ||
const QgsCoordinateReferenceSystem * | srs, | ||
const QString & | driverName = "ESRI Shapefile" , |
||
const QStringList & | datasourceOptions = QStringList() , |
||
const QStringList & | layerOptions = QStringList() , |
||
QString * | newFilename = nullptr , |
||
QgsVectorFileWriter::SymbologyExport | symbologyExport = NoSymbology |
||
) |
Create a new vector file writer.
Definition at line 103 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::QgsVectorFileWriter | ( | const QString & | vectorFileName, |
const QString & | fileEncoding, | ||
const QgsFields & | fields, | ||
QgsWKBTypes::Type | geometryType, | ||
const QgsCoordinateReferenceSystem * | srs, | ||
const QString & | driverName, | ||
const QStringList & | datasourceOptions, | ||
const QStringList & | layerOptions, | ||
QString * | newFilename, | ||
QgsVectorFileWriter::SymbologyExport | symbologyExport, | ||
FieldValueConverter * | fieldValueConverter, | ||
const QString & | layerName, | ||
ActionOnExistingFile | action | ||
) |
Create a new vector file writer.
vectorFileName | file name to write to |
fileEncoding | encoding to use |
fields | fields to write |
geometryType | geometry type of output file |
srs | spatial reference system of output file |
driverName | OGR driver to use |
datasourceOptions | list of OGR data source creation options |
layerOptions | list of OGR layer creation options |
newFilename | potentially modified file name (output parameter) |
symbologyExport | symbology to export |
fieldValueConverter | field value converter (added in QGIS 2.16) |
layerName | layer name. If let empty, it will be derived from the filename (added in QGIS 3.0) |
action | action on existing file (added in QGIS 3.0) |
Definition at line 119 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::~QgsVectorFileWriter | ( | ) |
Close opened shapefile for writing.
Definition at line 2286 of file qgsvectorfilewriter.cpp.
bool QgsVectorFileWriter::addFeature | ( | QgsFeature & | feature, |
QgsFeatureRendererV2 * | renderer = nullptr , |
||
QGis::UnitType | outputUnit = QGis::Meters |
||
) |
Add feature to the currently opened data source.
Definition at line 1967 of file qgsvectorfilewriter.cpp.
|
static |
Returns whether there are among the attributes specified some that do not exist yet in the layer.
Definition at line 3208 of file qgsvectorfilewriter.cpp.
|
inline |
Definition at line 495 of file qgsvectorfilewriter.h.
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.
Definition at line 2857 of file qgsvectorfilewriter.cpp.
|
protected |
Definition at line 709 of file qgsvectorfilewriter.cpp.
|
static |
Delete a shapefile (and its accompanying shx / dbf / prf)
theFileName | /path/to/file.shp |
Definition at line 2708 of file qgsvectorfilewriter.cpp.
|
static |
Definition at line 1926 of file qgsvectorfilewriter.cpp.
|
static |
Return edition capabilites for an existing dataset name.
Definition at line 3150 of file qgsvectorfilewriter.cpp.
QString QgsVectorFileWriter::errorMessage | ( | ) |
Retrieves error message.
Definition at line 1962 of file qgsvectorfilewriter.cpp.
|
static |
Returns filter string that can be used for dialogs.
Definition at line 2833 of file qgsvectorfilewriter.cpp.
Creates a filter for an OGR driver key.
Definition at line 2848 of file qgsvectorfilewriter.cpp.
QgsVectorFileWriter::WriterError QgsVectorFileWriter::hasError | ( | ) |
Checks whether there were any errors in constructor.
Definition at line 1957 of file qgsvectorfilewriter.cpp.
Returns driver list that can be used for dialogs.
It contains all OGR drivers
Definition at line 2767 of file qgsvectorfilewriter.cpp.
|
static |
Get the ogr geometry type from an internal QGIS wkb type enum.
Will drop M values and convert Z to 2.5D where required.
Definition at line 1944 of file qgsvectorfilewriter.cpp.
|
inline |
Definition at line 507 of file qgsvectorfilewriter.h.
void QgsVectorFileWriter::setSymbologyScaleDenominator | ( | double | d | ) |
Definition at line 2734 of file qgsvectorfilewriter.cpp.
Returns map with format filter string as key and OGR format key as value.
Definition at line 2740 of file qgsvectorfilewriter.cpp.
|
inline |
Definition at line 506 of file qgsvectorfilewriter.h.
|
inline |
Definition at line 509 of file qgsvectorfilewriter.h.
|
static |
Returns whether the target layer already exists.
Definition at line 3190 of file qgsvectorfilewriter.cpp.
|
static |
Write contents of vector layer to an (OGR supported) vector formt.
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 |
filterExtent | if not a null pointer, only features intersecting the extent will be saved (added in QGIS 2.4) |
overrideGeometryType | set to a valid geometry type to override the default geometry type for the layer. This parameter allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14) |
forceMulti | set to true to force creation of multi* geometries (added in QGIS 2.14) |
includeZ | set to true to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14) |
attributes | attributes to export (empty means all unless skipAttributeCreation is set) |
fieldValueConverter | field value converter (added in QGIS 2.16) |
Definition at line 2300 of file qgsvectorfilewriter.cpp.
|
static |
Writes a layer out to a vector file.
layer | layer to write |
fileName | file name to write to |
fileEncoding | encoding to use |
ct | pointer to coordinate transform to reproject exported geometries with |
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 |
filterExtent | if not a null pointer, only features intersecting the extent will be saved (added in QGIS 2.4) |
overrideGeometryType | set to a valid geometry type to override the default geometry type for the layer. This parameter allows for conversion of geometryless tables to null geometries, etc (added in QGIS 2.14) |
forceMulti | set to true to force creation of multi* geometries (added in QGIS 2.14) |
includeZ | set to true to include z dimension in output. This option is only valid if overrideGeometryType is set. (added in QGIS 2.14) |
attributes | attributes to export (empty means all unless skipAttributeCreation is set) |
fieldValueConverter | field value converter (added in QGIS 2.16) |
Definition at line 2335 of file qgsvectorfilewriter.cpp.
|
static |
Writes a layer out to a vector file.
layer | source layer to write |
fileName | file name to write to |
options | options. |
newFilename | QString pointer which will contain the new file name created (in case it is different to fileName). |
errorMessage | pointer to buffer fo error message |
Definition at line 2400 of file qgsvectorfilewriter.cpp.
|
protected |
Map attribute indizes to OGR field indexes.
Definition at line 564 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 558 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 548 of file qgsvectorfilewriter.h.
|
protected |
Contains error value if construction was not successful.
Definition at line 555 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 556 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 552 of file qgsvectorfilewriter.h.
|
protected |
Field value converter.
Definition at line 578 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 549 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 575 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 550 of file qgsvectorfilewriter.h.
|
protected |
Definition at line 566 of file qgsvectorfilewriter.h.
|
protected |
Scale for symbology export (e.g.
for symbols units in map units)
Definition at line 573 of file qgsvectorfilewriter.h.
|
protected |
Geometry type which is being used.
Definition at line 561 of file qgsvectorfilewriter.h.