Skip to content
Permalink
Browse files

[processing] Force regeneration of primary key for more algorithms

Fixes #21445
  • Loading branch information
nyalldawson committed Mar 3, 2019
1 parent 04f91f0 commit c9eb7dc6400b5d4fe5b9a4d5a92c8f388c8ece6c
Showing with 38 additions and 15 deletions.
  1. +1 −1 python/plugins/processing/algs/qgis/ExtractSpecificVertices.py
  2. +1 −1 python/plugins/processing/algs/qgis/PointsInPolygon.py
  3. +1 −1 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  4. +1 −1 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  5. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygons.py
  6. +5 −0 src/analysis/processing/qgsalgorithmarrayoffsetlines.cpp
  7. +1 −0 src/analysis/processing/qgsalgorithmarrayoffsetlines.h
  8. +5 −0 src/analysis/processing/qgsalgorithmarraytranslatedfeatures.cpp
  9. +1 −0 src/analysis/processing/qgsalgorithmarraytranslatedfeatures.h
  10. +5 −0 src/analysis/processing/qgsalgorithmexplode.cpp
  11. +1 −0 src/analysis/processing/qgsalgorithmexplode.h
  12. +1 −1 src/analysis/processing/qgsalgorithmextractvertices.cpp
  13. +0 −1 src/analysis/processing/qgsalgorithmextractvertices.h
  14. +1 −1 src/analysis/processing/qgsalgorithmintersection.cpp
  15. +1 −1 src/analysis/processing/qgsalgorithmjoinwithlines.cpp
  16. +1 −1 src/analysis/processing/qgsalgorithmlineintersection.cpp
  17. +5 −0 src/analysis/processing/qgsalgorithmmultiringconstantbuffer.cpp
  18. +1 −0 src/analysis/processing/qgsalgorithmmultiringconstantbuffer.h
  19. +1 −1 src/analysis/processing/qgsalgorithmshortestpathpointtolayer.cpp
  20. +1 −1 src/analysis/processing/qgsalgorithmsplitwithlines.cpp
  21. +1 −1 src/analysis/processing/qgsalgorithmsymmetricaldifference.cpp
  22. +1 −1 src/analysis/processing/qgsalgorithmtransect.cpp
  23. +1 −1 src/analysis/processing/qgsalgorithmunion.cpp
@@ -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))

@@ -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))

@@ -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))

@@ -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))

@@ -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))

@@ -177,6 +177,11 @@ QgsFields QgsCreateArrayOffsetLinesAlgorithm::outputFields( const QgsFields &inp
return output;
}

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

///@endcond


@@ -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:

@@ -216,6 +216,11 @@ QgsFields QgsArrayTranslatedFeaturesAlgorithm::outputFields( const QgsFields &in
return output;
}

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

///@endcond


@@ -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:

@@ -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() )
@@ -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;
@@ -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" ) ) );

@@ -46,7 +46,6 @@ class QgsExtractVerticesAlgorithm : public QgsProcessingAlgorithm
QgsExtractVerticesAlgorithm *createInstance() const override SIP_FACTORY;

protected:

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

@@ -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" ) ) );

@@ -179,7 +179,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" ) ) );

@@ -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" ) ) );

@@ -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;
@@ -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;
@@ -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" ) ) );

@@ -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" ) ) );

@@ -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" ) ) );

@@ -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" ) ) );

@@ -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" ) ) );

0 comments on commit c9eb7dc

Please sign in to comment.
You can’t perform that action at this time.