71 QVariantMap transformerMap = transformer.toMap();
73 mMinValue = transformerMap.value( QStringLiteral(
"minValue" ), 0.0 ).toDouble();
74 mMaxValue = transformerMap.value( QStringLiteral(
"maxValue" ), 1.0 ).toDouble();
77 QVariantMap curve = transformerMap.value( QStringLiteral(
"curve" ) ).toMap();
79 if ( !curve.isEmpty() )
90 QVariantMap transformerMap;
92 transformerMap.insert( QStringLiteral(
"minValue" ),
mMinValue );
93 transformerMap.insert( QStringLiteral(
"maxValue" ),
mMaxValue );
97 transformerMap.insert( QStringLiteral(
"curve" ),
mCurveTransform->toVariant() );
99 return transformerMap;
104 baseExpression.clear();
134 , mMinOutput( minOutput )
135 , mMaxOutput( maxOutput )
136 , mNullOutput( nullOutput )
137 , mExponent( exponent )
157 transformerMap.insert( QStringLiteral(
"minOutput" ), mMinOutput );
158 transformerMap.insert( QStringLiteral(
"maxOutput" ), mMaxOutput );
159 transformerMap.insert( QStringLiteral(
"nullOutput" ), mNullOutput );
160 transformerMap.insert( QStringLiteral(
"exponent" ), mExponent );
162 return transformerMap;
169 QVariantMap transformerMap = transformer.toMap();
171 mMinOutput = transformerMap.value( QStringLiteral(
"minOutput" ), 0.0 ).toDouble();
172 mMaxOutput = transformerMap.value( QStringLiteral(
"maxOutput" ), 1.0 ).toDouble();
173 mNullOutput = transformerMap.value( QStringLiteral(
"nullOutput" ), 0.0 ).toDouble();
174 mExponent = transformerMap.value( QStringLiteral(
"exponent" ), 1.0 ).toDouble();
181 return qBound( mMinOutput, input, mMaxOutput );
198 double dblValue = v.toDouble( &ok );
203 return value( dblValue );
213 QString minValueString = QString::number(
mMinValue );
214 QString maxValueString = QString::number(
mMaxValue );
215 QString minOutputString = QString::number( mMinOutput );
216 QString maxOutputString = QString::number( mMaxOutput );
217 QString nullOutputString = QString::number( mNullOutput );
218 QString exponentString = QString::number( mExponent );
221 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, nullOutputString );
223 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, exponentString, nullOutputString );
230 double nullValue = 0.0;
233 baseExpression.clear();
245 QList<QgsExpressionNode *> args = f->
args()->
list();
294 baseExpression = args[0]->
dump();
306 , mMinSize( minSize )
307 , mMaxSize( maxSize )
308 , mNullSize( nullSize )
309 , mExponent( exponent )
332 transformerMap.insert( QStringLiteral(
"scaleType" ), static_cast< int >( mType ) );
333 transformerMap.insert( QStringLiteral(
"minSize" ), mMinSize );
334 transformerMap.insert( QStringLiteral(
"maxSize" ), mMaxSize );
335 transformerMap.insert( QStringLiteral(
"nullSize" ), mNullSize );
336 transformerMap.insert( QStringLiteral(
"exponent" ), mExponent );
338 return transformerMap;
345 QVariantMap transformerMap = transformer.toMap();
347 mType =
static_cast< ScaleType >( transformerMap.value( QStringLiteral(
"scaleType" ),
Linear ).toInt() );
348 mMinSize = transformerMap.value( QStringLiteral(
"minSize" ), 0.0 ).toDouble();
349 mMaxSize = transformerMap.value( QStringLiteral(
"maxSize" ), 1.0 ).toDouble();
350 mNullSize = transformerMap.value( QStringLiteral(
"nullSize" ), 0.0 ).toDouble();
351 mExponent = transformerMap.value( QStringLiteral(
"exponent" ), 1.0 ).toDouble();
398 if ( value.isNull() )
402 double dblValue = value.toDouble( &ok );
407 return size( dblValue );
417 QString minValueString = QString::number(
mMinValue );
418 QString maxValueString = QString::number(
mMaxValue );
419 QString minSizeString = QString::number( mMinSize );
420 QString maxSizeString = QString::number( mMaxSize );
421 QString nullSizeString = QString::number( mNullSize );
422 QString exponentString = QString::number( mExponent );
427 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
432 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, exponentString, nullSizeString );
446 baseExpression.clear();
458 QList<QgsExpressionNode *> args = f->
args()->
list();
515 baseExpression = args[0]->
dump();
527 const QColor &nullColor )
529 , mGradientRamp( ramp )
530 , mNullColor( nullColor )
537 , mGradientRamp( other.mGradientRamp ? other.mGradientRamp->
clone() : nullptr )
538 , mNullColor( other.mNullColor )
539 , mRampName( other.mRampName )
549 mGradientRamp.reset( other.mGradientRamp ? other.mGradientRamp->clone() : nullptr );
550 mNullColor = other.mNullColor;
551 mRampName = other.mRampName;
558 mGradientRamp ? mGradientRamp->clone() :
nullptr,
560 c->setRampName( mRampName );
575 transformerMap.insert( QStringLiteral(
"rampName" ), mRampName );
577 return transformerMap;
582 QVariantMap transformerMap = definition.toMap();
586 mGradientRamp.reset(
nullptr );
587 if ( transformerMap.contains( QStringLiteral(
"colorramp" ) ) )
593 mRampName = transformerMap.value( QStringLiteral(
"rampName" ) ).toString();
601 if ( value.isNull() )
605 double dblValue = value.toDouble( &ok );
610 return color( dblValue );
620 if ( !mGradientRamp )
623 QString minValueString = QString::number(
mMinValue );
624 QString maxValueString = QString::number(
mMaxValue );
625 QString nullColorString = mNullColor.name();
627 return QStringLiteral(
"coalesce(ramp_color('%1',scale_linear(%2, %3, %4, 0, 1)), '%5')" ).arg( !mRampName.isEmpty() ? mRampName : QStringLiteral(
"custom ramp" ),
628 baseExpression, minValueString, maxValueString, nullColorString );
636 if ( !mGradientRamp )
639 return mGradientRamp->color( scaledVal );
644 return mGradientRamp.get();
649 mGradientRamp.reset( ramp );
659 return a.
x() < b.
x();
665 calcSecondDerivativeArray();
669 : mControlPoints( controlPoints )
671 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
672 calcSecondDerivativeArray();
677 delete [] mSecondDerivativeArray;
681 : mControlPoints( other.mControlPoints )
683 if ( other.mSecondDerivativeArray )
685 mSecondDerivativeArray =
new double[ mControlPoints.count()];
686 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
692 mControlPoints = other.mControlPoints;
693 if ( other.mSecondDerivativeArray )
695 delete [] mSecondDerivativeArray;
696 mSecondDerivativeArray =
new double[ mControlPoints.count()];
697 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
704 mControlPoints = points;
705 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
706 for (
int i = 0; i < mControlPoints.count(); ++i )
708 mControlPoints[ i ] =
QgsPointXY( qBound( 0.0, mControlPoints.at( i ).x(), 1.0 ),
709 qBound( 0.0, mControlPoints.at( i ).y(), 1.0 ) );
711 calcSecondDerivativeArray();
717 if ( mControlPoints.contains( point ) )
720 mControlPoints << point;
721 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
722 calcSecondDerivativeArray();
727 for (
int i = 0; i < mControlPoints.count(); ++i )
732 mControlPoints.removeAt( i );
736 calcSecondDerivativeArray();
745 int n = mControlPoints.count();
747 return qBound( 0.0, x, 1.0 );
751 if ( x <= mControlPoints.at( 0 ).x() )
752 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
753 else if ( x >= mControlPoints.at( n - 1 ).x() )
754 return qBound( 0.0, mControlPoints.at( 1 ).y(), 1.0 );
757 double dx = mControlPoints.at( 1 ).x() - mControlPoints.at( 0 ).x();
758 double dy = mControlPoints.at( 1 ).y() - mControlPoints.at( 0 ).y();
759 return qBound( 0.0, ( x - mControlPoints.at( 0 ).x() ) * ( dy / dx ) + mControlPoints.at( 0 ).y(), 1.0 );
764 if ( x <= mControlPoints.at( 0 ).x() )
765 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
766 if ( x >= mControlPoints.at( n - 1 ).x() )
767 return qBound( 0.0, mControlPoints.at( n - 1 ).y(), 1.0 );
770 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
775 for (
int i = 0; i < n - 1; ++i )
777 if ( x < nextControlPoint.
x() )
780 double h = nextControlPoint.
x() - currentControlPoint.
x();
781 double t = ( x - currentControlPoint.
x() ) / h;
785 return qBound( 0.0, a * currentControlPoint.
y() + t * nextControlPoint.
y() + ( h * h / 6 ) * ( ( a * a * a - a ) * mSecondDerivativeArray[i] + ( t * t * t - t ) * mSecondDerivativeArray[i + 1] ),
790 if ( pointIt == mControlPoints.constEnd() )
793 currentControlPoint = nextControlPoint;
794 nextControlPoint = *pointIt;
798 return qBound( 0.0, x, 1.0 );
807 QVector<double> result;
809 int n = mControlPoints.count();
813 const auto constX = x;
814 for (
double i : constX )
821 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
827 double currentX = x.at( xIndex );
829 while ( currentX <= currentControlPoint.
x() )
831 result << qBound( 0.0, currentControlPoint.
y(), 1.0 );
833 currentX = x.at( xIndex );
836 for (
int i = 0; i < n - 1; ++i )
838 while ( currentX < nextControlPoint.
x() )
841 double h = nextControlPoint.
x() - currentControlPoint.
x();
843 double t = ( currentX - currentControlPoint.
x() ) / h;
847 result << qBound( 0.0, a * currentControlPoint.
y() + t * nextControlPoint.
y() + ( h * h / 6 ) * ( ( a * a * a - a )*mSecondDerivativeArray[i] + ( t * t * t - t )*mSecondDerivativeArray[i + 1] ), 1.0 );
849 if ( xIndex == x.count() )
852 currentX = x.at( xIndex );
856 if ( pointIt == mControlPoints.constEnd() )
859 currentControlPoint = nextControlPoint;
860 nextControlPoint = *pointIt;
864 while ( xIndex < x.count() )
866 result << qBound( 0.0, nextControlPoint.
y(), 1.0 );
875 QString xString = elem.attribute( QStringLiteral(
"x" ) );
876 QString yString = elem.attribute( QStringLiteral(
"y" ) );
878 QStringList xVals = xString.split(
',' );
879 QStringList yVals = yString.split(
',' );
880 if ( xVals.count() != yVals.count() )
883 QList< QgsPointXY > newPoints;
885 for (
int i = 0; i < xVals.count(); ++i )
887 double x = xVals.at( i ).toDouble( &ok );
890 double y = yVals.at( i ).toDouble( &ok );
903 const auto constMControlPoints = mControlPoints;
904 for (
const QgsPointXY &p : constMControlPoints )
910 transformElem.setAttribute( QStringLiteral(
"x" ), x.join(
',' ) );
911 transformElem.setAttribute( QStringLiteral(
"y" ), y.join(
',' ) );
918 QVariantMap transformMap;
922 const auto constMControlPoints = mControlPoints;
923 for (
const QgsPointXY &p : constMControlPoints )
929 transformMap.insert( QStringLiteral(
"x" ), x.join(
',' ) );
930 transformMap.insert( QStringLiteral(
"y" ), y.join(
',' ) );
937 QVariantMap transformMap = transformer.toMap();
939 QString xString = transformMap.value( QStringLiteral(
"x" ) ).toString();
940 QString yString = transformMap.value( QStringLiteral(
"y" ) ).toString();
942 QStringList xVals = xString.split(
',' );
943 QStringList yVals = yString.split(
',' );
944 if ( xVals.count() != yVals.count() )
947 QList< QgsPointXY > newPoints;
949 for (
int i = 0; i < xVals.count(); ++i )
951 double x = xVals.at( i ).toDouble( &ok );
954 double y = yVals.at( i ).toDouble( &ok );
967 void QgsCurveTransform::calcSecondDerivativeArray()
969 int n = mControlPoints.count();
973 delete[] mSecondDerivativeArray;
975 double *matrix =
new double[ n * 3 ];
976 double *result =
new double[ n ];
981 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
988 for (
int i = 1; i < n - 1; ++i )
990 matrix[i * 3 + 0 ] = ( pointI.
x() - pointIm1.
x() ) / 6.0;
991 matrix[i * 3 + 1 ] = ( pointIp1.
x() - pointIm1.
x() ) / 3.0;
992 matrix[i * 3 + 2 ] = ( pointIp1.
x() - pointI.
x() ) / 6.0;
993 result[i] = ( pointIp1.
y() - pointI.
y() ) / ( pointIp1.
x() - pointI.
x() ) - ( pointI.
y() - pointIm1.
y() ) / ( pointI.
x() - pointIm1.
x() );
999 if ( pointIt == mControlPoints.constEnd() )
1002 pointIp1 = *pointIt;
1004 matrix[( n - 1 ) * 3 + 0] = 0;
1005 matrix[( n - 1 ) * 3 + 1] = 1;
1006 matrix[( n - 1 ) * 3 + 2] = 0;
1010 for (
int i = 1; i < n; ++i )
1012 double k = matrix[i * 3 + 0] / matrix[( i - 1 ) * 3 + 1];
1013 matrix[i * 3 + 1] -= k * matrix[( i - 1 ) * 3 + 2];
1014 matrix[i * 3 + 0] = 0;
1015 result[i] -= k * result[i - 1];
1018 for (
int i = n - 2; i >= 0; --i )
1020 double k = matrix[i * 3 + 2] / matrix[( i + 1 ) * 3 + 1];
1021 matrix[i * 3 + 1] -= k * matrix[( i + 1 ) * 3 + 0];
1022 matrix[i * 3 + 2] = 0;
1023 result[i] -= k * result[i + 1];
1027 mSecondDerivativeArray =
new double[n];
1028 for (
int i = 0; i < n; ++i )
1030 mSecondDerivativeArray[i] = result[i] / matrix[( i * 3 ) + 1];
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Abstract base class for color ramps.
QVariant evaluate()
Evaluate the feature and return the result.
static QString encodeColor(const QColor &color)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
static QVariant colorRampToVariant(const QString &name, QgsColorRamp *ramp)
Saves a color ramp to a QVariantMap, wrapped in a QVariant.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An expression node which takes it value from a feature's field.
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
An expression node for expression functions.
static const QList< QgsExpressionFunction * > & Functions()
QString dump() const override
Dump this node into a serialized (part) of an expression.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
static QColor decodeColor(const QString &str)
int fnIndex() const
Returns the index of the node's function.