2007-04-11 11:46:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class QgsVectorFileWriter
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsvectorfilewriter.h>
|
|
|
|
#include <qgsfield.h>
|
|
|
|
%End
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
2007-04-11 11:46:35 +00:00
|
|
|
enum WriterError
|
|
|
|
{
|
|
|
|
NoError = 0,
|
|
|
|
ErrDriverNotFound,
|
|
|
|
ErrCreateDataSource,
|
2011-08-04 19:48:54 +02:00
|
|
|
ErrCreateLayer,
|
|
|
|
ErrAttributeTypeUnsupported,
|
|
|
|
ErrAttributeCreationFailed,
|
|
|
|
ErrProjection, // added in 1.5
|
|
|
|
ErrFeatureWriteFailed, // added in 1.6
|
|
|
|
ErrInvalidLayer, // added in 2.0
|
2007-04-11 11:46:35 +00:00
|
|
|
};
|
|
|
|
|
2010-03-18 22:24:18 +00:00
|
|
|
/** Write contents of vector layer to an (OGR supported) vector formt
|
|
|
|
@note: this method was added in version 1.5*/
|
|
|
|
static WriterError writeAsVectorFormat( QgsVectorLayer* layer,
|
|
|
|
const QString& fileName,
|
|
|
|
const QString& fileEncoding,
|
|
|
|
const QgsCoordinateReferenceSystem *destCRS,
|
|
|
|
const QString& driverName = "ESRI Shapefile",
|
2012-09-24 02:28:15 +02:00
|
|
|
bool onlySelected = false,
|
2010-08-28 23:14:16 +00:00
|
|
|
QString *errorMessage = 0,
|
2012-11-22 10:35:20 +02:00
|
|
|
const QStringList &datasourceOptions = QStringList(), // added in 1.6
|
|
|
|
const QStringList &layerOptions = QStringList(), // added in 1.6
|
|
|
|
bool skipAttributeCreation = false, // added in 1.6
|
|
|
|
QString *newFilename = 0 // added in 1.9
|
2012-09-24 02:28:15 +02:00
|
|
|
);
|
2010-03-18 22:24:18 +00:00
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/** create shapefile and initialize it */
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsVectorFileWriter( const QString& vectorFileName,
|
|
|
|
const QString& fileEncoding,
|
2012-10-20 22:19:55 +02:00
|
|
|
const QgsFields& fields,
|
2012-09-24 02:28:15 +02:00
|
|
|
QGis::WkbType geometryType,
|
|
|
|
const QgsCoordinateReferenceSystem* srs,
|
|
|
|
const QString& driverName = "ESRI Shapefile",
|
2012-11-22 10:35:20 +02:00
|
|
|
const QStringList &datasourceOptions = QStringList(), // added in 1.6
|
|
|
|
const QStringList &layerOptions = QStringList(), // added in 1.6
|
|
|
|
QString *newFilename = 0 // added in 1.9
|
|
|
|
);
|
2010-03-18 22:24:18 +00:00
|
|
|
|
|
|
|
/**Returns map with format filter string as key and OGR format key as value*/
|
|
|
|
static QMap< QString, QString> supportedFiltersAndFormats();
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/**Returns driver list that can be used for dialogs*/
|
|
|
|
static QMap< QString, QString> ogrDriverList();
|
|
|
|
|
2010-03-18 22:24:18 +00:00
|
|
|
/**Returns filter string that can be used for dialogs*/
|
|
|
|
static QString fileFilterString();
|
|
|
|
|
|
|
|
/**Creates a filter for an OGR driver key*/
|
|
|
|
static QString filterForDriver( const QString& driverName );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/** checks whether there were any errors in constructor */
|
|
|
|
WriterError hasError();
|
2010-02-06 19:27:36 +00:00
|
|
|
|
|
|
|
/** retrieves error message
|
2012-09-24 02:28:15 +02:00
|
|
|
* @note added in 1.5
|
|
|
|
*/
|
2010-02-06 19:27:36 +00:00
|
|
|
QString errorMessage();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/** add feature to the currently opened shapefile */
|
2012-09-24 02:28:15 +02:00
|
|
|
bool addFeature( QgsFeature& feature );
|
|
|
|
|
|
|
|
// QMap<int, int> attrIdxToOgrIdx();
|
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/** close opened shapefile for writing */
|
|
|
|
~QgsVectorFileWriter();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2008-06-08 00:55:29 +00:00
|
|
|
/** Delete a shapefile (and its accompanying shx / dbf / prf)
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param theFileName /path/to/file.shp
|
2008-06-08 00:55:29 +00:00
|
|
|
* @return bool true if the file was deleted successfully
|
2012-09-24 02:28:15 +02:00
|
|
|
*/
|
|
|
|
static bool deleteShapeFile( QString theFileName );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// OGRGeometryH createEmptyGeometry( QGis::WkbType wkbType );
|
2007-04-11 11:46:35 +00:00
|
|
|
};
|
|
|
|
|