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
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum WriterError
|
|
|
|
{
|
|
|
|
NoError = 0,
|
|
|
|
ErrDriverNotFound,
|
|
|
|
ErrCreateDataSource,
|
|
|
|
ErrCreateLayer
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Write contents of vector layer to a shapefile */
|
|
|
|
static WriterError writeAsShapefile(QgsVectorLayer* layer,
|
|
|
|
const QString& shapefileName,
|
2007-05-10 11:26:25 +00:00
|
|
|
const QString& fileEncoding,
|
2008-09-15 20:51:01 +00:00
|
|
|
const QgsCoordinateReferenceSystem*,
|
2007-05-10 11:26:25 +00:00
|
|
|
bool onlySelected = FALSE);
|
2007-04-11 11:46:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** create shapefile and initialize it */
|
|
|
|
QgsVectorFileWriter(const QString& shapefileName,
|
|
|
|
const QString& fileEncoding,
|
|
|
|
const QMap<int, QgsField>& fields,
|
2008-10-10 20:02:22 +00:00
|
|
|
QGis::WkbType geometryType,
|
2008-08-21 21:11:56 +00:00
|
|
|
const QgsCoordinateReferenceSystem* srs);
|
2007-04-11 11:46:35 +00:00
|
|
|
|
|
|
|
/** checks whether there were any errors in constructor */
|
|
|
|
WriterError hasError();
|
|
|
|
|
|
|
|
/** add feature to the currently opened shapefile */
|
|
|
|
bool addFeature(QgsFeature& feature);
|
|
|
|
|
|
|
|
/** close opened shapefile for writing */
|
|
|
|
~QgsVectorFileWriter();
|
|
|
|
|
2008-06-08 00:55:29 +00:00
|
|
|
/** Delete a shapefile (and its accompanying shx / dbf / prf)
|
|
|
|
* @param QString theFileName - /path/to/file.shp
|
|
|
|
* @return bool true if the file was deleted successfully
|
|
|
|
*/
|
|
|
|
static bool deleteShapeFile(QString theFileName);
|
2007-04-11 11:46:35 +00:00
|
|
|
};
|
|
|
|
|