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 const auto constX = x;
809 for (
double i : constX )
816 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
822 double currentX = x.at( xIndex );
824 while ( currentX <= currentControlPoint.
x() )
826 result << qBound( 0.0, currentControlPoint.
y(), 1.0 );
828 currentX = x.at( xIndex );
831 for (
int i = 0; i < n - 1; ++i )
833 while ( currentX < nextControlPoint.
x() )
836 double h = nextControlPoint.
x() - currentControlPoint.
x();
838 double t = ( currentX - currentControlPoint.
x() ) / h;
842 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 );
844 if ( xIndex == x.count() )
847 currentX = x.at( xIndex );
851 if ( pointIt == mControlPoints.constEnd() )
854 currentControlPoint = nextControlPoint;
855 nextControlPoint = *pointIt;
859 while ( xIndex < x.count() )
861 result << qBound( 0.0, nextControlPoint.
y(), 1.0 );
870 QString xString = elem.attribute( QStringLiteral(
"x" ) );
871 QString yString = elem.attribute( QStringLiteral(
"y" ) );
873 QStringList xVals = xString.split(
',' );
874 QStringList yVals = yString.split(
',' );
875 if ( xVals.count() != yVals.count() )
878 QList< QgsPointXY > newPoints;
880 for (
int i = 0; i < xVals.count(); ++i )
882 double x = xVals.at( i ).toDouble( &ok );
885 double y = yVals.at( i ).toDouble( &ok );
898 const auto constMControlPoints = mControlPoints;
899 for (
const QgsPointXY &p : constMControlPoints )
905 transformElem.setAttribute( QStringLiteral(
"x" ), x.join(
',' ) );
906 transformElem.setAttribute( QStringLiteral(
"y" ), y.join(
',' ) );
913 QVariantMap transformMap;
917 const auto constMControlPoints = mControlPoints;
918 for (
const QgsPointXY &p : constMControlPoints )
924 transformMap.insert( QStringLiteral(
"x" ), x.join(
',' ) );
925 transformMap.insert( QStringLiteral(
"y" ), y.join(
',' ) );
932 QVariantMap transformMap = transformer.toMap();
934 QString xString = transformMap.value( QStringLiteral(
"x" ) ).toString();
935 QString yString = transformMap.value( QStringLiteral(
"y" ) ).toString();
937 QStringList xVals = xString.split(
',' );
938 QStringList yVals = yString.split(
',' );
939 if ( xVals.count() != yVals.count() )
942 QList< QgsPointXY > newPoints;
944 for (
int i = 0; i < xVals.count(); ++i )
946 double x = xVals.at( i ).toDouble( &ok );
949 double y = yVals.at( i ).toDouble( &ok );
962 void QgsCurveTransform::calcSecondDerivativeArray()
964 int n = mControlPoints.count();
968 delete[] mSecondDerivativeArray;
970 double *matrix =
new double[ n * 3 ];
971 double *result =
new double[ n ];
976 QList<QgsPointXY>::const_iterator pointIt = mControlPoints.constBegin();
983 for (
int i = 1; i < n - 1; ++i )
985 matrix[i * 3 + 0 ] = ( pointI.
x() - pointIm1.
x() ) / 6.0;
986 matrix[i * 3 + 1 ] = ( pointIp1.
x() - pointIm1.
x() ) / 3.0;
987 matrix[i * 3 + 2 ] = ( pointIp1.
x() - pointI.
x() ) / 6.0;
988 result[i] = ( pointIp1.
y() - pointI.
y() ) / ( pointIp1.
x() - pointI.
x() ) - ( pointI.
y() - pointIm1.
y() ) / ( pointI.
x() - pointIm1.
x() );
994 if ( pointIt == mControlPoints.constEnd() )
999 matrix[( n - 1 ) * 3 + 0] = 0;
1000 matrix[( n - 1 ) * 3 + 1] = 1;
1001 matrix[( n - 1 ) * 3 + 2] = 0;
1005 for (
int i = 1; i < n; ++i )
1007 double k = matrix[i * 3 + 0] / matrix[( i - 1 ) * 3 + 1];
1008 matrix[i * 3 + 1] -= k * matrix[( i - 1 ) * 3 + 2];
1009 matrix[i * 3 + 0] = 0;
1010 result[i] -= k * result[i - 1];
1013 for (
int i = n - 2; i >= 0; --i )
1015 double k = matrix[i * 3 + 2] / matrix[( i + 1 ) * 3 + 1];
1016 matrix[i * 3 + 1] -= k * matrix[( i + 1 ) * 3 + 0];
1017 matrix[i * 3 + 2] = 0;
1018 result[i] -= k * result[i + 1];
1022 mSecondDerivativeArray =
new double[n];
1023 for (
int i = 0; i < n; ++i )
1025 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.