Skip to content

Commit

Permalink
orthogonalize algorithm: make angle tolerance parameter dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 25, 2019
1 parent 59564c4 commit 1a3fb9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/analysis/processing/qgsalgorithmorthogonalize.cpp
Expand Up @@ -79,8 +79,12 @@ QgsOrthogonalizeAlgorithm *QgsOrthogonalizeAlgorithm::createInstance() const

void QgsOrthogonalizeAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "ANGLE_TOLERANCE" ), QObject::tr( "Maximum angle tolerance (degrees)" ),
QgsProcessingParameterNumber::Double, 15.0, false, 0.0, 45.0 ) );
auto angleToleranceParam = qgis::make_unique < QgsProcessingParameterNumber >( QStringLiteral( "ANGLE_TOLERANCE" ), QObject::tr( "Maximum angle tolerance (degrees)" ),
QgsProcessingParameterNumber::Double, 15.0, false, 0.0, 45.0 );
angleToleranceParam->setIsDynamic( true );
angleToleranceParam->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Angle tolerance" ), QObject::tr( "Maximum angle tolerance (degrees)" ), QgsPropertyDefinition::Double ) );
angleToleranceParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( angleToleranceParam.release() );

std::unique_ptr< QgsProcessingParameterNumber> maxIterations = qgis::make_unique< QgsProcessingParameterNumber >(
QStringLiteral( "MAX_ITERATIONS" ),
Expand All @@ -94,18 +98,26 @@ void QgsOrthogonalizeAlgorithm::initParameters( const QVariantMap & )
bool QgsOrthogonalizeAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mAngleTolerance = parameterAsDouble( parameters, QStringLiteral( "ANGLE_TOLERANCE" ), context );
mDynamicAngleTolerance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "ANGLE_TOLERANCE" ) );
if ( mDynamicAngleTolerance )
mAngleToleranceProperty = parameters.value( QStringLiteral( "ANGLE_TOLERANCE" ) ).value< QgsProperty >();

mMaxIterations = parameterAsDouble( parameters, QStringLiteral( "MAX_ITERATIONS" ), context );

return true;
}

QgsFeatureList QgsOrthogonalizeAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
QgsFeatureList QgsOrthogonalizeAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
{
QgsFeature f = feature;

if ( f.hasGeometry() )
{
QgsGeometry outputGeometry = f.geometry().orthogonalize( 1.0e-8, mMaxIterations, mAngleTolerance );
double angleTolerance = mAngleTolerance;
if ( mDynamicAngleTolerance )
angleTolerance = mAngleToleranceProperty.valueAsDouble( context.expressionContext(), angleTolerance );

QgsGeometry outputGeometry = f.geometry().orthogonalize( 1.0e-8, mMaxIterations, angleTolerance );
if ( outputGeometry.isNull() )
throw QgsProcessingException( QObject::tr( "Error orthogonalizing geometry" ) );

Expand Down
6 changes: 4 additions & 2 deletions src/analysis/processing/qgsalgorithmorthogonalize.h
Expand Up @@ -52,8 +52,10 @@ class QgsOrthogonalizeAlgorithm : public QgsProcessingFeatureBasedAlgorithm

private:

double mMaxIterations = 0;
double mAngleTolerance = 0;
double mMaxIterations = 0.0;
double mAngleTolerance = 0.0;
bool mDynamicAngleTolerance = false;
QgsProperty mAngleToleranceProperty;

};

Expand Down

0 comments on commit 1a3fb9a

Please sign in to comment.