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();
193 double dblValue = v.toDouble( &ok );
198 return value( dblValue );
208 QString minValueString = QString::number(
mMinValue );
209 QString maxValueString = QString::number(
mMaxValue );
210 QString minOutputString = QString::number( mMinOutput );
211 QString maxOutputString = QString::number( mMaxOutput );
212 QString nullOutputString = QString::number( mNullOutput );
213 QString exponentString = QString::number( mExponent );
216 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, nullOutputString );
218 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minOutputString, maxOutputString, exponentString, nullOutputString );
225 double nullValue = 0.0;
228 baseExpression.clear();
240 QList<QgsExpressionNode *> args = f->
args()->
list();
289 baseExpression = args[0]->
dump();
301 , mMinSize( minSize )
302 , mMaxSize( maxSize )
303 , mNullSize( nullSize )
304 , mExponent( exponent )
327 transformerMap.insert( QStringLiteral(
"scaleType" ), static_cast< int >( mType ) );
328 transformerMap.insert( QStringLiteral(
"minSize" ), mMinSize );
329 transformerMap.insert( QStringLiteral(
"maxSize" ), mMaxSize );
330 transformerMap.insert( QStringLiteral(
"nullSize" ), mNullSize );
331 transformerMap.insert( QStringLiteral(
"exponent" ), mExponent );
333 return transformerMap;
340 QVariantMap transformerMap = transformer.toMap();
342 mType =
static_cast< ScaleType >( transformerMap.value( QStringLiteral(
"scaleType" ),
Linear ).toInt() );
343 mMinSize = transformerMap.value( QStringLiteral(
"minSize" ), 0.0 ).toDouble();
344 mMaxSize = transformerMap.value( QStringLiteral(
"maxSize" ), 1.0 ).toDouble();
345 mNullSize = transformerMap.value( QStringLiteral(
"nullSize" ), 0.0 ).toDouble();
346 mExponent = transformerMap.value( QStringLiteral(
"exponent" ), 1.0 ).toDouble();
393 if ( value.isNull() )
397 double dblValue = value.toDouble( &ok );
402 return size( dblValue );
412 QString minValueString = QString::number(
mMinValue );
413 QString maxValueString = QString::number(
mMaxValue );
414 QString minSizeString = QString::number( mMinSize );
415 QString maxSizeString = QString::number( mMaxSize );
416 QString nullSizeString = QString::number( mNullSize );
417 QString exponentString = QString::number( mExponent );
422 return QStringLiteral(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
427 return QStringLiteral(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).arg( baseExpression, minValueString, maxValueString, minSizeString, maxSizeString, exponentString, nullSizeString );
441 baseExpression.clear();
453 QList<QgsExpressionNode *> args = f->
args()->
list();
510 baseExpression = args[0]->
dump();
522 const QColor &nullColor )
524 , mGradientRamp( ramp )
525 , mNullColor( nullColor )
532 , mGradientRamp( other.mGradientRamp ? other.mGradientRamp->
clone() : nullptr )
533 , mNullColor( other.mNullColor )
534 , mRampName( other.mRampName )
544 mGradientRamp.reset( other.mGradientRamp ? other.mGradientRamp->clone() : nullptr );
545 mNullColor = other.mNullColor;
546 mRampName = other.mRampName;
553 mGradientRamp ? mGradientRamp->clone() :
nullptr,
555 c->setRampName( mRampName );
570 transformerMap.insert( QStringLiteral(
"rampName" ), mRampName );
572 return transformerMap;
577 QVariantMap transformerMap = definition.toMap();
581 mGradientRamp.reset(
nullptr );
582 if ( transformerMap.contains( QStringLiteral(
"colorramp" ) ) )
588 mRampName = transformerMap.value( QStringLiteral(
"rampName" ) ).toString();
596 if ( value.isNull() )
600 double dblValue = value.toDouble( &ok );
605 return color( dblValue );
615 if ( !mGradientRamp )
618 QString minValueString = QString::number(
mMinValue );
619 QString maxValueString = QString::number(
mMaxValue );
620 QString nullColorString = mNullColor.name();
622 return QStringLiteral(
"coalesce(ramp_color('%1',scale_linear(%2, %3, %4, 0, 1)), '%5')" ).arg( !mRampName.isEmpty() ? mRampName : QStringLiteral(
"custom ramp" ),
623 baseExpression, minValueString, maxValueString, nullColorString );
631 if ( !mGradientRamp )
634 return mGradientRamp->color( scaledVal );
639 return mGradientRamp.get();
644 mGradientRamp.reset( ramp );
654 return a.
x() < b.
x();
660 calcSecondDerivativeArray();
664 : mControlPoints( controlPoints )
666 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
667 calcSecondDerivativeArray();
672 delete [] mSecondDerivativeArray;
676 : mControlPoints( other.mControlPoints )
678 if ( other.mSecondDerivativeArray )
680 mSecondDerivativeArray =
new double[ mControlPoints.count()];
681 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
687 mControlPoints = other.mControlPoints;
688 if ( other.mSecondDerivativeArray )
690 delete [] mSecondDerivativeArray;
691 mSecondDerivativeArray =
new double[ mControlPoints.count()];
692 memcpy( mSecondDerivativeArray, other.mSecondDerivativeArray,
sizeof(
double ) * mControlPoints.count() );
699 mControlPoints = points;
700 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
701 for (
int i = 0; i < mControlPoints.count(); ++i )
703 mControlPoints[ i ] =
QgsPointXY( qBound( 0.0, mControlPoints.at( i ).x(), 1.0 ),
704 qBound( 0.0, mControlPoints.at( i ).y(), 1.0 ) );
706 calcSecondDerivativeArray();
712 if ( mControlPoints.contains( point ) )
715 mControlPoints << point;
716 std::sort( mControlPoints.begin(), mControlPoints.end(),
sortByX );
717 calcSecondDerivativeArray();
722 for (
int i = 0; i < mControlPoints.count(); ++i )
727 mControlPoints.removeAt( i );
731 calcSecondDerivativeArray();
740 int n = mControlPoints.count();
742 return qBound( 0.0, x, 1.0 );
746 if ( x <= mControlPoints.at( 0 ).x() )
747 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
748 else if ( x >= mControlPoints.at( n - 1 ).x() )
749 return qBound( 0.0, mControlPoints.at( 1 ).y(), 1.0 );
752 double dx = mControlPoints.at( 1 ).x() - mControlPoints.at( 0 ).x();
753 double dy = mControlPoints.at( 1 ).y() - mControlPoints.at( 0 ).y();
754 return qBound( 0.0, ( x - mControlPoints.at( 0 ).x() ) * ( dy / dx ) + mControlPoints.at( 0 ).y(), 1.0 );
759 if ( x <= mControlPoints.at( 0 ).x() )
760 return qBound( 0.0, mControlPoints.at( 0 ).y(), 1.0 );
761 if ( x >= mControlPoints.at( n - 1 ).x() )
762 return qBound( 0.0, mControlPoints.at( n - 1 ).y(), 1.0 );
765 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
770 for (
int i = 0; i < n - 1; ++i )
772 if ( x < nextControlPoint.
x() )
775 double h = nextControlPoint.
x() - currentControlPoint.
x();
776 double t = ( x - currentControlPoint.
x() ) / h;
780 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] ),
785 if ( pointIt == mControlPoints.constEnd() )
788 currentControlPoint = nextControlPoint;
789 nextControlPoint = *pointIt;
793 return qBound( 0.0, x, 1.0 );
802 QVector<double> result;
804 int n = mControlPoints.count();
808 Q_FOREACH (
double i, x )
815 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
821 double currentX = x.at( xIndex );
823 while ( currentX <= currentControlPoint.
x() )
825 result << qBound( 0.0, currentControlPoint.
y(), 1.0 );
827 currentX = x.at( xIndex );
830 for (
int i = 0; i < n - 1; ++i )
832 while ( currentX < nextControlPoint.
x() )
835 double h = nextControlPoint.
x() - currentControlPoint.
x();
837 double t = ( currentX - currentControlPoint.
x() ) / h;
841 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 );
843 if ( xIndex == x.count() )
846 currentX = x.at( xIndex );
850 if ( pointIt == mControlPoints.constEnd() )
853 currentControlPoint = nextControlPoint;
854 nextControlPoint = *pointIt;
858 while ( xIndex < x.count() )
860 result << qBound( 0.0, nextControlPoint.
y(), 1.0 );
869 QString xString = elem.attribute( QStringLiteral(
"x" ) );
870 QString yString = elem.attribute( QStringLiteral(
"y" ) );
872 QStringList xVals = xString.split(
',' );
873 QStringList yVals = yString.split(
',' );
874 if ( xVals.count() != yVals.count() )
877 QList< QgsPointXY > newPoints;
879 for (
int i = 0; i < xVals.count(); ++i )
881 double x = xVals.at( i ).toDouble( &ok );
884 double y = yVals.at( i ).toDouble( &ok );
897 Q_FOREACH (
const QgsPointXY &p, mControlPoints )
903 transformElem.setAttribute( QStringLiteral(
"x" ), x.join(
',' ) );
904 transformElem.setAttribute( QStringLiteral(
"y" ), y.join(
',' ) );
911 QVariantMap transformMap;
915 Q_FOREACH (
const QgsPointXY &p, mControlPoints )
921 transformMap.insert( QStringLiteral(
"x" ), x.join(
',' ) );
922 transformMap.insert( QStringLiteral(
"y" ), y.join(
',' ) );
929 QVariantMap transformMap = transformer.toMap();
931 QString xString = transformMap.value( QStringLiteral(
"x" ) ).toString();
932 QString yString = transformMap.value( QStringLiteral(
"y" ) ).toString();
934 QStringList xVals = xString.split(
',' );
935 QStringList yVals = yString.split(
',' );
936 if ( xVals.count() != yVals.count() )
939 QList< QgsPointXY > newPoints;
941 for (
int i = 0; i < xVals.count(); ++i )
943 double x = xVals.at( i ).toDouble( &ok );
946 double y = yVals.at( i ).toDouble( &ok );
959 void QgsCurveTransform::calcSecondDerivativeArray()
961 int n = mControlPoints.count();
965 delete[] mSecondDerivativeArray;
967 double *matrix =
new double[ n * 3 ];
968 double *result =
new double[ n ];
973 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
980 for (
int i = 1; i < n - 1; ++i )
982 matrix[i * 3 + 0 ] = ( pointI.
x() - pointIm1.
x() ) / 6.0;
983 matrix[i * 3 + 1 ] = ( pointIp1.
x() - pointIm1.
x() ) / 3.0;
984 matrix[i * 3 + 2 ] = ( pointIp1.
x() - pointI.
x() ) / 6.0;
985 result[i] = ( pointIp1.
y() - pointI.
y() ) / ( pointIp1.
x() - pointI.
x() ) - ( pointI.
y() - pointIm1.
y() ) / ( pointI.
x() - pointIm1.
x() );
991 if ( pointIt == mControlPoints.constEnd() )
996 matrix[( n - 1 ) * 3 + 0] = 0;
997 matrix[( n - 1 ) * 3 + 1] = 1;
998 matrix[( n - 1 ) * 3 + 2] = 0;
1002 for (
int i = 1; i < n; ++i )
1004 double k = matrix[i * 3 + 0] / matrix[( i - 1 ) * 3 + 1];
1005 matrix[i * 3 + 1] -= k * matrix[( i - 1 ) * 3 + 2];
1006 matrix[i * 3 + 0] = 0;
1007 result[i] -= k * result[i - 1];
1010 for (
int i = n - 2; i >= 0; --i )
1012 double k = matrix[i * 3 + 2] / matrix[( i + 1 ) * 3 + 1];
1013 matrix[i * 3 + 1] -= k * matrix[( i + 1 ) * 3 + 0];
1014 matrix[i * 3 + 2] = 0;
1015 result[i] -= k * result[i + 1];
1019 mSecondDerivativeArray =
new double[n];
1020 for (
int i = 0; i < n; ++i )
1022 mSecondDerivativeArray[i] = result[i] / matrix[( i * 3 ) + 1];
Class for parsing and evaluation of expressions (formerly called "search strings").
int fnIndex() const
Returns the index of the node's 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.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
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 root node of the expression. Root node is null is parsing has failed.
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)