Skip to content
Permalink
Browse files

[processing] Don't run validity checks for buffer alg

Buffering doesn't care about validity and can sometimes be used
to repair geometries
  • Loading branch information
nyalldawson committed Nov 17, 2018
1 parent 7126fae commit 9d5c949378a686fb9c8997106d01692ad539b431
@@ -81,7 +81,7 @@ QgsBufferAlgorithm *QgsBufferAlgorithm::createInstance() const

QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
if ( !source )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );

@@ -98,7 +98,7 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
double miterLimit = parameterAsDouble( parameters, QStringLiteral( "MITER_LIMIT" ), context );
double bufferDistance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context );
bool dynamicBuffer = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) );
QgsExpressionContext expressionContext = createExpressionContext( parameters, context, dynamic_cast< QgsProcessingFeatureSource * >( source.get() ) );
QgsExpressionContext expressionContext = createExpressionContext( parameters, context, source.get() );
QgsProperty bufferProperty;
if ( dynamicBuffer )
{
@@ -108,7 +108,8 @@ QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap &parameters,
long count = source->featureCount();

QgsFeature f;
QgsFeatureIterator it = source->getFeatures();
// buffer doesn't care about invalid features, and buffering can be used to repair geometries
QgsFeatureIterator it = source->getFeatures( QgsFeatureRequest(), QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );

double step = count > 0 ? 100.0 / count : 1;
int current = 0;
@@ -113,6 +113,11 @@ QgsFields QgsMultiRingConstantBufferAlgorithm::outputFields( const QgsFields &in
return fields;
}

QgsProcessingFeatureSource::Flag QgsMultiRingConstantBufferAlgorithm::sourceFlags() const
{
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

QgsFeatureList QgsMultiRingConstantBufferAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
double currentDistance = 0;
@@ -49,6 +49,7 @@ class QgsMultiRingConstantBufferAlgorithm : public QgsProcessingFeatureBasedAlgo
QString outputName() const override;
QgsFields outputFields( const QgsFields &inputFields ) const override;
QgsProcessing::SourceType outputLayerType() const override { return QgsProcessing::TypeVectorPolygon; }
QgsProcessingFeatureSource::Flag sourceFlags() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override { Q_UNUSED( inputWkbType ); return QgsWkbTypes::Polygon; }
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

0 comments on commit 9d5c949

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