Skip to content

Commit

Permalink
[processing] Force regeneration of primary key for more algorithms
Browse files Browse the repository at this point in the history
Fixes #21445

(cherry picked from commit ce5faa1)
  • Loading branch information
nyalldawson committed Mar 5, 2019
1 parent 581d09c commit 53a695a
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def processAlgorithm(self, parameters, context, feedback):
wkb_type = QgsWkbTypes.addZ(wkb_type)

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, wkb_type, source.sourceCrs())
fields, wkb_type, source.sourceCrs(), QgsFeatureSink.RegeneratePrimaryKey)
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/PointsInPolygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def processAlgorithm(self, parameters, context, feedback):
field_index = fields.lookupField(field_name)

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, poly_source.wkbType(), poly_source.sourceCrs())
fields, poly_source.wkbType(), poly_source.sourceCrs(), QgsFeatureSink.RegeneratePrimaryKey)
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def processAlgorithm(self, parameters, context, feedback):
fields.append(QgsField('id', QVariant.Int, '', 10, 0))

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, QgsWkbTypes.Point, source.sourceCrs())
fields, QgsWkbTypes.Point, source.sourceCrs(), QgsFeatureSink.RegeneratePrimaryKey)
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/RandomPointsLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def processAlgorithm(self, parameters, context, feedback):
fields.append(QgsField('id', QVariant.Int, '', 10, 0))

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, QgsWkbTypes.Point, source.sourceCrs())
fields, QgsWkbTypes.Point, source.sourceCrs(), QgsFeatureSink.RegeneratePrimaryKey)
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def processAlgorithm(self, parameters, context, feedback):
fields.append(QgsField('id', QVariant.Int, '', 10, 0))

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, QgsWkbTypes.Point, source.sourceCrs())
fields, QgsWkbTypes.Point, source.sourceCrs(), QgsFeatureSink.RegeneratePrimaryKey)
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))

Expand Down
5 changes: 5 additions & 0 deletions src/analysis/processing/qgsalgorithmarrayoffsetlines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ QgsFields QgsCreateArrayOffsetLinesAlgorithm::outputFields( const QgsFields &inp
return output;
}

QgsFeatureSink::SinkFlags QgsCreateArrayOffsetLinesAlgorithm::sinkFlags() const
{
return QgsFeatureSink::RegeneratePrimaryKey;
}

///@endcond


1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmarrayoffsetlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QgsCreateArrayOffsetLinesAlgorithm : public QgsProcessingFeatureBasedAlgor
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFields outputFields( const QgsFields &inputFields ) const override;
QgsFeatureSink::SinkFlags sinkFlags() const override;

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ QgsFields QgsArrayTranslatedFeaturesAlgorithm::outputFields( const QgsFields &in
return output;
}

QgsFeatureSink::SinkFlags QgsArrayTranslatedFeaturesAlgorithm::sinkFlags() const
{
return QgsFeatureSink::RegeneratePrimaryKey;
}

///@endcond


Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QgsArrayTranslatedFeaturesAlgorithm : public QgsProcessingFeatureBasedAlgo
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsFields outputFields( const QgsFields &inputFields ) const override;
QgsFeatureSink::SinkFlags sinkFlags() const override;

private:

Expand Down
5 changes: 5 additions & 0 deletions src/analysis/processing/qgsalgorithmexplode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ QgsFeatureList QgsExplodeAlgorithm::processFeature( const QgsFeature &f, QgsProc
}
}

QgsFeatureSink::SinkFlags QgsExplodeAlgorithm::sinkFlags() const
{
return QgsFeatureSink::RegeneratePrimaryKey;
}

std::vector<QgsGeometry> QgsExplodeAlgorithm::extractAsParts( const QgsGeometry &geometry ) const
{
if ( geometry.isMultipart() )
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmexplode.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QgsExplodeAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString outputName() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureSink::SinkFlags sinkFlags() const override;

std::vector< QgsGeometry > extractAsParts( const QgsGeometry &geometry ) const;
std::vector< QgsGeometry > curveAsSingleSegments( const QgsCurve *curve, bool useCompoundCurves = false ) const;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmextractvertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ QVariantMap QgsExtractVerticesAlgorithm::processAlgorithm( const QVariantMap &pa
outputFields.append( QgsField( QStringLiteral( "angle" ), QVariant::Double, QString(), 20, 14 ) );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, outputWkbType, featureSource->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, outputWkbType, featureSource->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
1 change: 0 additions & 1 deletion src/analysis/processing/qgsalgorithmextractvertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class QgsExtractVerticesAlgorithm : public QgsProcessingAlgorithm
QgsExtractVerticesAlgorithm *createInstance() const override SIP_FACTORY;

protected:

QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmintersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ QVariantMap QgsIntersectionAlgorithm::processAlgorithm( const QVariantMap &param
QgsProcessingUtils::indicesToFields( fieldIndicesB, sourceB->fields() ) );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, geomType, sourceA->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outputFields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmjoinwithlines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields,
outType, hubSource->sourceCrs() ) );
outType, hubSource->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmlineintersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ QVariantMap QgsLineIntersectionAlgorithm::processAlgorithm( const QVariantMap &p
QgsFields outFields = QgsProcessingUtils::combineFields( outFieldsA, outFieldsB );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outFields, QgsWkbTypes::Point, sourceA->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, outFields, QgsWkbTypes::Point, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ QgsProcessingFeatureSource::Flag QgsMultiRingConstantBufferAlgorithm::sourceFlag
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

QgsFeatureSink::SinkFlags QgsMultiRingConstantBufferAlgorithm::sinkFlags() const
{
return QgsFeatureSink::RegeneratePrimaryKey;
}

QgsFeatureList QgsMultiRingConstantBufferAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
double currentDistance = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QgsMultiRingConstantBufferAlgorithm : public QgsProcessingFeatureBasedAlgo
QgsFields outputFields( const QgsFields &inputFields ) const override;
QgsProcessing::SourceType outputLayerType() const override { return QgsProcessing::TypeVectorPolygon; }
QgsProcessingFeatureSource::Flag sourceFlags() const override;
QgsFeatureSink::SinkFlags sinkFlags() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override { Q_UNUSED( inputWkbType ); return QgsWkbTypes::MultiPolygon; }
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QVariantMap QgsShortestPathPointToLayerAlgorithm::processAlgorithm( const QVaria
fields.append( QgsField( QStringLiteral( "cost" ), QVariant::Double ) );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, QgsWkbTypes::LineString, mNetwork->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, QgsWkbTypes::LineString, mNetwork->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmsplitwithlines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, source->fields(),
QgsWkbTypes::multiType( source->wkbType() ), source->sourceCrs() ) );
QgsWkbTypes::multiType( source->wkbType() ), source->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ QVariantMap QgsSymmetricalDifferenceAlgorithm::processAlgorithm( const QVariantM
QgsFields fields = QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields() );

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmtransect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ QVariantMap QgsTransectAlgorithm::processAlgorithm( const QVariantMap &parameter

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields,
outputWkb, source->sourceCrs() ) );
outputWkb, source->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmunion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ QVariantMap QgsUnionAlgorithm::processAlgorithm( const QVariantMap &parameters,
QgsFields fields = sourceB ? QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields() ) : sourceA->fields();

QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs() ) );
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );

Expand Down

0 comments on commit 53a695a

Please sign in to comment.