69 QVariantMap transformerMap = transformer.toMap();
71 mMinValue = transformerMap.value( QStringLiteral(
"minValue" ), 0.0 ).toDouble();
72 mMaxValue = transformerMap.value( QStringLiteral(
"maxValue" ), 1.0 ).toDouble();
75 QVariantMap curve = transformerMap.value( QStringLiteral(
"curve" ) ).toMap();
77 if ( !curve.isEmpty() )
88 QVariantMap transformerMap;
90 transformerMap.insert( QStringLiteral(
"minValue" ),
mMinValue );
91 transformerMap.insert( QStringLiteral(
"maxValue" ),
mMaxValue );
95 transformerMap.insert( QStringLiteral(
"curve" ),
mCurveTransform->toVariant() );
97 return transformerMap;
102 baseExpression.clear();
132 , mMinOutput( minOutput )
133 , mMaxOutput( maxOutput )
134 , mNullOutput( nullOutput )
135 , mExponent( exponent )
155 transformerMap.insert( QStringLiteral(
"minOutput" ), mMinOutput );
156 transformerMap.insert( QStringLiteral(
"maxOutput" ), mMaxOutput );
157 transformerMap.insert( QStringLiteral(
"nullOutput" ), mNullOutput );
158 transformerMap.insert( QStringLiteral(
"exponent" ), mExponent );
160 return transformerMap;
167 QVariantMap transformerMap = transformer.toMap();
169 mMinOutput = transformerMap.value( QStringLiteral(
"minOutput" ), 0.0 ).toDouble();
170 mMaxOutput = transformerMap.value( QStringLiteral(
"maxOutput" ), 1.0 ).toDouble();
171 mNullOutput = transformerMap.value( QStringLiteral(
"nullOutput" ), 0.0 ).toDouble();
172 mExponent = transformerMap.value( QStringLiteral(
"exponent" ), 1.0 ).toDouble();
179 return qBound( mMinOutput, input, mMaxOutput );
196 double dblValue = v.toDouble( &ok );
201 return value( dblValue );
211 QString minValueString = QString::number(
mMinValue );
212 QString maxValueString = QString::number(
mMaxValue );
213 QString minOutputString = QString::number( mMinOutput );
214 QString maxOutputString = QString::number( mMaxOutput );
215 QString nullOutputString = QString::number( mNullOutput );
216 QString exponentString = QString::number( mExponent );
219 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, nullOutputString );
221 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, exponentString, nullOutputString );
228 double nullValue = 0.0;
231 baseExpression.clear();
243 QList<QgsExpressionNode *> args = f->
args()->
list();
292 baseExpression = args[0]->
dump();
304 , mMinSize( minSize )
305 , mMaxSize( maxSize )
306 , mNullSize( nullSize )
307 , mExponent( exponent )
330 transformerMap.insert( QStringLiteral(
"scaleType" ), static_cast< int >( mType ) );
331 transformerMap.insert( QStringLiteral(
"minSize" ), mMinSize );
332 transformerMap.insert( QStringLiteral(
"maxSize" ), mMaxSize );
333 transformerMap.insert( QStringLiteral(
"nullSize" ), mNullSize );
334 transformerMap.insert( QStringLiteral(
"exponent" ), mExponent );
336 return transformerMap;
343 QVariantMap transformerMap = transformer.toMap();
345 mType =
static_cast< ScaleType >( transformerMap.value( QStringLiteral(
"scaleType" ),
Linear ).toInt() );
346 mMinSize = transformerMap.value( QStringLiteral(
"minSize" ), 0.0 ).toDouble();
347 mMaxSize = transformerMap.value( QStringLiteral(
"maxSize" ), 1.0 ).toDouble();
348 mNullSize = transformerMap.value( QStringLiteral(
"nullSize" ), 0.0 ).toDouble();
349 mExponent = transformerMap.value( QStringLiteral(
"exponent" ), 1.0 ).toDouble();
396 if ( value.isNull() )
400 double dblValue = value.toDouble( &ok );
405 return size( dblValue );
415 QString minValueString = QString::number(
mMinValue );
416 QString maxValueString = QString::number(
mMaxValue );
417 QString minSizeString = QString::number( mMinSize );
418 QString maxSizeString = QString::number( mMaxSize );
419 QString nullSizeString = QString::number( mNullSize );
420 QString exponentString = QString::number( mExponent );
425 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
430 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, exponentString, nullSizeString );
444 baseExpression.clear();
456 QList<QgsExpressionNode *> args = f->
args()->
list();
513 baseExpression = args[0]->
dump();
525 const QColor &nullColor )
527 , mGradientRamp( ramp )
528 , mNullColor( nullColor )
535 , mGradientRamp( other.mGradientRamp ? other.mGradientRamp->
clone() : nullptr )
536 , mNullColor( other.mNullColor )
537 , mRampName( other.mRampName )
547 mGradientRamp.reset( other.mGradientRamp ? other.mGradientRamp->clone() : nullptr );
548 mNullColor = other.mNullColor;
549 mRampName = other.mRampName;
556 mGradientRamp ? mGradientRamp->clone() :
nullptr,
558 c->setRampName( mRampName );
573 transformerMap.insert( QStringLiteral(
"rampName" ), mRampName );
575 return transformerMap;
580 QVariantMap transformerMap = definition.toMap();
584 mGradientRamp.reset(
nullptr );
585 if ( transformerMap.contains( QStringLiteral(
"colorramp" ) ) )
591 mRampName = transformerMap.value( QStringLiteral(
"rampName" ) ).toString();
599 if ( value.isNull() )
603 double dblValue = value.toDouble( &ok );
608 return color( dblValue );
618 if ( !mGradientRamp )
621 QString minValueString = QString::number(
mMinValue );
622 QString maxValueString = QString::number(
mMaxValue );
623 QString nullColorString = mNullColor.name();
625 return QStringLiteral(
"coalesce(ramp_color('%1',scale_linear(%2, %3, %4, 0, 1)), '%5')" ).arg( !mRampName.isEmpty() ? mRampName : QStringLiteral(
"custom ramp" ),
626 baseExpression, minValueString, maxValueString, nullColorString );
634 if ( !mGradientRamp )
637 return mGradientRamp->color( scaledVal );
642 return mGradientRamp.get();
647 mGradientRamp.reset( ramp );
657 return a.
x() < b.
x();
663 calcSecondDerivativeArray();
667 : mControlPoints( controlPoints )
669 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
670 calcSecondDerivativeArray();
675 delete [] mSecondDerivativeArray;
679 : mControlPoints( other.mControlPoints )
681 if ( other.mSecondDerivativeArray )
683 mSecondDerivativeArray =
new double[ mControlPoints.count()];
684 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
690 mControlPoints = other.mControlPoints;
691 if ( other.mSecondDerivativeArray )
693 delete [] mSecondDerivativeArray;
694 mSecondDerivativeArray =
new double[ mControlPoints.count()];
695 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
702 mControlPoints = points;
703 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
704 for (
int i = 0; i < mControlPoints.count(); ++i )
706 mControlPoints[ i ] =
QgsPointXY( qBound( 0.0, mControlPoints.at( i ).x(), 1.0 ),
707 qBound( 0.0, mControlPoints.at( i ).y(), 1.0 ) );
709 calcSecondDerivativeArray();
715 if ( mControlPoints.contains( point ) )
718 mControlPoints << point;
719 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
720 calcSecondDerivativeArray();
725 for (
int i = 0; i < mControlPoints.count(); ++i )
730 mControlPoints.removeAt( i );
734 calcSecondDerivativeArray();
743 int n = mControlPoints.count();
745 return qBound( 0.0, x, 1.0 );
749 if ( x <= mControlPoints.at( 0 ).x() )
750 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
751 else if ( x >= mControlPoints.at( n - 1 ).x() )
752 return qBound( 0.0, mControlPoints.at( 1 ).y(), 1.0 );
755 double dx = mControlPoints.at( 1 ).x() - mControlPoints.at( 0 ).x();
756 double dy = mControlPoints.at( 1 ).y() - mControlPoints.at( 0 ).y();
757 return qBound( 0.0, ( x - mControlPoints.at( 0 ).x() ) * ( dy / dx ) + mControlPoints.at( 0 ).y(), 1.0 );
762 if ( x <= mControlPoints.at( 0 ).x() )
763 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
764 if ( x >= mControlPoints.at( n - 1 ).x() )
765 return qBound( 0.0, mControlPoints.at( n - 1 ).y(), 1.0 );
768 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
773 for (
int i = 0; i < n - 1; ++i )
775 if ( x < nextControlPoint.
x() )
778 double h = nextControlPoint.
x() - currentControlPoint.
x();
779 double t = ( x - currentControlPoint.
x() ) / h;
783 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] ),
788 if ( pointIt == mControlPoints.constEnd() )
791 currentControlPoint = nextControlPoint;
792 nextControlPoint = *pointIt;
796 return qBound( 0.0, x, 1.0 );
805 QVector<double> result;
807 int n = mControlPoints.count();
811 const auto constX = x;
812 for (
double i : constX )
819 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
825 double currentX = x.at( xIndex );
827 while ( currentX <= currentControlPoint.
x() )
829 result << qBound( 0.0, currentControlPoint.
y(), 1.0 );
831 currentX = x.at( xIndex );
834 for (
int i = 0; i < n - 1; ++i )
836 while ( currentX < nextControlPoint.
x() )
839 double h = nextControlPoint.
x() - currentControlPoint.
x();
841 double t = ( currentX - currentControlPoint.
x() ) / h;
845 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 );
847 if ( xIndex == x.count() )
850 currentX = x.at( xIndex );
854 if ( pointIt == mControlPoints.constEnd() )
857 currentControlPoint = nextControlPoint;
858 nextControlPoint = *pointIt;
862 while ( xIndex < x.count() )
864 result << qBound( 0.0, nextControlPoint.
y(), 1.0 );
873 QString xString = elem.attribute( QStringLiteral(
"x" ) );
874 QString yString = elem.attribute( QStringLiteral(
"y" ) );
876 QStringList xVals = xString.split(
',' );
877 QStringList yVals = yString.split(
',' );
878 if ( xVals.count() != yVals.count() )
881 QList< QgsPointXY > newPoints;
883 for (
int i = 0; i < xVals.count(); ++i )
885 double x = xVals.at( i ).toDouble( &ok );
888 double y = yVals.at( i ).toDouble( &ok );
901 const auto constMControlPoints = mControlPoints;
902 for (
const QgsPointXY &p : constMControlPoints )
908 transformElem.setAttribute( QStringLiteral(
"x" ), x.join(
',' ) );
909 transformElem.setAttribute( QStringLiteral(
"y" ), y.join(
',' ) );
916 QVariantMap transformMap;
920 const auto constMControlPoints = mControlPoints;
921 for (
const QgsPointXY &p : constMControlPoints )
927 transformMap.insert( QStringLiteral(
"x" ), x.join(
',' ) );
928 transformMap.insert( QStringLiteral(
"y" ), y.join(
',' ) );
935 QVariantMap transformMap = transformer.toMap();
937 QString xString = transformMap.value( QStringLiteral(
"x" ) ).toString();
938 QString yString = transformMap.value( QStringLiteral(
"y" ) ).toString();
940 QStringList xVals = xString.split(
',' );
941 QStringList yVals = yString.split(
',' );
942 if ( xVals.count() != yVals.count() )
945 QList< QgsPointXY > newPoints;
947 for (
int i = 0; i < xVals.count(); ++i )
949 double x = xVals.at( i ).toDouble( &ok );
952 double y = yVals.at( i ).toDouble( &ok );
965 void QgsCurveTransform::calcSecondDerivativeArray()
967 int n = mControlPoints.count();
971 delete[] mSecondDerivativeArray;
973 double *matrix =
new double[ n * 3 ];
974 double *result =
new double[ n ];
979 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
986 for (
int i = 1; i < n - 1; ++i )
988 matrix[i * 3 + 0 ] = ( pointI.
x() - pointIm1.
x() ) / 6.0;
989 matrix[i * 3 + 1 ] = ( pointIp1.
x() - pointIm1.
x() ) / 3.0;
990 matrix[i * 3 + 2 ] = ( pointIp1.
x() - pointI.
x() ) / 6.0;
991 result[i] = ( pointIp1.
y() - pointI.
y() ) / ( pointIp1.
x() - pointI.
x() ) - ( pointI.
y() - pointIm1.
y() ) / ( pointI.
x() - pointIm1.
x() );
997 if ( pointIt == mControlPoints.constEnd() )
1000 pointIp1 = *pointIt;
1002 matrix[( n - 1 ) * 3 + 0] = 0;
1003 matrix[( n - 1 ) * 3 + 1] = 1;
1004 matrix[( n - 1 ) * 3 + 2] = 0;
1008 for (
int i = 1; i < n; ++i )
1010 double k = matrix[i * 3 + 0] / matrix[( i - 1 ) * 3 + 1];
1011 matrix[i * 3 + 1] -= k * matrix[( i - 1 ) * 3 + 2];
1012 matrix[i * 3 + 0] = 0;
1013 result[i] -= k * result[i - 1];
1016 for (
int i = n - 2; i >= 0; --i )
1018 double k = matrix[i * 3 + 2] / matrix[( i + 1 ) * 3 + 1];
1019 matrix[i * 3 + 1] -= k * matrix[( i + 1 ) * 3 + 0];
1020 matrix[i * 3 + 2] = 0;
1021 result[i] -= k * result[i + 1];
1025 mSecondDerivativeArray =
new double[n];
1026 for (
int i = 0; i < n; ++i )
1028 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.