QgsVectorFileWriter is a QgsFeatureSink

This commit is contained in:
Nyall Dawson 2017-04-26 10:56:39 +10:00
parent 8d0a9d6bce
commit 8d598337f3
3 changed files with 26 additions and 4 deletions

View File

@ -4,7 +4,7 @@
1. static call to QgsVectorFileWriter::writeAsVectorFormat(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)
*/
class QgsVectorFileWriter
class QgsVectorFileWriter : QgsFeatureSink
{
%TypeHeaderCode
#include <qgsvectorfilewriter.h>
@ -380,8 +380,11 @@ class QgsVectorFileWriter
/** Retrieves error message */
QString errorMessage();
bool addFeature( QgsFeature &feature /In,Out/ );
bool addFeatures( QgsFeatureList &features /In,Out/ );
/** Add feature to the currently opened data source */
bool addFeature( QgsFeature& feature, QgsFeatureRenderer* renderer = 0, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::DistanceMeters );
bool addFeature( QgsFeature& feature, QgsFeatureRenderer* renderer, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::DistanceMeters );
//! @note not available in python bindings
// QMap<int, int> attrIdxToOgrIdx();

View File

@ -1818,6 +1818,22 @@ QString QgsVectorFileWriter::errorMessage()
return mErrorMessage;
}
bool QgsVectorFileWriter::addFeature( QgsFeature &feature )
{
return addFeature( feature, nullptr, QgsUnitTypes::DistanceMeters );
}
bool QgsVectorFileWriter::addFeatures( QgsFeatureList &features )
{
QgsFeatureList::iterator fIt = features.begin();
bool result = true;
for ( ; fIt != features.end(); ++fIt )
{
result = result && addFeature( *fIt, nullptr, QgsUnitTypes::DistanceMeters );
}
return result;
}
bool QgsVectorFileWriter::addFeature( QgsFeature &feature, QgsFeatureRenderer *renderer, QgsUnitTypes::DistanceUnit outputUnit )
{
// create the feature

View File

@ -40,7 +40,7 @@ class QgsFeatureIterator;
1. static call to QgsVectorFileWriter::writeAsVectorFormat(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)
*/
class CORE_EXPORT QgsVectorFileWriter
class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
{
public:
enum OptionType
@ -497,8 +497,11 @@ class CORE_EXPORT QgsVectorFileWriter
//! Retrieves error message
QString errorMessage();
bool addFeature( QgsFeature &feature ) override;
bool addFeatures( QgsFeatureList &features ) override;
//! Add feature to the currently opened data source
bool addFeature( QgsFeature &feature, QgsFeatureRenderer *renderer = nullptr, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::DistanceMeters );
bool addFeature( QgsFeature &feature, QgsFeatureRenderer *renderer, QgsUnitTypes::DistanceUnit outputUnit = QgsUnitTypes::DistanceMeters );
//! \note not available in Python bindings
QMap<int, int> attrIdxToOgrIdx() { return mAttrIdxToOgrIdx; }