[mvt] use scale_exponential expression

This commit is contained in:
Denis Rouzaud 2024-09-27 05:21:12 +02:00
parent 2bd635461a
commit edeb2a938d

View File

@ -2497,10 +2497,11 @@ QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateOpacityByZoom( const QVar
double top = 0.0;
const bool numeric = numericArgumentsOnly( bv, tv, bottom, top );
scaleExpression = QStringLiteral( "set_color_part(@symbol_color, 'alpha', %1)" )
.arg( interpolateExpression( stops.value( 0 ).toList().value( 0 ).toDouble(),
stops.last().toList().value( 0 ).toDouble(),
numeric ? QString::number( bottom * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
numeric ? QString::number( top * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ), base, 1, &context ) );
.arg( interpolateExpression(
stops.value( 0 ).toList().value( 0 ).toDouble(),
stops.last().toList().value( 0 ).toDouble(),
numeric ? QString::number( bottom * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
numeric ? QString::number( top * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ), base, 1, &context ) );
}
else
{
@ -2527,11 +2528,12 @@ QString QgsMapBoxGlStyleConverter::parseOpacityStops( double base, const QVarian
"THEN set_color_part(@symbol_color, 'alpha', %3)" )
.arg( stops.value( i ).toList().value( 0 ).toString(),
stops.value( i + 1 ).toList().value( 0 ).toString(),
interpolateExpression( stops.value( i ).toList().value( 0 ).toDouble(),
stops.value( i + 1 ).toList().value( 0 ).toDouble(),
numeric ? QString::number( bottom * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
numeric ? QString::number( top * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
base, 1, &context ) );
interpolateExpression(
stops.value( i ).toList().value( 0 ).toDouble(),
stops.value( i + 1 ).toList().value( 0 ).toDouble(),
numeric ? QString::number( bottom * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
numeric ? QString::number( top * maxOpacity ) : QString( "(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
base, 1, &context ) );
}
@ -3217,23 +3219,11 @@ QString QgsMapBoxGlStyleConverter::interpolateExpression( double zoomMin, double
{
if ( base == 1 )
{
expression = QStringLiteral( "scale_linear(@vector_tile_zoom,%1,%2,%3,%4)" ).arg( zoomMin )
.arg( zoomMax )
.arg( minValueExpr )
.arg( maxValueExpr );
expression = QStringLiteral( "scale_linear(@vector_tile_zoom,%1,%2,%3,%4)" ).arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr );
}
else
{
// use formula to scale value exponentially as scale_exp expression function
// gives wrong resutls, see https://github.com/qgis/QGIS/pull/53164
QString ratioExpr = QStringLiteral( "(%1^(@vector_tile_zoom - %2) - 1) / (%1^(%3 - %2) - 1)" ).arg( base ).arg( zoomMin ).arg( zoomMax );
expression = QStringLiteral( "(%1) + (%2) * ((%3) - (%1))" ).arg( minValueExpr ).arg( ratioExpr ).arg( maxValueExpr );
// can be uncommented when scale_exponential expression function gets to the old LTR
//expression = QStringLiteral( "scale_exponential(@vector_tile_zoom,%1,%2,%3,%4,%5)" ).arg( zoomMin )
// .arg( zoomMax )
// .arg( minValueExpr )
// .arg( maxValueExpr )
// .arg( base );
expression = QStringLiteral( "scale_exponential(@vector_tile_zoom,%1,%2,%3,%4,%5)" ).arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr ).arg( base );
}
}