Skip to content

Commit

Permalink
QgsVectorFileWriter is a QgsFeatureSink
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 8d0a9d6 commit 8d59833
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions python/core/qgsvectorfilewriter.sip
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsvectorfilewriter.h
Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand Down

0 comments on commit 8d59833

Please sign in to comment.