Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make densify interval parameter dynamic
  • Loading branch information
m-kuhn committed Jan 21, 2019
1 parent 1e8f819 commit 9fec8ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -69,9 +69,13 @@ QList<int> QgsDensifyGeometriesByIntervalAlgorithm::inputLayerTypes() const
void QgsDensifyGeometriesByIntervalAlgorithm::initParameters( const QVariantMap &configuration )
{
Q_UNUSED( configuration )
addParameter( new QgsProcessingParameterDistance( QStringLiteral( "INTERVAL" ),
QObject::tr( "Interval between vertices to add" ),
1, QStringLiteral( "INPUT" ), false, 0, 10000000 ) );
std::unique_ptr<QgsProcessingParameterDistance> interval = qgis::make_unique<QgsProcessingParameterDistance>( QStringLiteral( "INTERVAL" ),
QObject::tr( "Interval between vertices to add" ),
1, QStringLiteral( "INPUT" ), false, 0, 10000000 );
interval->setIsDynamic( true );
interval->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Interval" ), QObject::tr( "Interval" ), QgsPropertyDefinition::DoublePositive ) );
interval->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( interval.release() );
}

QString QgsDensifyGeometriesByIntervalAlgorithm::outputName() const
Expand All @@ -84,6 +88,11 @@ QgsFeatureList QgsDensifyGeometriesByIntervalAlgorithm::processFeature( const Qg
Q_UNUSED( context );
Q_UNUSED( feedback );
QgsFeature modifiedFeature = feature;

double interval = mInterval;
if ( mDynamicInterval )
interval = mIntervalProperty.valueAsDouble( context.expressionContext(), interval );

if ( feature.hasGeometry() )
modifiedFeature.setGeometry( feature.geometry().densifyByDistance( mInterval ) );

Expand All @@ -94,5 +103,10 @@ bool QgsDensifyGeometriesByIntervalAlgorithm::prepareAlgorithm( const QVariantMa
{
Q_UNUSED( feedback );
mInterval = parameterAsDouble( parameters, QStringLiteral( "INTERVAL" ), context );

mDynamicInterval = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "INTERVAL" ) );
if ( mDynamicInterval )
mIntervalProperty = parameters.value( QStringLiteral( "INTERVAL" ) ).value< QgsProperty >();

return true;
}
Expand Up @@ -49,6 +49,8 @@ class QgsDensifyGeometriesByIntervalAlgorithm : public QgsProcessingFeatureBased

private:
double mInterval = 0.0;
bool mDynamicInterval = false;
QgsProperty mIntervalProperty;
};

///@endcond PRIVATE
Expand Down

0 comments on commit 9fec8ed

Please sign in to comment.