Skip to content

Commit

Permalink
use run() to execute nested algorithms
Browse files Browse the repository at this point in the history
move step calculation to prepareAlgorithm to avoid crash
disable tests for native implementation
  • Loading branch information
alexbruy authored and wonder-sk committed Oct 9, 2023
1 parent 8dbf287 commit e302345
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 298 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -268,40 +268,6 @@ tests:
cast: str
fid: skip

- algorithm: native:concavehull
name: Concave Hull - Points (0.3) (GEOS <= 3.10)
condition:
geos:
less_than: 31100
params:
ALPHA: 0.3
HOLES: true
INPUT:
name: points.gml
type: vector
NO_MULTIGEOMETRY: false
results:
OUTPUT:
name: expected/concave_hull_points_03_qgis.gml
type: vector

- algorithm: native:concavehull
name: Concave Hull - Points (0.7) (GEOS <= 3.10)
condition:
geos:
less_than: 31100
params:
ALPHA: 0.7
HOLES: true
INPUT:
name: points.gml
type: vector
NO_MULTIGEOMETRY: false
results:
OUTPUT:
name: expected/concave_hull_points_07_qgis.gml
type: vector

- algorithm: native:concavehull
name: Concave Hull - Points (0.3) (GEOS > 3.11)
condition:
Expand All @@ -316,24 +282,24 @@ tests:
NO_MULTIGEOMETRY: false
results:
OUTPUT:
name: expected/concave_hull_points_03_geos.gml
name: expected/concave_hull_points_03.gml
type: vector

- algorithm: native:concavehull
name: Concave Hull - Points (0.7) (GEOS > 3.11)
name: Concave Hull - Points (0.9) (GEOS > 3.11)
condition:
geos:
at_least: 31100
params:
ALPHA: 0.7
ALPHA: 0.9
HOLES: true
INPUT:
name: points.gml
type: vector
NO_MULTIGEOMETRY: false
results:
OUTPUT:
name: expected/concave_hull_points_07_geos.gml
name: expected/concave_hull_points_09.gml
type: vector

- algorithm: qgis:knearestconcavehull
Expand Down
15 changes: 7 additions & 8 deletions src/analysis/processing/qgsalgorithmconcavehull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ bool QgsConcaveHullAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Q
if ( mSource->featureCount() < 3 )
throw QgsProcessingException( QObject::tr( "Input layer should contain at least 3 points." ) );

mStep = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;

mPercentage = parameterAsDouble( parameters, QStringLiteral( "ALPHA" ), context );
mAllowHoles = parameterAsBool( parameters, QStringLiteral( "HOLES" ), context );
mSplitMultipart = parameterAsBool( parameters, QStringLiteral( "NO_MULTIGEOMETRY" ), context );
Expand Down Expand Up @@ -104,7 +106,6 @@ QVariantMap QgsConcaveHullAlgorithm::processAlgorithm( const QVariantMap &parame
void QgsConcaveHullAlgorithm::concaveHullGeos( std::unique_ptr< QgsFeatureSink > &sink, const QVariantMap &parameters, QgsProcessingFeedback *feedback )
{
long long i = 0;
double step = mSource->featureCount() > 0 ? 50.0 / mSource->featureCount() : 1;

QgsFeatureIterator it = mSource->getFeatures( QgsFeatureRequest().setNoAttributes(), QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );
QgsFeature f;
Expand All @@ -115,7 +116,7 @@ void QgsConcaveHullAlgorithm::concaveHullGeos( std::unique_ptr< QgsFeatureSink >
if ( feedback->isCanceled() )
return;

feedback->setProgress( i * step );
feedback->setProgress( i * mStep );

if ( !f.hasGeometry() )
continue;
Expand All @@ -139,7 +140,7 @@ void QgsConcaveHullAlgorithm::concaveHullGeos( std::unique_ptr< QgsFeatureSink >
if ( mSplitMultipart && concaveHull.isMultipart() )
{
QVector< QgsGeometry > collection = concaveHull.asGeometryCollection();
step = collection.length() > 0 ? 50.0 / collection.length() : 1;
mStep = collection.length() > 0 ? 50.0 / collection.length() : 1;
for ( int i = 0; i < collection.length(); i++ )
{
if ( feedback->isCanceled() )
Expand All @@ -157,7 +158,7 @@ void QgsConcaveHullAlgorithm::concaveHullGeos( std::unique_ptr< QgsFeatureSink >
if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );

feedback->setProgress( 50 + i * step );
feedback->setProgress( 50 + i * mStep );
}
}
else
Expand Down Expand Up @@ -194,8 +195,7 @@ void QgsConcaveHullAlgorithm::concaveHullQgis( std::unique_ptr< QgsFeatureSink >
}
std::unique_ptr< QgsProcessingAlgorithm > algorithm;
algorithm.reset( delaunayAlg->create() );
algorithm->prepare( params, context, &multiStepFeedback );
QVariantMap results = algorithm->runPrepared( params, context, &multiStepFeedback );
QVariantMap results = algorithm->run( params, context, &multiStepFeedback );
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( results["OUTPUT"].toString(), context ) );

if ( !layer )
Expand Down Expand Up @@ -271,8 +271,7 @@ void QgsConcaveHullAlgorithm::concaveHullQgis( std::unique_ptr< QgsFeatureSink >
feedback->reportError( QObject::tr( "Failed to compute concave hull: Dissolve algorithm not found!" ), true );
}
algorithm.reset( dissolveAlg->create() );
algorithm->prepare( params, context, &multiStepFeedback );
results = algorithm->runPrepared( params, context, &multiStepFeedback );
results = algorithm->run( params, context, &multiStepFeedback );
layer = qobject_cast<QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( results["OUTPUT"].toString(), context ) );
if ( !layer )
{
Expand Down
Loading

0 comments on commit e302345

Please sign in to comment.