64 #include <QProcessEnvironment>
65 #include <QCryptographicHash>
66 #include <QRegularExpression>
88 QVariantList argValues;
92 const QList< QgsExpressionNode * > argList = args->
list();
99 v = QVariant::fromValue( n );
103 v = n->eval( parent, context );
105 bool defaultParamIsNull = mParameterList.count() > arg && mParameterList.at( arg ).optional() && !mParameterList.at( arg ).defaultValue().isValid();
106 if ( QgsExpressionUtils::isNull( v ) && !defaultParamIsNull && !
handlesNull() )
109 argValues.append( v );
114 return func( argValues, context, parent, node );
125 return QStringList();
152 return mGroups.isEmpty() ? false : mGroups.contains( QStringLiteral(
"deprecated" ) );
157 return ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 );
169 const QString &group,
170 const QString &helpText,
174 const QStringList &aliases,
178 , mAliases( aliases )
179 , mUsesGeometry( false )
180 , mUsesGeometryFunc( usesGeometry )
181 , mReferencedColumnsFunc( referencedColumns )
193 if ( mUsesGeometryFunc )
194 return mUsesGeometryFunc( node );
196 return mUsesGeometry;
201 if ( mReferencedColumnsFunc )
202 return mReferencedColumnsFunc( node );
204 return mReferencedColumns;
210 return mIsStaticFunc( node, parent, context );
218 return mPrepareFunc( node, parent, context );
230 mIsStaticFunc =
nullptr;
236 mPrepareFunc = prepareFunc;
241 if ( node && node->
args() )
243 const QList< QgsExpressionNode * > argList = node->
args()->
list();
246 if ( !argNode->isStatic( parent, context ) )
256 double start = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
257 double stop = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
258 double step = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
260 if ( step == 0.0 || ( step > 0.0 && start > stop ) || ( step < 0.0 && start < stop ) )
267 double current = start + step;
268 while ( ( ( step > 0.0 && current <= stop ) || ( step < 0.0 && current >= stop ) ) && length <= 1000000 )
283 QString name = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
289 QString templateString = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
298 QString expString = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
300 return expression.evaluate( context );
305 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
306 return QVariant( std::sqrt( x ) );
311 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
312 return QVariant( std::fabs( val ) );
317 double deg = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
318 return ( deg * M_PI ) / 180;
322 double rad = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
323 return ( 180 * rad ) / M_PI;
327 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
328 return QVariant( std::sin( x ) );
332 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
333 return QVariant( std::cos( x ) );
337 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
338 return QVariant( std::tan( x ) );
342 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
343 return QVariant( std::asin( x ) );
347 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
348 return QVariant( std::acos( x ) );
352 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
353 return QVariant( std::atan( x ) );
357 double y = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
358 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
359 return QVariant( std::atan2( y, x ) );
363 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
364 return QVariant( std::exp( x ) );
368 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
371 return QVariant( std::log( x ) );
375 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
378 return QVariant( log10( x ) );
382 double b = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
383 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
384 if ( x <= 0 || b <= 0 )
386 return QVariant( std::log( x ) / std::log( b ) );
390 double min = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
391 double max = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
395 std::random_device rd;
396 std::mt19937_64 generator( rd() );
398 if ( !QgsExpressionUtils::isNull( values.at( 2 ) ) )
401 if ( QgsExpressionUtils::isIntSafe( values.at( 2 ) ) )
404 seed = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
409 QString seedStr = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
410 std::hash<std::string> hasher;
411 seed = hasher( seedStr.toStdString() );
413 generator.seed( seed );
417 double f =
static_cast< double >( generator() ) /
static_cast< double >( generator.max() );
418 return QVariant( min + f * ( max - min ) );
422 qlonglong min = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
423 qlonglong max = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
427 std::random_device rd;
428 std::mt19937_64 generator( rd() );
430 if ( !QgsExpressionUtils::isNull( values.at( 2 ) ) )
433 if ( QgsExpressionUtils::isIntSafe( values.at( 2 ) ) )
436 seed = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
441 QString seedStr = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
442 std::hash<std::string> hasher;
443 seed = hasher( seedStr.toStdString() );
445 generator.seed( seed );
448 qint64 randomInteger = min + ( generator() % ( max - min + 1 ) );
449 if ( randomInteger > std::numeric_limits<int>::max() || randomInteger < -std::numeric_limits<int>::max() )
450 return QVariant( randomInteger );
453 return QVariant(
int( randomInteger ) );
458 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
459 double domainMin = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
460 double domainMax = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
461 double rangeMin = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
462 double rangeMax = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
464 if ( domainMin >= domainMax )
466 parent->
setEvalErrorString( QObject::tr(
"Domain max must be greater than domain min" ) );
471 if ( val >= domainMax )
475 else if ( val <= domainMin )
481 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
482 double c = rangeMin - ( domainMin * m );
485 return QVariant( m * val +
c );
490 double val = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
491 double domainMin = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
492 double domainMax = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
493 double rangeMin = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
494 double rangeMax = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
495 double exponent = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
497 if ( domainMin >= domainMax )
499 parent->
setEvalErrorString( QObject::tr(
"Domain max must be greater than domain min" ) );
509 if ( val >= domainMax )
513 else if ( val <= domainMin )
519 return QVariant( ( ( rangeMax - rangeMin ) / std::pow( domainMax - domainMin, exponent ) ) * std::pow( val - domainMin, exponent ) + rangeMin );
524 QVariant result( QVariant::Double );
525 double maxVal = std::numeric_limits<double>::quiet_NaN();
526 for (
const QVariant &val : values )
528 double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
529 if ( std::isnan( maxVal ) )
533 else if ( !std::isnan( testVal ) )
535 maxVal = std::max( maxVal, testVal );
539 if ( !std::isnan( maxVal ) )
541 result = QVariant( maxVal );
548 QVariant result( QVariant::Double );
549 double minVal = std::numeric_limits<double>::quiet_NaN();
550 for (
const QVariant &val : values )
552 double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
553 if ( std::isnan( minVal ) )
557 else if ( !std::isnan( testVal ) )
559 minVal = std::min( minVal, testVal );
563 if ( !std::isnan( minVal ) )
565 result = QVariant( minVal );
577 QVariant value = node->
eval( parent, context );
579 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( value, parent );
582 parent->
setEvalErrorString( QObject::tr(
"Cannot find layer with name or ID '%1'" ).arg( value.toString() ) );
587 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
589 value = node->
eval( parent, context );
595 parent->
setEvalErrorString( QObject::tr(
"No such aggregate '%1'" ).arg( value.toString() ) );
600 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
602 QString subExpression = node->
dump();
606 if ( values.count() > 3 )
608 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
611 if ( !nl || nl->value().isValid() )
616 if ( values.count() > 4 )
618 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
620 value = node->
eval( parent, context );
627 if ( values.count() > 5 )
629 node = QgsExpressionUtils::getNode( values.at( 5 ), parent );
632 if ( !nl || nl->value().isValid() )
634 orderBy = node->
dump();
646 bool isStatic =
true;
647 if ( filterExp.referencedVariables().contains( QStringLiteral(
"parent" ) )
648 || filterExp.referencedVariables().contains( QString() )
649 || subExp.referencedVariables().contains( QStringLiteral(
"parent" ) )
650 || subExp.referencedVariables().contains( QString() ) )
656 const QSet<QString> refVars = filterExp.referencedVariables() + subExp.referencedVariables();
657 for (
const QString &varName : refVars )
660 if ( scope && !scope->
isStatic( varName ) )
670 cacheKey = QStringLiteral(
"aggfcn:%1:%2:%3:%4:%5%6:%7" ).arg( vl->id(), QString::number( aggregate ), subExpression, parameters.
filter,
675 cacheKey = QStringLiteral(
"aggfcn:%1:%2:%3:%4:%5" ).arg( vl->id(), QString::number( aggregate ), subExpression, parameters.
filter, orderBy );
686 subContext.appendScope( subScope );
687 result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok );
693 result = vl->aggregate( aggregate, subExpression, parameters,
nullptr, &ok );
697 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
708 parent->
setEvalErrorString( QObject::tr(
"Cannot use relation aggregate function in this context" ) );
713 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
716 parent->
setEvalErrorString( QObject::tr(
"Cannot use relation aggregate function in this context" ) );
725 QVariant value = node->
eval( parent, context );
727 QString relationId = value.toString();
734 if ( relations.isEmpty() || relations.at( 0 ).referencedLayer() != vl )
736 parent->
setEvalErrorString( QObject::tr(
"Cannot find relation with id '%1'" ).arg( relationId ) );
741 relation = relations.at( 0 );
748 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
750 value = node->
eval( parent, context );
756 parent->
setEvalErrorString( QObject::tr(
"No such aggregate '%1'" ).arg( value.toString() ) );
761 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
763 QString subExpression = node->
dump();
767 if ( values.count() > 3 )
769 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
771 value = node->
eval( parent, context );
778 if ( values.count() > 4 )
780 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
783 if ( !nl || nl->value().isValid() )
785 orderBy = node->
dump();
796 QString cacheKey = QStringLiteral(
"relagg:%1:%2:%3:%4:%5" ).arg( vl->
id(),
797 QString::number(
static_cast< int >( aggregate ) ),
809 result = childLayer->
aggregate( aggregate, subExpression, parameters, &subContext, &ok );
813 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
827 parent->
setEvalErrorString( QObject::tr(
"Cannot use aggregate function in this context" ) );
832 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
835 parent->
setEvalErrorString( QObject::tr(
"Cannot use aggregate function in this context" ) );
844 QString subExpression = node->
dump();
848 if ( values.count() > 1 )
850 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
853 if ( !nl || nl->value().isValid() )
854 groupBy = node->
dump();
858 if ( values.count() > 2 )
860 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
863 if ( !nl || nl->value().isValid() )
869 if ( orderByPos >= 0 && values.count() > orderByPos )
871 node = QgsExpressionUtils::getNode( values.at( orderByPos ), parent );
874 if ( !nl || nl->value().isValid() )
876 orderBy = node->
dump();
884 if ( !groupBy.isEmpty() )
887 QVariant groupByValue = groupByExp.evaluate( context );
888 QString groupByClause = QStringLiteral(
"%1 %2 %3" ).arg( groupBy,
889 groupByValue.isNull() ? QStringLiteral(
"is" ) : QStringLiteral(
"=" ),
891 if ( !parameters.
filter.isEmpty() )
892 parameters.
filter = QStringLiteral(
"(%1) AND (%2)" ).arg( parameters.
filter, groupByClause );
894 parameters.
filter = groupByClause;
900 bool isStatic =
true;
901 const QSet<QString> refVars = filterExp.referencedVariables() + subExp.referencedVariables();
902 for (
const QString &varName : refVars )
905 if ( scope && !scope->
isStatic( varName ) )
915 cacheKey = QStringLiteral(
"agg:%1:%2:%3:%4:%5%6:%7" ).arg( vl->
id(), QString::number( aggregate ), subExpression, parameters.
filter,
920 cacheKey = QStringLiteral(
"agg:%1:%2:%3:%4:%5" ).arg( vl->
id(), QString::number( aggregate ), subExpression, parameters.
filter, orderBy );
932 subContext.appendScope( subScope );
933 result = vl->
aggregate( aggregate, subExpression, parameters, &subContext, &ok );
937 parent->
setEvalErrorString( QObject::tr(
"Could not calculate aggregate for: %1" ).arg( subExpression ) );
1042 if ( values.count() > 3 )
1044 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
1046 QVariant value = node->
eval( parent, context );
1048 parameters.
delimiter = value.toString();
1059 if ( values.count() > 3 )
1061 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
1063 QVariant value = node->
eval( parent, context );
1065 parameters.
delimiter = value.toString();
1081 QVariant scale = context->
variable( QStringLiteral(
"map_scale" ) );
1083 if ( !scale.isValid() || scale.isNull() )
1086 const double v = scale.toDouble( &ok );
1094 double minValue = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1095 double testValue = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
1096 double maxValue = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1099 if ( testValue <= minValue )
1101 return QVariant( minValue );
1103 else if ( testValue >= maxValue )
1105 return QVariant( maxValue );
1109 return QVariant( testValue );
1115 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1116 return QVariant( std::floor( x ) );
1121 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1122 return QVariant( std::ceil( x ) );
1127 return QVariant( QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) );
1131 return QVariant( QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent ) );
1135 return QVariant( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ) );
1140 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1141 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1142 if ( format.isEmpty() && !language.isEmpty() )
1144 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to DateTime when the language is specified" ) );
1145 return QVariant( QDateTime() );
1148 if ( format.isEmpty() && language.isEmpty() )
1149 return QVariant( QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent ) );
1151 QString datetimestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1152 QLocale locale = QLocale();
1153 if ( !language.isEmpty() )
1155 locale = QLocale( language );
1158 QDateTime datetime = locale.toDateTime( datetimestring, format );
1159 if ( !datetime.isValid() )
1161 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to DateTime" ).arg( datetimestring ) );
1162 datetime = QDateTime();
1164 return QVariant( datetime );
1169 const int year = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1170 const int month = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1171 const int day = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
1173 const QDate date( year, month, day );
1174 if ( !date.isValid() )
1176 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid date" ).arg( year ).arg( month ).arg( day ) );
1179 return QVariant( date );
1184 const int hours = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1185 const int minutes = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1186 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1188 const QTime time( hours, minutes, std::floor( seconds ), ( seconds - std::floor( seconds ) ) * 1000 );
1189 if ( !time.isValid() )
1191 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid time" ).arg( hours ).arg( minutes ).arg( seconds ) );
1194 return QVariant( time );
1199 const int year = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
1200 const int month = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1201 const int day = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
1202 const int hours = QgsExpressionUtils::getIntValue( values.at( 3 ), parent );
1203 const int minutes = QgsExpressionUtils::getIntValue( values.at( 4 ), parent );
1204 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
1206 const QDate date( year, month, day );
1207 if ( !date.isValid() )
1209 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid date" ).arg( year ).arg( month ).arg( day ) );
1212 const QTime time( hours, minutes, std::floor( seconds ), ( seconds - std::floor( seconds ) ) * 1000 );
1213 if ( !time.isValid() )
1215 parent->
setEvalErrorString( QObject::tr(
"'%1-%2-%3' is not a valid time" ).arg( hours ).arg( minutes ).arg( seconds ) );
1218 return QVariant( QDateTime( date, time ) );
1223 const double years = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
1224 const double months = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
1225 const double weeks = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
1226 const double days = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
1227 const double hours = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
1228 const double minutes = QgsExpressionUtils::getDoubleValue( values.at( 5 ), parent );
1229 const double seconds = QgsExpressionUtils::getDoubleValue( values.at( 6 ), parent );
1231 return QVariant::fromValue(
QgsInterval( years, months, weeks, days, hours, minutes, seconds ) );
1236 for (
const QVariant &value : values )
1238 if ( value.isNull() )
1247 const QVariant val1 = values.at( 0 );
1248 const QVariant val2 = values.at( 1 );
1258 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1259 return QVariant( str.toLower() );
1263 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1264 return QVariant( str.toUpper() );
1268 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1269 QStringList elems = str.split(
' ' );
1270 for (
int i = 0; i < elems.size(); i++ )
1272 if ( elems[i].size() > 1 )
1273 elems[i] = elems[i].at( 0 ).toUpper() + elems[i].mid( 1 ).toLower();
1275 return QVariant( elems.join( QLatin1Char(
' ' ) ) );
1280 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1281 return QVariant( str.trimmed() );
1286 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1287 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1293 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1294 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1300 QString string1 = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1301 QString string2 = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1308 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1314 QChar character = QChar( QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent ) );
1315 return QVariant( QString( character ) );
1320 QString value = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1322 if ( value.isEmpty() )
1327 int res = value.at( 0 ).unicode();
1328 return QVariant( res );
1333 if ( values.length() == 2 || values.length() == 3 )
1335 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1336 qlonglong wrap = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
1338 QString customdelimiter = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1352 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
1356 return QVariant( geom.
length() );
1360 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1361 return QVariant( str.length() );
1366 if ( values.count() == 2 && values.at( 1 ).type() == QVariant::Map )
1368 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1369 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 1 ), parent );
1371 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
1373 str = str.replace( it.key(), it.value().toString() );
1376 return QVariant( str );
1378 else if ( values.count() == 3 )
1380 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1381 QVariantList before;
1383 bool isSingleReplacement =
false;
1385 if ( values.at( 1 ).type() != QVariant::List && values.at( 2 ).type() != QVariant::StringList )
1387 before = QVariantList() << QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1391 before = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
1394 if ( values.at( 2 ).type() != QVariant::List && values.at( 2 ).type() != QVariant::StringList )
1396 after = QVariantList() << QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1397 isSingleReplacement =
true;
1401 after = QgsExpressionUtils::getListValue( values.at( 2 ), parent );
1404 if ( !isSingleReplacement && before.length() != after.length() )
1406 parent->
setEvalErrorString( QObject::tr(
"Invalid pair of array, length not identical" ) );
1410 for (
int i = 0; i < before.length(); i++ )
1412 str = str.replace( before.at( i ).toString(), after.at( isSingleReplacement ? 0 : i ).toString() );
1415 return QVariant( str );
1419 parent->
setEvalErrorString( QObject::tr(
"Function replace requires 2 or 3 arguments" ) );
1425 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1426 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1427 QString after = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1429 QRegularExpression re( regexp, QRegularExpression::UseUnicodePropertiesOption );
1430 if ( !re.isValid() )
1432 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1435 return QVariant( str.replace( re, after ) );
1440 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1441 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1443 QRegularExpression re( regexp, QRegularExpression::UseUnicodePropertiesOption );
1444 if ( !re.isValid() )
1446 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1449 return QVariant( ( str.indexOf( re ) + 1 ) );
1454 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1455 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1456 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
1458 QRegularExpression re( regexp, QRegularExpression::UseUnicodePropertiesOption );
1459 if ( !re.isValid() )
1461 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1465 QRegularExpressionMatch matches = re.match( str );
1466 if ( matches.hasMatch() )
1469 QStringList list = matches.capturedTexts();
1472 for ( QStringList::const_iterator it = ++list.constBegin(); it != list.constEnd(); ++it )
1474 array += ( !( *it ).isEmpty() ) ? *it : empty;
1477 return QVariant( array );
1487 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1488 QString regexp = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1490 QRegularExpression re( regexp, QRegularExpression::UseUnicodePropertiesOption );
1491 if ( !re.isValid() )
1493 parent->
setEvalErrorString( QObject::tr(
"Invalid regular expression '%1': %2" ).arg( regexp, re.errorString() ) );
1498 QRegularExpressionMatch match = re.match( str );
1499 if ( match.hasMatch() )
1502 if ( match.lastCapturedIndex() > 0 )
1505 return QVariant( match.captured( 1 ) );
1510 return QVariant( match.captured( 0 ) );
1515 return QVariant(
"" );
1521 QString uuid = QUuid::createUuid().toString();
1522 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1523 if ( values.at( 0 ).toString().compare( QStringLiteral(
"WithoutBraces" ), Qt::CaseInsensitive ) == 0 )
1524 uuid.remove( QRegExp(
"[{}]" ) );
1525 else if ( values.at( 0 ).toString().compare( QStringLiteral(
"Id128" ), Qt::CaseInsensitive ) == 0 )
1526 uuid.remove( QRegExp(
"[{}-]" ) );
1528 if ( values.at( 0 ).toString().compare( QStringLiteral(
"WithoutBraces" ), Qt::CaseInsensitive ) == 0 )
1529 uuid = QUuid::createUuid().toString( QUuid::StringFormat::WithoutBraces );
1530 else if ( values.at( 0 ).toString().compare( QStringLiteral(
"Id128" ), Qt::CaseInsensitive ) == 0 )
1531 uuid = QUuid::createUuid().toString( QUuid::StringFormat::Id128 );
1538 if ( !values.at( 0 ).isValid() || !values.at( 1 ).isValid() )
1541 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1542 int from = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1545 if ( values.at( 2 ).isValid() )
1546 len = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
1552 from = str.size() + from;
1558 else if ( from > 0 )
1566 len = str.size() + len - from;
1573 return QVariant( str.mid( from, len ) );
1579 return QVariant(
static_cast< int >( f.
id() ) );
1584 QgsRasterLayer *layer = QgsExpressionUtils::getRasterLayer( values.at( 0 ), parent );
1587 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid raster layer." ) );
1591 int bandNb = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
1592 if ( bandNb < 1 || bandNb > layer->
bandCount() )
1594 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid raster band number." ) );
1598 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 2 ), parent );
1601 parent->
setEvalErrorString( QObject::tr(
"Function `raster_value` requires a valid point geometry." ) );
1609 if ( multiPoint.count() == 1 )
1611 point = multiPoint[0];
1621 return std::isnan( value ) ? QVariant() : value;
1636 if ( values.size() == 1 )
1638 attr = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1641 else if ( values.size() == 2 )
1643 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1644 attr = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
1648 parent->
setEvalErrorString( QObject::tr(
"Function `attribute` requires one or two parameters. %1 given." ).arg( values.length() ) );
1658 if ( values.size() == 0 || values.at( 0 ).isNull() )
1664 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1669 for (
int i = 0; i < fields.
count(); ++i )
1680 bool evaluate =
true;
1682 if ( values.isEmpty() )
1685 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1687 else if ( values.size() == 1 )
1689 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1690 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1692 else if ( values.size() == 2 )
1694 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1695 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1697 else if ( values.size() == 3 )
1699 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1700 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1701 evaluate = values.value( 2 ).toBool();
1707 parent->
setEvalErrorString( QObject::tr(
"Function `maptip` requires no more than three parameters. %1 given." ).arg( values.length() ) );
1711 parent->
setEvalErrorString( QObject::tr(
"Function `display` requires no more than three parameters. %1 given." ).arg( values.length() ) );
1742 subContext.setFeature( feature );
1751 exp.prepare( &subContext );
1752 return exp.evaluate( &subContext ).toString();
1758 return fcnCoreFeatureMaptipDisplay( values, context, parent,
false );
1763 return fcnCoreFeatureMaptipDisplay( values, context, parent,
true );
1771 if ( values.isEmpty() )
1774 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1776 else if ( values.size() == 1 )
1778 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1779 feature = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
1781 else if ( values.size() == 2 )
1783 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1784 feature = QgsExpressionUtils::getFeature( values.at( 1 ), parent );
1788 parent->
setEvalErrorString( QObject::tr(
"Function `is_selected` requires no more than two parameters. %1 given." ).arg( values.length() ) );
1792 if ( !layer || !feature.
isValid() )
1794 return QVariant( QVariant::Bool );
1804 if ( values.isEmpty() )
1805 layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
1806 else if ( values.count() == 1 )
1807 layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1810 parent->
setEvalErrorString( QObject::tr(
"Function `num_selected` requires no more than one parameter. %1 given." ).arg( values.length() ) );
1816 return QVariant( QVariant::LongLong );
1824 static QMap<QString, qlonglong> counterCache;
1825 QVariant functionResult;
1827 std::function<void()> fetchAndIncrementFunc = [ =, &functionResult ]()
1830 const QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
1835 database = decodedUri.value( QStringLiteral(
"path" ) ).toString();
1836 if ( database.isEmpty() )
1838 parent->
setEvalErrorString( QObject::tr(
"Could not extract file path from layer `%1`." ).arg( layer->
name() ) );
1843 database = values.at( 0 ).toString();
1846 const QString table = values.at( 1 ).toString();
1847 const QString idColumn = values.at( 2 ).toString();
1848 const QString filterAttribute = values.at( 3 ).toString();
1849 const QVariant filterValue = values.at( 4 ).toString();
1850 const QVariantMap defaultValues = values.at( 5 ).toMap();
1856 if ( sqliteDb.
open_v2( database, SQLITE_OPEN_READWRITE,
nullptr ) != SQLITE_OK )
1859 functionResult = QVariant();
1863 QString errorMessage;
1864 QString currentValSql;
1866 qlonglong nextId = 0;
1867 bool cachedMode =
false;
1868 bool valueRetrieved =
false;
1870 QString cacheString = QStringLiteral(
"%1:%2:%3:%4:%5" ).arg( database, table, idColumn, filterAttribute, filterValue.toString() );
1877 auto cachedCounter = counterCache.find( cacheString );
1879 if ( cachedCounter != counterCache.end() )
1881 qlonglong &cachedValue = cachedCounter.value();
1882 nextId = cachedValue;
1884 cachedValue = nextId;
1885 valueRetrieved =
true;
1890 if ( !cachedMode || !valueRetrieved )
1892 int result = SQLITE_ERROR;
1895 if ( !filterAttribute.isNull() )
1900 sqliteStatement = sqliteDb.
prepare( currentValSql, result );
1902 if ( result == SQLITE_OK )
1905 if ( sqliteStatement.
step() == SQLITE_ROW )
1911 if ( cachedMode && result == SQLITE_OK )
1913 counterCache.insert( cacheString, nextId );
1917 counterCache.remove( cacheString );
1920 valueRetrieved =
true;
1924 if ( valueRetrieved )
1933 if ( !filterAttribute.isNull() )
1939 for ( QVariantMap::const_iterator iter = defaultValues.constBegin(); iter != defaultValues.constEnd(); ++iter )
1942 vals << iter.value().toString();
1945 upsertSql += QLatin1String(
" (" ) + cols.join(
',' ) +
')';
1946 upsertSql += QLatin1String(
" VALUES " );
1947 upsertSql +=
'(' + vals.join(
',' ) +
')';
1949 int result = SQLITE_ERROR;
1953 if ( transaction->
executeSql( upsertSql, errorMessage ) )
1960 result = sqliteDb.
exec( upsertSql, errorMessage );
1962 if ( result == SQLITE_OK )
1964 functionResult = QVariant( nextId );
1969 parent->
setEvalErrorString( QStringLiteral(
"Could not increment value: SQLite error: \"%1\" (%2)." ).arg( errorMessage, QString::number( result ) ) );
1970 functionResult = QVariant();
1975 functionResult = QVariant();
1980 return functionResult;
1986 for (
const QVariant &value : values )
1988 if ( !value.isNull() )
1989 concat += QgsExpressionUtils::getStringValue( value, parent );
1996 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
1997 return string.indexOf( QgsExpressionUtils::getStringValue( values.at( 1 ), parent ) ) + 1;
2002 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2003 int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2004 return string.right( pos );
2009 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2010 int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2011 return string.left( pos );
2016 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2017 int length = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2018 QString fill = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2019 return string.leftJustified( length, fill.at( 0 ),
true );
2024 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2025 int length = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2026 QString fill = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2027 return string.rightJustified( length, fill.at( 0 ),
true );
2032 if ( values.size() < 1 )
2034 parent->
setEvalErrorString( QObject::tr(
"Function format requires at least 1 argument" ) );
2038 QString
string = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2039 for (
int n = 1; n < values.length(); n++ )
2041 string =
string.arg( QgsExpressionUtils::getStringValue( values.at( n ), parent ) );
2049 return QVariant( QDateTime::currentDateTime() );
2054 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2055 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2056 if ( format.isEmpty() && !language.isEmpty() )
2058 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to Date when the language is specified" ) );
2059 return QVariant( QDate() );
2062 if ( format.isEmpty() && language.isEmpty() )
2063 return QVariant( QgsExpressionUtils::getDateValue( values.at( 0 ), parent ) );
2065 QString datestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2066 QLocale locale = QLocale();
2067 if ( !language.isEmpty() )
2069 locale = QLocale( language );
2072 QDate date = locale.toDate( datestring, format );
2073 if ( !date.isValid() )
2075 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to Date" ).arg( datestring ) );
2078 return QVariant( date );
2083 QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2084 QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2085 if ( format.isEmpty() && !language.isEmpty() )
2087 parent->
setEvalErrorString( QObject::tr(
"A format is required to convert to Time when the language is specified" ) );
2088 return QVariant( QTime() );
2091 if ( format.isEmpty() && language.isEmpty() )
2092 return QVariant( QgsExpressionUtils::getTimeValue( values.at( 0 ), parent ) );
2094 QString timestring = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
2095 QLocale locale = QLocale();
2096 if ( !language.isEmpty() )
2098 locale = QLocale( language );
2101 QTime time = locale.toTime( timestring, format );
2102 if ( !time.isValid() )
2104 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to Time" ).arg( timestring ) );
2107 return QVariant( time );
2112 return QVariant::fromValue( QgsExpressionUtils::getInterval( values.at( 0 ), parent ) );
2121 double value = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2122 QString axis = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
2123 int precision = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
2125 QString formatString;
2126 if ( values.count() > 3 )
2127 formatString = QgsExpressionUtils::getStringValue( values.at( 3 ), parent );
2129 QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FormatFlags();
2130 if ( formatString.compare( QLatin1String(
"suffix" ), Qt::CaseInsensitive ) == 0 )
2134 else if ( formatString.compare( QLatin1String(
"aligned" ), Qt::CaseInsensitive ) == 0 )
2138 else if ( ! formatString.isEmpty() )
2140 parent->
setEvalErrorString( QObject::tr(
"Invalid formatting parameter: '%1'. It must be empty, or 'suffix' or 'aligned'." ).arg( formatString ) );
2144 if ( axis.compare( QLatin1String(
"x" ), Qt::CaseInsensitive ) == 0 )
2148 else if ( axis.compare( QLatin1String(
"y" ), Qt::CaseInsensitive ) == 0 )
2154 parent->
setEvalErrorString( QObject::tr(
"Invalid axis name: '%1'. It must be either 'x' or 'y'." ).arg( axis ) );
2162 return floatToDegreeFormat( format, values, context, parent, node );
2169 value = QgsCoordinateUtils::dmsToDecimal( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), &ok );
2171 return ok ? QVariant( value ) : QVariant();
2177 return floatToDegreeFormat( format, values, context, parent, node );
2182 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
2183 QDateTime d2 = QgsExpressionUtils::getDateTimeValue( values.at( 1 ), parent );
2184 qint64 seconds = d2.secsTo( d1 );
2185 return QVariant::fromValue(
QgsInterval( seconds ) );
2190 if ( !values.at( 0 ).canConvert<QDate>() )
2193 QDate date = QgsExpressionUtils::getDateValue( values.at( 0 ), parent );
2194 if ( !date.isValid() )
2199 return date.dayOfWeek() % 7;
2204 QVariant value = values.at( 0 );
2205 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2208 return QVariant( inter.
days() );
2212 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2213 return QVariant( d1.date().day() );
2219 QVariant value = values.at( 0 );
2220 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2223 return QVariant( inter.
years() );
2227 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2228 return QVariant( d1.date().year() );
2234 QVariant value = values.at( 0 );
2235 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2238 return QVariant( inter.
months() );
2242 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2243 return QVariant( d1.date().month() );
2249 QVariant value = values.at( 0 );
2250 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2253 return QVariant( inter.
weeks() );
2257 QDateTime d1 = QgsExpressionUtils::getDateTimeValue( value, parent );
2258 return QVariant( d1.date().weekNumber() );
2264 QVariant value = values.at( 0 );
2265 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2268 return QVariant( inter.
hours() );
2272 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2273 return QVariant( t1.hour() );
2279 QVariant value = values.at( 0 );
2280 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2283 return QVariant( inter.
minutes() );
2287 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2288 return QVariant( t1.minute() );
2294 QVariant value = values.at( 0 );
2295 QgsInterval inter = QgsExpressionUtils::getInterval( value, parent,
false );
2298 return QVariant( inter.
seconds() );
2302 QTime t1 = QgsExpressionUtils::getTimeValue( value, parent );
2303 return QVariant( t1.second() );
2309 QDateTime dt = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
2312 return QVariant( dt.toMSecsSinceEpoch() );
2322 long long millisecs_since_epoch = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
2324 return QVariant( QDateTime::fromMSecsSinceEpoch( millisecs_since_epoch ) );
2327 #define ENSURE_GEOM_TYPE(f, g, geomtype) \
2328 if ( !(f).hasGeometry() ) \
2329 return QVariant(); \
2330 QgsGeometry g = (f).geometry(); \
2331 if ( (g).type() != (geomtype) ) \
2338 if ( g.isMultipart() )
2340 return g.asMultiPoint().at( 0 ).x();
2344 return g.asPoint().x();
2352 if ( g.isMultipart() )
2354 return g.asMultiPoint().at( 0 ).y();
2358 return g.asPoint().y();
2364 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2370 return QVariant( isValid );
2375 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2387 QVariant result( centroid.
asPoint().
x() );
2393 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2405 QVariant result( centroid.
asPoint().
y() );
2411 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2421 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2429 if ( collection->numGeometries() == 1 )
2431 if (
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN( 0 ) ) )
2442 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2452 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2460 if ( collection->numGeometries() == 1 )
2462 if (
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( collection->geometryN( 0 ) ) )
2473 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2478 int idx = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
2505 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2522 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2539 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2544 bool ignoreClosing =
false;
2545 if ( values.length() > 1 )
2547 ignoreClosing = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
2557 bool skipLast =
false;
2558 if ( ignoreClosing && ring.count() > 2 && ring.first() == ring.last() )
2563 for (
int i = 0; i < ( skipLast ? ring.count() - 1 : ring.count() ); ++ i )
2575 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2586 for (
int i = 0; i < line->numPoints() - 1; ++i )
2590 << line->pointN( i )
2591 << line->pointN( i + 1 ) );
2602 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2612 if ( collection->numGeometries() == 1 )
2614 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->geometryN( 0 ) );
2619 if ( !curvePolygon )
2623 qlonglong idx = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) - 1;
2629 QVariant result = curve ? QVariant::fromValue(
QgsGeometry( curve ) ) : QVariant();
2635 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2645 qlonglong idx = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) - 1;
2651 QVariant result = part ? QVariant::fromValue(
QgsGeometry( part ) ) : QVariant();
2657 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2666 return QVariant::fromValue(
QgsGeometry( boundary ) );
2671 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2680 return QVariant::fromValue( merged );
2685 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2690 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2693 if ( simplified.
isNull() )
2701 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2706 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2711 if ( simplified.
isNull() )
2719 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2724 int iterations = std::min( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ), 10 );
2725 double offset = qBound( 0.0, QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent ), 0.5 );
2726 double minLength = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
2727 double maxAngle = qBound( 0.0, QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent ), 180.0 );
2729 QgsGeometry smoothed = geom.
smooth(
static_cast<unsigned int>( iterations ), offset, minLength, maxAngle );
2739 if ( values.size() == 1 && ( values.at( 0 ).type() == QVariant::List || values.at( 0 ).type() == QVariant::StringList ) )
2741 list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
2748 QVector< QgsGeometry > parts;
2749 parts.reserve( list.size() );
2750 for (
const QVariant &value : qgis::as_const( list ) )
2768 if ( values.count() < 2 || values.count() > 4 )
2770 parent->
setEvalErrorString( QObject::tr(
"Function make_point requires 2-4 arguments" ) );
2774 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2775 double y = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2776 double z = values.count() >= 3 ? QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent ) : 0.0;
2777 double m = values.count() >= 4 ? QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent ) : 0.0;
2778 switch ( values.count() )
2792 double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
2793 double y = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2794 double m = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
2800 if ( values.empty() )
2805 QVector<QgsPoint> points;
2806 points.reserve( values.count() );
2808 auto addPoint = [&points](
const QgsGeometry & geom )
2816 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2823 for (
const QVariant &value : values )
2825 if ( value.type() == QVariant::List )
2827 const QVariantList list = value.toList();
2828 for (
const QVariant &v : list )
2830 addPoint( QgsExpressionUtils::getGeometry( v, parent ) );
2835 addPoint( QgsExpressionUtils::getGeometry( value, parent ) );
2839 if ( points.count() < 2 )
2847 if ( values.count() < 1 )
2849 parent->
setEvalErrorString( QObject::tr(
"Function make_polygon requires an argument" ) );
2853 QgsGeometry outerRing = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2857 std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
2859 const QgsCurve *exteriorRing = qgsgeometry_cast< QgsCurve * >( outerRing.
constGet() );
2866 exteriorRing = qgsgeometry_cast< QgsCurve * >( collection->
geometryN( 0 ) );
2871 if ( !exteriorRing )
2874 polygon->setExteriorRing( exteriorRing->
segmentize() );
2877 for (
int i = 1; i < values.count(); ++i )
2879 QgsGeometry ringGeom = QgsExpressionUtils::getGeometry( values.at( i ), parent );
2886 const QgsCurve *ring = qgsgeometry_cast< QgsCurve * >( ringGeom.
constGet() );
2893 ring = qgsgeometry_cast< QgsCurve * >( collection->
geometryN( 0 ) );
2901 polygon->addInteriorRing( ring->
segmentize() );
2904 return QVariant::fromValue(
QgsGeometry( std::move( polygon ) ) );
2909 std::unique_ptr<QgsTriangle> tr(
new QgsTriangle() );
2910 std::unique_ptr<QgsLineString> lineString(
new QgsLineString() );
2911 lineString->clear();
2913 for (
const QVariant &value : values )
2915 QgsGeometry geom = QgsExpressionUtils::getGeometry( value, parent );
2922 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2929 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
2937 lineString->addVertex( *point );
2940 tr->setExteriorRing( lineString.release() );
2942 return QVariant::fromValue(
QgsGeometry( tr.release() ) );
2947 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2954 double radius = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2955 int segment = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
2962 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
2969 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
2977 return QVariant::fromValue(
QgsGeometry( circ.toPolygon(
static_cast<unsigned int>( segment ) ) ) );
2982 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
2989 double majorAxis = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
2990 double minorAxis = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
2991 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
2992 int segment = QgsExpressionUtils::getNativeIntValue( values.at( 4 ), parent );
2998 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( geom.
constGet() );
3005 point = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3012 QgsEllipse elp( *point, majorAxis, minorAxis, azimuth );
3013 return QVariant::fromValue(
QgsGeometry( elp.toPolygon(
static_cast<unsigned int>( segment ) ) ) );
3019 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3026 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3033 unsigned int nbEdges =
static_cast<unsigned int>( QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) );
3036 parent->
setEvalErrorString( QObject::tr(
"Number of edges/sides must be greater than 2" ) );
3043 parent->
setEvalErrorString( QObject::tr(
"Option can be 0 (inscribed) or 1 (circumscribed)" ) );
3047 const QgsPoint *center = qgsgeometry_cast< const QgsPoint * >( pt1.
constGet() );
3054 center = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3061 const QgsPoint *corner = qgsgeometry_cast< const QgsPoint * >( pt2.
constGet() );
3068 corner = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3083 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3089 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3095 const QgsPoint *point1 = qgsgeometry_cast< const QgsPoint *>( pt1.
constGet() );
3096 const QgsPoint *point2 = qgsgeometry_cast< const QgsPoint *>( pt2.
constGet() );
3104 QgsGeometry pt1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3110 QgsGeometry pt2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3116 QgsGeometry pt3 = QgsExpressionUtils::getGeometry( values.at( 2 ), parent );
3125 parent->
setEvalErrorString( QObject::tr(
"Option can be 0 (distance) or 1 (projected)" ) );
3128 const QgsPoint *point1 = qgsgeometry_cast< const QgsPoint *>( pt1.
constGet() );
3129 const QgsPoint *point2 = qgsgeometry_cast< const QgsPoint *>( pt2.
constGet() );
3130 const QgsPoint *point3 = qgsgeometry_cast< const QgsPoint *>( pt3.
constGet() );
3138 int idx = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
3154 return QVariant( QPointF( p.
x(), p.
y() ) );
3159 QVariant v = pointAt( values, f, parent );
3160 if ( v.type() == QVariant::PointF )
3161 return QVariant( v.toPointF().x() );
3167 QVariant v = pointAt( values, f, parent );
3168 if ( v.type() == QVariant::PointF )
3169 return QVariant( v.toPointF().y() );
3178 return QVariant::fromValue( geom );
3185 QString wkt = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
3187 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3193 const QByteArray wkb = QgsExpressionUtils::getBinaryValue( values.at( 0 ), parent );
3199 return !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3204 QString gml = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
3211 ogcContext.
layer = mapLayerPtr.data();
3212 ogcContext.
transformContext = context->
variable( QStringLiteral(
"_project_transform_context" ) ).value<QgsCoordinateTransformContext>();
3216 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3229 return QVariant( area );
3233 return QVariant( f.geometry().area() );
3239 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3244 return QVariant( geom.
area() );
3256 return QVariant( len );
3260 return QVariant( f.geometry().length() );
3273 return QVariant( len );
3277 return f.geometry().isNull() ? QVariant( 0 ) : QVariant( f.geometry().constGet()->perimeter() );
3283 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3289 return QVariant( geom.
length() );
3294 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3300 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3309 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3318 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3333 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon *>( collection->
geometryN( i ) );
3334 if ( !curvePolygon )
3346 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3353 return QVariant( curvePolygon->
ringCount() );
3355 bool foundPoly =
false;
3363 curvePolygon = qgsgeometry_cast< QgsCurvePolygon *>( collection->
geometryN( i ) );
3364 if ( !curvePolygon )
3375 return QVariant( ringCount );
3380 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3382 QVariant result = !geomBounds.
isNull() ? QVariant::fromValue( geomBounds ) : QVariant();
3388 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3394 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3400 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3406 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3412 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3418 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3424 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3432 double max = std::numeric_limits< double >::lowest();
3436 double z = ( *it ).z();
3442 if ( max == std::numeric_limits< double >::lowest() )
3443 return QVariant( QVariant::Double );
3445 return QVariant( max );
3450 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3458 double min = std::numeric_limits< double >::max();
3462 double z = ( *it ).z();
3468 if ( min == std::numeric_limits< double >::max() )
3469 return QVariant( QVariant::Double );
3471 return QVariant( min );
3476 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3484 double min = std::numeric_limits< double >::max();
3488 double m = ( *it ).m();
3494 if ( min == std::numeric_limits< double >::max() )
3495 return QVariant( QVariant::Double );
3497 return QVariant( min );
3502 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3510 double max = std::numeric_limits< double >::lowest();
3514 double m = ( *it ).m();
3520 if ( max == std::numeric_limits< double >::lowest() )
3521 return QVariant( QVariant::Double );
3523 return QVariant( max );
3528 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3532 std::unique_ptr< QgsAbstractGeometry > flipped( geom.
constGet()->
clone() );
3534 return QVariant::fromValue(
QgsGeometry( std::move( flipped ) ) );
3539 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3543 const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( fGeom.
constGet() );
3550 curve = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( 0 ) );
3558 return QVariant::fromValue( curve->
isClosed() );
3563 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3576 std::unique_ptr< QgsLineString > closedLine( line->
clone() );
3577 closedLine->close();
3579 result = QVariant::fromValue(
QgsGeometry( std::move( closedLine ) ) );
3589 if (
const QgsLineString *line = qgsgeometry_cast<const QgsLineString * >( collection->
geometryN( i ) ) )
3591 std::unique_ptr< QgsLineString > closedLine( line->
clone() );
3592 closedLine->close();
3594 closed->addGeometry( closedLine.release() );
3597 result = QVariant::fromValue(
QgsGeometry( std::move( closed ) ) );
3605 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3609 return QVariant::fromValue( fGeom.
isEmpty() );
3614 if ( values.at( 0 ).isNull() )
3615 return QVariant::fromValue(
true );
3617 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3618 return QVariant::fromValue( fGeom.
isNull() || fGeom.
isEmpty() );
3623 if ( values.length() < 2 || values.length() > 3 )
3626 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3627 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3634 if ( values.length() == 2 )
3637 QString result = engine->relate( sGeom.
constGet() );
3638 return QVariant::fromValue( result );
3643 QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
3644 bool result = engine->relatePattern( sGeom.
constGet(), pattern );
3645 return QVariant::fromValue( result );
3651 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3652 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3657 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3658 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3659 return fGeom.
disjoint( sGeom ) ? TVL_True : TVL_False;
3663 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3664 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3665 return fGeom.
intersects( sGeom ) ? TVL_True : TVL_False;
3669 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3670 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3671 return fGeom.
touches( sGeom ) ? TVL_True : TVL_False;
3675 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3676 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3677 return fGeom.
crosses( sGeom ) ? TVL_True : TVL_False;
3681 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3682 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3683 return fGeom.
contains( sGeom ) ? TVL_True : TVL_False;
3687 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3688 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3689 return fGeom.
overlaps( sGeom ) ? TVL_True : TVL_False;
3693 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3694 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3695 return fGeom.
within( sGeom ) ? TVL_True : TVL_False;
3699 if ( values.length() < 2 || values.length() > 3 )
3702 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3703 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3705 if ( values.length() == 3 )
3706 seg = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3709 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3715 const QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3717 return !reoriented.
isNull() ? QVariant::fromValue( reoriented ) : QVariant();
3722 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3723 const QgsPoint *pt = qgsgeometry_cast<const QgsPoint *>( fGeom.
constGet() );
3730 pt = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
3737 parent->
setEvalErrorString( QObject::tr(
"Function `wedge_buffer` requires a point value for the center." ) );
3741 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3742 double width = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3743 double outerRadius = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3744 double innerRadius = QgsExpressionUtils::getDoubleValue( values.at( 4 ), parent );
3747 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3753 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3756 parent->
setEvalErrorString( QObject::tr(
"Function `tapered_buffer` requires a line geometry." ) );
3760 double startWidth = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3761 double endWidth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3762 int segments =
static_cast< int >( QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) );
3765 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3771 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3774 parent->
setEvalErrorString( QObject::tr(
"Function `buffer_by_m` requires a line geometry." ) );
3778 int segments =
static_cast< int >( QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) );
3781 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3787 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3788 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3789 int segments = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3793 double miterLimit = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3796 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3802 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3803 double dist = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3804 int segments = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
3808 double miterLimit = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
3811 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3817 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3818 double distStart = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3819 double distEnd = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3822 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3828 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3829 double dx = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3830 double dy = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
3832 return QVariant::fromValue( fGeom );
3837 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3838 const double rotation = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3839 const QgsGeometry center = values.at( 2 ).
isValid() ? QgsExpressionUtils::getGeometry( values.at( 2 ), parent )
3850 parent->
setEvalErrorString( QObject::tr(
"Function 'rotate' requires a point value for the center" ) );
3856 if ( multiPoint.count() == 1 )
3862 parent->
setEvalErrorString( QObject::tr(
"Function 'rotate' requires a point value for the center" ) );
3871 fGeom.
rotate( rotation, pt );
3872 return QVariant::fromValue( fGeom );
3877 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3879 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3884 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3886 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3892 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3893 double tolerance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
3895 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3901 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3903 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3910 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3912 if ( values.length() == 2 )
3913 segments = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
3921 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3927 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3929 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3935 const QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3941 double area,
angle, width, height;
3954 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3955 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
3957 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
3963 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
3970 const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( fGeom.
constGet() );
3975 result = reversed ? QVariant::fromValue(
QgsGeometry( reversed ) ) : QVariant();
3983 if (
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( collection->
geometryN( i ) ) )
3985 reversed->addGeometry( curve->
reversed() );
3992 result = reversed ? QVariant::fromValue(
QgsGeometry( std::move( reversed ) ) ) : QVariant();
3999 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4010 curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( collection->
geometryN( 0 ) );
4019 QVariant result = exterior ? QVariant::fromValue(
QgsGeometry( exterior ) ) : QVariant();
4025 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4026 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4027 return QVariant( fGeom.
distance( sGeom ) );
4032 QgsGeometry g1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4033 QgsGeometry g2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4036 if ( values.length() == 3 && values.at( 2 ).isValid() )
4038 double densify = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4039 densify = qBound( 0.0, densify, 1.0 );
4047 return res > -1 ? QVariant( res ) : QVariant();
4052 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4053 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4055 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4060 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4061 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4063 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4068 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4069 QgsGeometry sGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4071 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4077 if ( values.length() < 1 || values.length() > 2 )
4080 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4082 if ( values.length() == 2 )
4083 prec = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4084 QString wkt = fGeom.
asWkt( prec );
4085 return QVariant( wkt );
4090 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4091 return fGeom.
isNull() ? QVariant() : QVariant( fGeom.asWkb() );
4096 if ( values.length() != 2 )
4098 parent->
setEvalErrorString( QObject::tr(
"Function `azimuth` requires exactly two parameters. %1 given." ).arg( values.length() ) );
4102 QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4103 QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4105 const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.
constGet() );
4112 pt1 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4117 const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.
constGet() );
4124 pt2 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4131 parent->
setEvalErrorString( QObject::tr(
"Function `azimuth` requires two points as arguments." ) );
4138 if ( pt1->
y() < pt2->
y() )
4140 else if ( pt1->
y() > pt2->
y() )
4148 if ( pt1->
x() < pt2->
x() )
4150 else if ( pt1->
x() > pt2->
x() )
4151 return M_PI + ( M_PI_2 );
4156 if ( pt1->
x() < pt2->
x() )
4158 if ( pt1->
y() < pt2->
y() )
4160 return std::atan( std::fabs( pt1->
x() - pt2->
x() ) / std::fabs( pt1->
y() - pt2->
y() ) );
4164 return std::atan( std::fabs( pt1->
y() - pt2->
y() ) / std::fabs( pt1->
x() - pt2->
x() ) )
4171 if ( pt1->
y() > pt2->
y() )
4173 return std::atan( std::fabs( pt1->
x() - pt2->
x() ) / std::fabs( pt1->
y() - pt2->
y() ) )
4178 return std::atan( std::fabs( pt1->
y() - pt2->
y() ) / std::fabs( pt1->
x() - pt2->
x() ) )
4179 + ( M_PI + ( M_PI_2 ) );
4186 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4190 parent->
setEvalErrorString( QStringLiteral(
"'project' requires a point geometry" ) );
4194 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4195 double azimuth = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4196 double inclination = QgsExpressionUtils::getDoubleValue( values.at( 3 ), parent );
4199 QgsPoint newPoint = p->
project( distance, 180.0 * azimuth / M_PI, 180.0 * inclination / M_PI );
4206 QgsGeometry fGeom1 = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4207 QgsGeometry fGeom2 = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4209 const QgsPoint *pt1 = qgsgeometry_cast<const QgsPoint *>( fGeom1.
constGet() );
4216 pt1 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4220 const QgsPoint *pt2 = qgsgeometry_cast<const QgsPoint *>( fGeom2.
constGet() );
4227 pt2 = qgsgeometry_cast< const QgsPoint * >( collection->
geometryN( 0 ) );
4235 parent->
setEvalErrorString( QStringLiteral(
"Function 'inclination' requires two points as arguments." ) );
4245 if ( values.length() != 3 )
4248 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4249 double x = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4250 double y = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4254 QVariant result = geom.
constGet() ? QVariant::fromValue( geom ) : QVariant();
4260 if ( values.length() < 2 )
4263 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4266 return values.at( 0 );
4268 QString expString = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4269 QVariant cachedExpression;
4274 if ( cachedExpression.isValid() )
4281 bool asc = values.value( 2 ).toBool();
4299 Q_ASSERT( collection );
4303 QgsExpressionSorter sorter( orderBy );
4305 QList<QgsFeature> partFeatures;
4306 partFeatures.reserve( collection->
partCount() );
4307 for (
int i = 0; i < collection->
partCount(); ++i )
4313 sorter.sortFeatures( partFeatures, unconstedContext );
4317 Q_ASSERT( orderedGeom );
4322 for (
const QgsFeature &feature : qgis::as_const( partFeatures ) )
4327 QVariant result = QVariant::fromValue(
QgsGeometry( orderedGeom ) );
4330 delete unconstedContext;
4337 QgsGeometry fromGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4338 QgsGeometry toGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4342 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4348 QgsGeometry fromGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4349 QgsGeometry toGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4353 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4359 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4360 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4364 QVariant result = !geom.
isNull() ? QVariant::fromValue( geom ) : QVariant();
4370 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4373 parent->
setEvalErrorString( QObject::tr(
"line_substring requires a curve geometry input" ) );
4379 curve = qgsgeometry_cast< const QgsCurve * >( lineGeom.
constGet() );
4386 curve = qgsgeometry_cast< const QgsCurve * >( collection->
geometryN( 0 ) );
4393 double startDistance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4394 double endDistance = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4396 std::unique_ptr< QgsCurve > substring( curve->
curveSubstring( startDistance, endDistance ) );
4398 return !result.isNull() ? QVariant::fromValue( result ) : QVariant();
4403 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4404 double distance = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4411 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4412 int vertex = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4417 vertex = count + vertex;
4425 QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4426 int vertex = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4431 vertex = count + vertex;
4439 QgsGeometry lineGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4440 QgsGeometry pointGeom = QgsExpressionUtils::getGeometry( values.at( 1 ), parent );
4444 return distance >= 0 ? distance : QVariant();
4449 if ( values.length() == 2 && values.at( 1 ).toInt() != 0 )
4451 double number = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
4452 return qgsRound( number, QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4455 if ( values.length() >= 1 )
4457 double number = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
4458 return QVariant( qlonglong( std::round( number ) ) );
4473 const double value = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
4474 const int places = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4475 const QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4482 QLocale locale = !language.isEmpty() ? QLocale( language ) : QLocale();
4483 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
4484 return locale.toString( value,
'f', places );
4489 const QDateTime datetime = QgsExpressionUtils::getDateTimeValue( values.at( 0 ), parent );
4490 const QString format = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4491 const QString language = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4493 QLocale locale = !language.isEmpty() ? QLocale( language ) : QLocale();
4494 return locale.toString( datetime, format );
4500 int avg = ( color.red() + color.green() + color.blue() ) / 3;
4501 int alpha = color.alpha();
4503 color.setRgb( avg, avg, avg, alpha );
4512 double ratio = QgsExpressionUtils::getDoubleValue( values.at( 2 ), parent );
4517 else if ( ratio < 0 )
4522 int red =
static_cast<int>( color1.red() * ( 1 - ratio ) + color2.red() * ratio );
4523 int green =
static_cast<int>( color1.green() * ( 1 - ratio ) + color2.green() * ratio );
4524 int blue =
static_cast<int>( color1.blue() * ( 1 - ratio ) + color2.blue() * ratio );
4525 int alpha =
static_cast<int>( color1.alpha() * ( 1 - ratio ) + color2.alpha() * ratio );
4527 QColor newColor( red, green, blue, alpha );
4534 int red = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
4535 int green = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4536 int blue = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4537 QColor color = QColor( red, green, blue );
4538 if ( ! color.isValid() )
4540 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( red ).arg( green ).arg( blue ) );
4541 color = QColor( 0, 0, 0 );
4544 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4549 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
4550 QVariant value = node->
eval( parent, context );
4554 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
4556 value = node->
eval( parent, context );
4564 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
4566 QVariant value = node->
eval( parent, context );
4568 if ( value.toBool() )
4570 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
4572 value = node->
eval( parent, context );
4577 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
4579 value = node->
eval( parent, context );
4587 int red = QgsExpressionUtils::getNativeIntValue( values.at( 0 ), parent );
4588 int green = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
4589 int blue = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4590 int alpha = QgsExpressionUtils::getNativeIntValue( values.at( 3 ), parent );
4591 QColor color = QColor( red, green, blue, alpha );
4592 if ( ! color.isValid() )
4594 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( red ).arg( green ).arg( blue ).arg( alpha ) );
4595 color = QColor( 0, 0, 0 );
4606 expRamp = QgsExpressionUtils::getRamp( values.at( 0 ), parent );
4611 QString rampName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
4615 parent->
setEvalErrorString( QObject::tr(
"\"%1\" is not a valid color ramp" ).arg( rampName ) );
4620 double value = QgsExpressionUtils::getDoubleValue( values.at( 1 ), parent );
4621 QColor color = ramp->
color( value );
4628 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4630 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4632 double lightness = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4634 QColor color = QColor::fromHslF( hue, saturation, lightness );
4636 if ( ! color.isValid() )
4638 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( hue ).arg( saturation ).arg( lightness ) );
4639 color = QColor( 0, 0, 0 );
4642 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4648 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4650 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4652 double lightness = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4654 double alpha = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 255.0;
4656 QColor color = QColor::fromHslF( hue, saturation, lightness, alpha );
4657 if ( ! color.isValid() )
4659 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
4660 color = QColor( 0, 0, 0 );
4668 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4670 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4672 double value = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4674 QColor color = QColor::fromHsvF( hue, saturation, value );
4676 if ( ! color.isValid() )
4678 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3' to color" ).arg( hue ).arg( saturation ).arg( value ) );
4679 color = QColor( 0, 0, 0 );
4682 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4688 double hue = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 360.0;
4690 double saturation = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4692 double value = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4694 double alpha = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 255.0;
4696 QColor color = QColor::fromHsvF( hue, saturation, value, alpha );
4697 if ( ! color.isValid() )
4699 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
4700 color = QColor( 0, 0, 0 );
4708 double cyan = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 100.0;
4710 double magenta = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4712 double yellow = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4714 double black = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 100.0;
4716 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black );
4718 if ( ! color.isValid() )
4720 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ) );
4721 color = QColor( 0, 0, 0 );
4724 return QStringLiteral(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
4730 double cyan = QgsExpressionUtils::getIntValue( values.at( 0 ), parent ) / 100.0;
4732 double magenta = QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) / 100.0;
4734 double yellow = QgsExpressionUtils::getIntValue( values.at( 2 ), parent ) / 100.0;
4736 double black = QgsExpressionUtils::getIntValue( values.at( 3 ), parent ) / 100.0;
4738 double alpha = QgsExpressionUtils::getIntValue( values.at( 4 ), parent ) / 255.0;
4740 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black, alpha );
4741 if ( ! color.isValid() )
4743 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
4744 color = QColor( 0, 0, 0 );
4752 if ( ! color.isValid() )
4754 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4758 QString part = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4759 if ( part.compare( QLatin1String(
"red" ), Qt::CaseInsensitive ) == 0 )
4761 else if ( part.compare( QLatin1String(
"green" ), Qt::CaseInsensitive ) == 0 )
4762 return color.green();
4763 else if ( part.compare( QLatin1String(
"blue" ), Qt::CaseInsensitive ) == 0 )
4764 return color.blue();
4765 else if ( part.compare( QLatin1String(
"alpha" ), Qt::CaseInsensitive ) == 0 )
4766 return color.alpha();
4767 else if ( part.compare( QLatin1String(
"hue" ), Qt::CaseInsensitive ) == 0 )
4768 return color.hsvHueF() * 360;
4769 else if ( part.compare( QLatin1String(
"saturation" ), Qt::CaseInsensitive ) == 0 )
4770 return color.hsvSaturationF() * 100;
4771 else if ( part.compare( QLatin1String(
"value" ), Qt::CaseInsensitive ) == 0 )
4772 return color.valueF() * 100;
4773 else if ( part.compare( QLatin1String(
"hsl_hue" ), Qt::CaseInsensitive ) == 0 )
4774 return color.hslHueF() * 360;
4775 else if ( part.compare( QLatin1String(
"hsl_saturation" ), Qt::CaseInsensitive ) == 0 )
4776 return color.hslSaturationF() * 100;
4777 else if ( part.compare( QLatin1String(
"lightness" ), Qt::CaseInsensitive ) == 0 )
4778 return color.lightnessF() * 100;
4779 else if ( part.compare( QLatin1String(
"cyan" ), Qt::CaseInsensitive ) == 0 )
4780 return color.cyanF() * 100;
4781 else if ( part.compare( QLatin1String(
"magenta" ), Qt::CaseInsensitive ) == 0 )
4782 return color.magentaF() * 100;
4783 else if ( part.compare( QLatin1String(
"yellow" ), Qt::CaseInsensitive ) == 0 )
4784 return color.yellowF() * 100;
4785 else if ( part.compare( QLatin1String(
"black" ), Qt::CaseInsensitive ) == 0 )
4786 return color.blackF() * 100;
4788 parent->
setEvalErrorString( QObject::tr(
"Unknown color component '%1'" ).arg( part ) );
4794 const QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
4795 if ( map.count() < 1 )
4797 parent->
setEvalErrorString( QObject::tr(
"A minimum of two colors is required to create a ramp" ) );
4801 QList< QColor > colors;
4803 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
4806 if ( !colors.last().isValid() )
4808 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( it.value().toString() ) );
4812 double step = it.key().toDouble();
4813 if ( it == map.constBegin() )
4818 else if ( it == map.constEnd() )
4828 bool discrete = values.at( 1 ).toBool();
4830 return QVariant::fromValue(
QgsGradientColorRamp( colors.first(), colors.last(), discrete, stops ) );
4836 if ( ! color.isValid() )
4838 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4842 QString part = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4843 int value = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
4844 if ( part.compare( QLatin1String(
"red" ), Qt::CaseInsensitive ) == 0 )
4845 color.setRed( value );
4846 else if ( part.compare( QLatin1String(
"green" ), Qt::CaseInsensitive ) == 0 )
4847 color.setGreen( value );
4848 else if ( part.compare( QLatin1String(
"blue" ), Qt::CaseInsensitive ) == 0 )
4849 color.setBlue( value );
4850 else if ( part.compare( QLatin1String(
"alpha" ), Qt::CaseInsensitive ) == 0 )
4851 color.setAlpha( value );
4852 else if ( part.compare( QLatin1String(
"hue" ), Qt::CaseInsensitive ) == 0 )
4853 color.setHsv( value, color.hsvSaturation(), color.value(), color.alpha() );
4854 else if ( part.compare( QLatin1String(
"saturation" ), Qt::CaseInsensitive ) == 0 )
4855 color.setHsvF( color.hsvHueF(), value / 100.0, color.valueF(), color.alphaF() );
4856 else if ( part.compare( QLatin1String(
"value" ), Qt::CaseInsensitive ) == 0 )
4857 color.setHsvF( color.hsvHueF(), color.hsvSaturationF(), value / 100.0, color.alphaF() );
4858 else if ( part.compare( QLatin1String(
"hsl_hue" ), Qt::CaseInsensitive ) == 0 )
4859 color.setHsl( value, color.hslSaturation(), color.lightness(), color.alpha() );
4860 else if ( part.compare( QLatin1String(
"hsl_saturation" ), Qt::CaseInsensitive ) == 0 )
4861 color.setHslF( color.hslHueF(), value / 100.0, color.lightnessF(), color.alphaF() );
4862 else if ( part.compare( QLatin1String(
"lightness" ), Qt::CaseInsensitive ) == 0 )
4863 color.setHslF( color.hslHueF(), color.hslSaturationF(), value / 100.0, color.alphaF() );
4864 else if ( part.compare( QLatin1String(
"cyan" ), Qt::CaseInsensitive ) == 0 )
4865 color.setCmykF( value / 100.0, color.magentaF(), color.yellowF(), color.blackF(), color.alphaF() );
4866 else if ( part.compare( QLatin1String(
"magenta" ), Qt::CaseInsensitive ) == 0 )
4867 color.setCmykF( color.cyanF(), value / 100.0, color.yellowF(), color.blackF(), color.alphaF() );
4868 else if ( part.compare( QLatin1String(
"yellow" ), Qt::CaseInsensitive ) == 0 )
4869 color.setCmykF( color.cyanF(), color.magentaF(), value / 100.0, color.blackF(), color.alphaF() );
4870 else if ( part.compare( QLatin1String(
"black" ), Qt::CaseInsensitive ) == 0 )
4871 color.setCmykF( color.cyanF(), color.magentaF(), color.yellowF(), value / 100.0, color.alphaF() );
4874 parent->
setEvalErrorString( QObject::tr(
"Unknown color component '%1'" ).arg( part ) );
4883 if ( ! color.isValid() )
4885 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4889 color = color.darker( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4897 if ( ! color.isValid() )
4899 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to color" ).arg( values.at( 0 ).toString() ) );
4903 color = color.lighter( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
4910 QgsFeature feat = QgsExpressionUtils::getFeature( values.at( 0 ), parent );
4913 return QVariant::fromValue( geom );
4919 QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
4920 QString sAuthId = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4921 QString dAuthId = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
4925 return QVariant::fromValue( fGeom );
4928 return QVariant::fromValue( fGeom );
4937 return QVariant::fromValue( fGeom );
4951 QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer( values.at( 0 ), parent );
4954 QgsFeatureId fid = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
4964 result = QVariant::fromValue( fet );
4974 std::unique_ptr<QgsVectorLayerFeatureSource> featureSource = QgsExpressionUtils::getFeatureSource( values.at( 0 ), parent );
4977 if ( !featureSource )
4982 QString attribute = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
4983 int attributeId = featureSource->fields().lookupField( attribute );
4984 if ( attributeId == -1 )
4989 const QVariant &attVal = values.at( 2 );
4991 const QString cacheValueKey = QStringLiteral(
"getfeature:%1:%2:%3" ).arg( featureSource->id(), QString::number( attributeId ), attVal.toString() );
5013 res = QVariant::fromValue( fet );
5028 if ( !values.isEmpty() )
5031 if ( col && ( values.size() == 1 || !values.at( 1 ).isValid() ) )
5032 fieldName = col->
name();
5033 else if ( values.size() == 2 )
5034 fieldName = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5037 QVariant value = values.at( 0 );
5042 if ( fieldIndex == -1 )
5044 parent->
setEvalErrorString( QCoreApplication::translate(
"expression",
"%1: Field not found %2" ).arg( QStringLiteral(
"represent_value" ), fieldName ) );
5048 QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer( context->
variable( QStringLiteral(
"layer" ) ), parent );
5050 const QString cacheValueKey = QStringLiteral(
"repvalfcnval:%1:%2:%3" ).arg( layer ? layer->
id() : QStringLiteral(
"[None]" ), fieldName, value.toString() );
5059 const QString cacheKey = QStringLiteral(
"repvalfcn:%1:%2" ).arg( layer ? layer->
id() : QStringLiteral(
"[None]" ), fieldName );
5070 result =
formatter->representValue( layer, fieldIndex, setup.
config(), cache, value );
5077 parent->
setEvalErrorString( QCoreApplication::translate(
"expression",
"%1: function cannot be evaluated without a context." ).arg( QStringLiteral(
"represent_value" ), fieldName ) );
5085 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
5091 QString layerProperty = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5092 if ( QString::compare( layerProperty, QStringLiteral(
"name" ), Qt::CaseInsensitive ) == 0 )
5093 return layer->
name();
5094 else if ( QString::compare( layerProperty, QStringLiteral(
"id" ), Qt::CaseInsensitive ) == 0 )
5096 else if ( QString::compare( layerProperty, QStringLiteral(
"title" ), Qt::CaseInsensitive ) == 0 )
5098 else if ( QString::compare( layerProperty, QStringLiteral(
"abstract" ), Qt::CaseInsensitive ) == 0 )
5100 else if ( QString::compare( layerProperty, QStringLiteral(
"keywords" ), Qt::CaseInsensitive ) == 0 )
5102 QStringList keywords;
5104 for (
auto it = keywordMap.constBegin(); it != keywordMap.constEnd(); ++it )
5106 keywords.append( it.value() );
5108 if ( !keywords.isEmpty() )
5112 else if ( QString::compare( layerProperty, QStringLiteral(
"data_url" ), Qt::CaseInsensitive ) == 0 )
5114 else if ( QString::compare( layerProperty, QStringLiteral(
"attribution" ), Qt::CaseInsensitive ) == 0 )
5118 else if ( QString::compare( layerProperty, QStringLiteral(
"attribution_url" ), Qt::CaseInsensitive ) == 0 )
5120 else if ( QString::compare( layerProperty, QStringLiteral(
"source" ), Qt::CaseInsensitive ) == 0 )
5122 else if ( QString::compare( layerProperty, QStringLiteral(
"min_scale" ), Qt::CaseInsensitive ) == 0 )
5124 else if ( QString::compare( layerProperty, QStringLiteral(
"max_scale" ), Qt::CaseInsensitive ) == 0 )
5126 else if ( QString::compare( layerProperty, QStringLiteral(
"is_editable" ), Qt::CaseInsensitive ) == 0 )
5128 else if ( QString::compare( layerProperty, QStringLiteral(
"crs" ), Qt::CaseInsensitive ) == 0 )
5130 else if ( QString::compare( layerProperty, QStringLiteral(
"crs_definition" ), Qt::CaseInsensitive ) == 0 )
5132 else if ( QString::compare( layerProperty, QStringLiteral(
"crs_description" ), Qt::CaseInsensitive ) == 0 )
5134 else if ( QString::compare( layerProperty, QStringLiteral(
"extent" ), Qt::CaseInsensitive ) == 0 )
5137 QVariant result = QVariant::fromValue( extentGeom );
5140 else if ( QString::compare( layerProperty, QStringLiteral(
"distance_units" ), Qt::CaseInsensitive ) == 0 )
5142 else if ( QString::compare( layerProperty, QStringLiteral(
"type" ), Qt::CaseInsensitive ) == 0 )
5144 switch ( layer->
type() )
5147 return QCoreApplication::translate(
"expressions",
"Vector" );
5149 return QCoreApplication::translate(
"expressions",
"Raster" );
5151 return QCoreApplication::translate(
"expressions",
"Mesh" );
5153 return QCoreApplication::translate(
"expressions",
"Vector Tile" );
5155 return QCoreApplication::translate(
"expressions",
"Plugin" );
5157 return QCoreApplication::translate(
"expressions",
"Annotation" );
5159 return QCoreApplication::translate(
"expressions",
"Point Cloud" );
5165 QgsVectorLayer *vLayer = qobject_cast< QgsVectorLayer * >( layer );
5168 if ( QString::compare( layerProperty, QStringLiteral(
"storage_type" ), Qt::CaseInsensitive ) == 0 )
5170 else if ( QString::compare( layerProperty, QStringLiteral(
"geometry_type" ), Qt::CaseInsensitive ) == 0 )
5172 else if ( QString::compare( layerProperty, QStringLiteral(
"feature_count" ), Qt::CaseInsensitive ) == 0 )
5174 else if ( QString::compare( layerProperty, QStringLiteral(
"path" ), Qt::CaseInsensitive ) == 0 )
5179 return decodedUri.value( QStringLiteral(
"path" ) );
5190 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
5193 parent->
setEvalErrorString( QObject::tr(
"Cannot find layer %1" ).arg( values.at( 0 ).toString() ) );
5203 const QString uriPart = values.at( 1 ).toString();
5207 if ( !uriPart.isNull() )
5209 return decodedUri.value( values.at( 1 ).toString() );
5219 QString layerIdOrName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5226 if ( !layersByName.isEmpty() )
5228 layer = layersByName.at( 0 );
5239 int band = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5240 if ( band < 1 || band > rl->
bandCount() )
5242 parent->
setEvalErrorString( QObject::tr(
"Invalid band number %1 for layer %2" ).arg( band ).arg( layerIdOrName ) );
5246 QString layerProperty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5249 if ( QString::compare( layerProperty, QStringLiteral(
"avg" ), Qt::CaseInsensitive ) == 0 )
5251 else if ( QString::compare( layerProperty, QStringLiteral(
"stdev" ), Qt::CaseInsensitive ) == 0 )
5253 else if ( QString::compare( layerProperty, QStringLiteral(
"min" ), Qt::CaseInsensitive ) == 0 )
5255 else if ( QString::compare( layerProperty, QStringLiteral(
"max" ), Qt::CaseInsensitive ) == 0 )
5257 else if ( QString::compare( layerProperty, QStringLiteral(
"range" ), Qt::CaseInsensitive ) == 0 )
5259 else if ( QString::compare( layerProperty, QStringLiteral(
"sum" ), Qt::CaseInsensitive ) == 0 )
5263 parent->
setEvalErrorString( QObject::tr(
"Invalid raster statistic: '%1'" ).arg( layerProperty ) );
5293 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5294 bool ascending = values.value( 1 ).toBool();
5295 std::sort( list.begin(), list.end(), [ascending]( QVariant a, QVariant b ) ->
bool { return ( !ascending ? qgsVariantLessThan( b, a ) : qgsVariantLessThan( a, b ) ); } );
5301 return QgsExpressionUtils::getListValue( values.at( 0 ), parent ).length();
5306 return QVariant( QgsExpressionUtils::getListValue( values.at( 0 ), parent ).contains( values.at( 1 ) ) );
5311 QVariantList listA = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5312 QVariantList listB = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
5314 for (
const auto &item : listB )
5316 if ( listA.contains( item ) )
5320 return QVariant( match == listB.count() );
5325 return QgsExpressionUtils::getListValue( values.at( 0 ), parent ).indexOf( values.at( 1 ) );
5330 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5331 const int pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5332 if ( pos < list.length() && pos >= 0 )
return list.at( pos );
5333 else if ( pos < 0 && ( list.length() + pos ) >= 0 )
5334 return list.at( list.length() + pos );
5340 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5341 return list.value( 0 );
5346 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5347 return list.value( list.size() - 1 );
5352 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5353 return list.isEmpty() ? QVariant() : *std::min_element( list.constBegin(), list.constEnd(), []( QVariant a, QVariant b ) -> bool { return (
qgsVariantLessThan( a, b ) ); } );
5358 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5359 return list.isEmpty() ? QVariant() : *std::max_element( list.constBegin(), list.constEnd(), []( QVariant a, QVariant b ) -> bool { return (
qgsVariantLessThan( a, b ) ); } );
5364 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5367 for (
const QVariant &item : list )
5369 switch ( item.userType() )
5371 case QMetaType::Int:
5372 case QMetaType::UInt:
5373 case QMetaType::LongLong:
5374 case QMetaType::ULongLong:
5375 case QMetaType::Float:
5376 case QMetaType::Double:
5377 total += item.toDouble();
5382 return i == 0 ? QVariant() : total / i;
5387 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5388 QVariantList numbers;
5389 for (
const auto &item : list )
5391 switch ( item.userType() )
5393 case QMetaType::Int:
5394 case QMetaType::UInt:
5395 case QMetaType::LongLong:
5396 case QMetaType::ULongLong:
5397 case QMetaType::Float:
5398 case QMetaType::Double:
5399 numbers.append( item );
5403 std::sort( numbers.begin(), numbers.end(), []( QVariant a, QVariant b ) ->
bool { return ( qgsVariantLessThan( a, b ) ); } );
5404 const int count = numbers.count();
5409 else if ( count % 2 )
5411 return numbers.at( count / 2 );
5415 return ( numbers.at( count / 2 - 1 ).toDouble() + numbers.at( count / 2 ).toDouble() ) / 2;
5421 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5422 QHash< QVariant, int > hash;
5423 for (
const auto &item : list )
5427 const QList< int > occurrences = hash.values();
5428 const int maxValue = *std::max_element( occurrences.constBegin(), occurrences.constEnd() );
5429 return list.isEmpty() ? QVariant() : hash.keys( maxValue );
5434 const QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5437 for (
const QVariant &item : list )
5439 switch ( item.userType() )
5441 case QMetaType::Int:
5442 case QMetaType::UInt:
5443 case QMetaType::LongLong:
5444 case QMetaType::ULongLong:
5445 case QMetaType::Float:
5446 case QMetaType::Double:
5447 total += item.toDouble();
5452 return i == 0 ? QVariant() : total;
5455 static QVariant convertToSameType(
const QVariant &value, QVariant::Type type )
5457 QVariant result = value;
5458 result.convert(
static_cast<int>( type ) );
5464 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5465 list.append( values.at( 1 ) );
5466 return convertToSameType( list, values.at( 0 ).type() );
5471 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5472 list.prepend( values.at( 1 ) );
5473 return convertToSameType( list, values.at( 0 ).type() );
5478 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5479 list.insert( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ), values.at( 2 ) );
5480 return convertToSameType( list, values.at( 0 ).type() );
5485 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5486 list.removeAt( QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent ) );
5487 return convertToSameType( list, values.at( 0 ).type() );
5492 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5493 list.removeAll( values.at( 1 ) );
5494 return convertToSameType( list, values.at( 0 ).type() );
5500 for (
const QVariant &cur : values )
5502 list += QgsExpressionUtils::getListValue( cur, parent );
5504 return convertToSameType( list, values.at( 0 ).type() );
5509 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5510 int start_pos = QgsExpressionUtils::getNativeIntValue( values.at( 1 ), parent );
5511 const int end_pos = QgsExpressionUtils::getNativeIntValue( values.at( 2 ), parent );
5512 int slice_length = 0;
5514 if ( start_pos < 0 )
5516 start_pos = list.length() + start_pos;
5520 slice_length = end_pos - start_pos + 1;
5524 slice_length = list.length() + end_pos - start_pos + 1;
5527 if ( slice_length < 0 )
5531 list = list.mid( start_pos, slice_length );
5537 QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5538 std::reverse( list.begin(), list.end() );
5544 const QVariantList array1 = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5545 const QVariantList array2 = QgsExpressionUtils::getListValue( values.at( 1 ), parent );
5546 for (
const QVariant &cur : array2 )
5548 if ( array1.contains( cur ) )
5549 return QVariant(
true );
5551 return QVariant(
false );
5556 QVariantList array = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5558 QVariantList distinct;
5560 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
5562 if ( !distinct.contains( *it ) )
5564 distinct += ( *it );
5573 QVariantList array = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
5574 QString delimiter = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5575 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5579 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
5581 str += ( !( *it ).toString().isEmpty() ) ? ( *it ).toString() : empty;
5582 if ( it != ( array.constEnd() - 1 ) )
5588 return QVariant( str );
5593 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5594 QString delimiter = QgsExpressionUtils::getStringValue( values.at( 1 ), parent );
5595 QString empty = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
5597 QStringList list = str.split( delimiter );
5600 for ( QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
5602 array += ( !( *it ).isEmpty() ) ? *it : empty;
5610 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5611 QJsonDocument document = QJsonDocument::fromJson( str.toUtf8() );
5612 if ( document.isNull() )
5615 return document.toVariant();
5621 QJsonDocument document = QJsonDocument::fromVariant( values.at( 0 ) );
5622 return document.toJson( QJsonDocument::Compact );
5627 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5628 if ( str.isEmpty() )
5629 return QVariantMap();
5630 str = str.trimmed();
5637 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5644 for (
int i = 0; i + 1 < values.length(); i += 2 )
5646 result.insert( QgsExpressionUtils::getStringValue( values.at( i ), parent ), values.at( i + 1 ) );
5653 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).value( values.at( 1 ).toString() );
5658 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).contains( values.at( 1 ).toString() );
5663 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5664 map.remove( values.at( 1 ).toString() );
5670 QVariantMap map = QgsExpressionUtils::getMapValue( values.at( 0 ), parent );
5671 map.insert( values.at( 1 ).toString(), values.at( 2 ) );
5678 for (
const QVariant &cur : values )
5680 const QVariantMap curMap = QgsExpressionUtils::getMapValue( cur, parent );
5681 for ( QVariantMap::const_iterator it = curMap.constBegin(); it != curMap.constEnd(); ++it )
5682 result.insert( it.key(), it.value() );
5689 return QStringList( QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).keys() );
5694 return QgsExpressionUtils::getMapValue( values.at( 0 ), parent ).values();
5699 QString envVarName = values.at( 0 ).toString();
5700 return QProcessEnvironment::systemEnvironment().value( envVarName );
5705 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5706 return QFileInfo( file ).completeBaseName();
5711 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5712 return QFileInfo( file ).completeSuffix();
5717 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5718 return QFileInfo::exists( file );
5723 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5724 return QFileInfo( file ).fileName();
5729 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5730 return QFileInfo( file ).isFile();
5735 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5736 return QFileInfo( file ).isDir();
5741 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5742 return QDir::toNativeSeparators( QFileInfo( file ).path() );
5747 const QString file = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5748 return QFileInfo( file ).size();
5751 static QVariant fcnHash(
const QString str,
const QCryptographicHash::Algorithm
algorithm )
5753 return QString( QCryptographicHash::hash( str.toUtf8(),
algorithm ).toHex() );
5759 QString str = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5760 QString method = QgsExpressionUtils::getStringValue( values.at( 1 ), parent ).toLower();
5762 if ( method == QLatin1String(
"md4" ) )
5764 hash = fcnHash( str, QCryptographicHash::Md4 );
5766 else if ( method == QLatin1String(
"md5" ) )
5768 hash = fcnHash( str, QCryptographicHash::Md5 );
5770 else if ( method == QLatin1String(
"sha1" ) )
5772 hash = fcnHash( str, QCryptographicHash::Sha1 );
5774 else if ( method == QLatin1String(
"sha224" ) )
5776 hash = fcnHash( str, QCryptographicHash::Sha224 );
5778 else if ( method == QLatin1String(
"sha256" ) )
5780 hash = fcnHash( str, QCryptographicHash::Sha256 );
5782 else if ( method == QLatin1String(
"sha384" ) )
5784 hash = fcnHash( str, QCryptographicHash::Sha384 );
5786 else if ( method == QLatin1String(
"sha512" ) )
5788 hash = fcnHash( str, QCryptographicHash::Sha512 );
5790 else if ( method == QLatin1String(
"sha3_224" ) )
5792 hash = fcnHash( str, QCryptographicHash::Sha3_224 );
5794 else if ( method == QLatin1String(
"sha3_256" ) )
5796 hash = fcnHash( str, QCryptographicHash::Sha3_256 );
5798 else if ( method == QLatin1String(
"sha3_384" ) )
5800 hash = fcnHash( str, QCryptographicHash::Sha3_384 );
5802 else if ( method == QLatin1String(
"sha3_512" ) )
5804 hash = fcnHash( str, QCryptographicHash::Sha3_512 );
5806 #if QT_VERSION >= QT_VERSION_CHECK( 5, 9, 2 )
5807 else if ( method == QLatin1String(
"keccak_224" ) )
5809 hash = fcnHash( str, QCryptographicHash::Keccak_224 );
5811 else if ( method == QLatin1String(
"keccak_256" ) )
5813 hash = fcnHash( str, QCryptographicHash::Keccak_256 );
5815 else if ( method == QLatin1String(
"keccak_384" ) )
5817 hash = fcnHash( str, QCryptographicHash::Keccak_384 );
5819 else if ( method == QLatin1String(
"keccak_512" ) )
5821 hash = fcnHash( str, QCryptographicHash::Keccak_512 );
5826 parent->
setEvalErrorString( QObject::tr(
"Hash method %1 is not available on this system." ).arg( str ) );
5833 return fcnHash( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), QCryptographicHash::Md5 );
5838 return fcnHash( QgsExpressionUtils::getStringValue( values.at( 0 ), parent ), QCryptographicHash::Sha256 );
5843 const QByteArray input = values.at( 0 ).toByteArray();
5844 return QVariant( QString( input.toBase64() ) );
5849 const QString value = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
5850 const QByteArray base64 = value.toLocal8Bit();
5851 const QByteArray decoded = QByteArray::fromBase64( base64 );
5852 return QVariant( decoded );
5860 const QVariant sourceLayerRef = context->
variable( QStringLiteral(
"layer" ) );
5861 QgsVectorLayer *sourceLayer = QgsExpressionUtils::getVectorLayer( sourceLayerRef, parent );
5868 QgsExpressionNode *node = QgsExpressionUtils::getNode( values.at( 0 ), parent );
5871 const bool layerCanBeCached = node->
isStatic( parent, context );
5872 QVariant targetLayerValue = node->
eval( parent, context );
5876 node = QgsExpressionUtils::getNode( values.at( 1 ), parent );
5878 QString subExpString = node->
dump();
5880 bool testOnly = ( subExpString ==
"NULL" );
5881 QgsVectorLayer *targetLayer = QgsExpressionUtils::getVectorLayer( targetLayerValue, parent );
5884 parent->
setEvalErrorString( QObject::tr(
"Layer '%1' could not be loaded." ).arg( targetLayerValue.toString() ) );
5889 node = QgsExpressionUtils::getNode( values.at( 2 ), parent );
5891 QString filterString = node->
dump();
5892 if ( filterString !=
"NULL" )
5898 node = QgsExpressionUtils::getNode( values.at( 3 ), parent );
5900 QVariant limitValue = node->
eval( parent, context );
5902 qlonglong limit = QgsExpressionUtils::getIntValue( limitValue, parent );
5905 double max_distance = 0;
5906 if ( isNearestFunc )
5908 node = QgsExpressionUtils::getNode( values.at( 4 ), parent );
5910 QVariant distanceValue = node->
eval( parent, context );
5912 max_distance = QgsExpressionUtils::getDoubleValue( distanceValue, parent );
5916 node = QgsExpressionUtils::getNode( values.at( isNearestFunc ? 5 : 4 ), parent );
5918 QVariant cacheValue = node->
eval( parent, context );
5920 bool cacheEnabled = cacheValue.toBool();
5926 if ( sourceLayer && targetLayer->
crs() != sourceLayer->
crs() )
5932 bool sameLayers = ( sourceLayer && sourceLayer->
id() == targetLayer->
id() );
5935 if ( bboxGrow != 0 )
5937 intDomain.
grow( bboxGrow );
5940 const QString cacheBase { QStringLiteral(
"%1:%2" ).arg( targetLayer->
id(), subExpString ) };
5946 QList<QgsFeature> features;
5947 if ( isNearestFunc || ( layerCanBeCached && cacheEnabled ) )
5951 const QString cacheLayer { QStringLiteral(
"ovrlaylyr:%1" ).arg( cacheBase ) };
5952 const QString cacheIndex { QStringLiteral(
"ovrlayidx:%1" ).arg( cacheBase ) };
5956 cachedTarget = targetLayer->
materialize( request );
5957 if ( layerCanBeCached )
5958 context->
setCachedValue( cacheLayer, QVariant::fromValue( cachedTarget ) );
5968 if ( layerCanBeCached )
5969 context->
setCachedValue( cacheIndex, QVariant::fromValue( spatialIndex ) );
5976 QList<QgsFeatureId> fidsList;
5977 if ( isNearestFunc )
5979 fidsList = spatialIndex.
nearestNeighbor( geometry, sameLayers ? limit + 1 : limit, max_distance );
5983 fidsList = spatialIndex.
intersects( intDomain );
5986 QListIterator<QgsFeatureId> i( fidsList );
5987 while ( i.hasNext() )
5990 if ( sameLayers && feat.
id() == fId2 )
5992 features.append( cachedTarget->
getFeature( fId2 ) );
6005 if ( sameLayers && feat.
id() == feat2.
id() )
6007 features.append( feat2 );
6015 const QString expCacheKey { QStringLiteral(
"exp:%1" ).arg( cacheBase ) };
6016 const QString ctxCacheKey { QStringLiteral(
"ctx:%1" ).arg( cacheBase ) };
6022 subExpression.
prepare( &subContext );
6034 QVariantList results;
6036 QListIterator<QgsFeature> i( features );
6037 while ( i.hasNext() && ( limit == -1 || foundCount < limit ) )
6041 if ( ! relationFunction || ( geometry.*relationFunction )( feat2.
geometry() ) )
6054 results.append( subExpression.
evaluate( &subContext ) );
6059 results.append( feat2.
id() );
6075 QVariantList disjoint_results;
6082 if ( !results.contains( feat2.
id() ) )
6085 disjoint_results.append( subExpression.
evaluate( &subContext ) );
6088 return disjoint_results;
6131 return executeGeomOverlay( values, context, parent,
nullptr,
false, 0,
true );
6140 static QMutex sFunctionsMutex( QMutex::Recursive );
6141 QMutexLocker locker( &sFunctionsMutex );
6143 QList<QgsExpressionFunction *> &functions = *sFunctions();
6145 if ( functions.isEmpty() )
6182 functions << randFunc;
6186 functions << randfFunc;
6189 <<
new QgsStaticExpressionFunction( QStringLiteral(
"max" ), -1, fcnMax, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6190 <<
new QgsStaticExpressionFunction( QStringLiteral(
"min" ), -1, fcnMin, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6196 <<
new QgsStaticExpressionFunction( QStringLiteral(
"pi" ), 0, fcnPi, QStringLiteral(
"Math" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"$pi" ) )
6200 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_datetime" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToDateTime, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"todatetime" ) )
6201 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_date" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToDate, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"todate" ) )
6202 <<
new QgsStaticExpressionFunction( QStringLiteral(
"to_time" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"value" ) ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QVariant() ) <<
QgsExpressionFunction::Parameter( QStringLiteral(
"language" ),
true, QVariant() ), fcnToTime, QStringList() << QStringLiteral(
"Conversions" ) << QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"totime" ) )
6207 <<
new QgsStaticExpressionFunction( QStringLiteral(
"coalesce" ), -1, fcnCoalesce, QStringLiteral(
"Conditionals" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
6221 QStringLiteral(
"Aggregates" ),
6230 if ( !node->
args() )
6233 QSet<QString> referencedVars;
6236 QgsExpressionNode *subExpressionNode = node->args()->at( 2 );
6237 referencedVars = subExpressionNode->referencedVariables();
6242 QgsExpressionNode *filterNode = node->args()->at( 3 );
6243 referencedVars.unite( filterNode->referencedVariables() );
6245 return referencedVars.contains( QStringLiteral(
"parent" ) ) || referencedVars.contains( QString() );
6254 if ( !node->
args() )
6255 return QSet<QString>();
6257 QSet<QString> referencedCols;
6258 QSet<QString> referencedVars;
6273 if ( referencedVars.contains( QStringLiteral(
"parent" ) ) || referencedVars.contains( QString() ) )
6276 return referencedCols;
6289 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count" ), aggParams, fcnAggregateCount, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6290 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count_distinct" ), aggParams, fcnAggregateCountDistinct, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6291 <<
new QgsStaticExpressionFunction( QStringLiteral(
"count_missing" ), aggParams, fcnAggregateCountMissing, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6292 <<
new QgsStaticExpressionFunction( QStringLiteral(
"minimum" ), aggParams, fcnAggregateMin, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6293 <<
new QgsStaticExpressionFunction( QStringLiteral(
"maximum" ), aggParams, fcnAggregateMax, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6294 <<
new QgsStaticExpressionFunction( QStringLiteral(
"sum" ), aggParams, fcnAggregateSum, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6295 <<
new QgsStaticExpressionFunction( QStringLiteral(
"mean" ), aggParams, fcnAggregateMean, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6296 <<
new QgsStaticExpressionFunction( QStringLiteral(
"median" ), aggParams, fcnAggregateMedian, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6297 <<
new QgsStaticExpressionFunction( QStringLiteral(
"stdev" ), aggParams, fcnAggregateStdev, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6298 <<
new QgsStaticExpressionFunction( QStringLiteral(
"range" ), aggParams, fcnAggregateRange, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6299 <<
new QgsStaticExpressionFunction( QStringLiteral(
"minority" ), aggParams, fcnAggregateMinority, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6300 <<
new QgsStaticExpressionFunction( QStringLiteral(
"majority" ), aggParams, fcnAggregateMajority, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6301 <<
new QgsStaticExpressionFunction( QStringLiteral(
"q1" ), aggParams, fcnAggregateQ1, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6302 <<
new QgsStaticExpressionFunction( QStringLiteral(
"q3" ), aggParams, fcnAggregateQ3, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6303 <<
new QgsStaticExpressionFunction( QStringLiteral(
"iqr" ), aggParams, fcnAggregateIQR, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6304 <<
new QgsStaticExpressionFunction( QStringLiteral(
"min_length" ), aggParams, fcnAggregateMinLength, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6305 <<
new QgsStaticExpressionFunction( QStringLiteral(
"max_length" ), aggParams, fcnAggregateMaxLength, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6306 <<
new QgsStaticExpressionFunction( QStringLiteral(
"collect" ), aggParams, fcnAggregateCollectGeometry, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6307 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concatenate" ), aggParamsConcat, fcnAggregateStringConcat, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6308 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concatenate_unique" ), aggParamsConcat, fcnAggregateStringConcatUnique, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6309 <<
new QgsStaticExpressionFunction( QStringLiteral(
"array_agg" ), aggParamsArray, fcnAggregateArray, QStringLiteral(
"Aggregates" ), QString(),
false, QSet<QString>(), true )
6314 <<
new QgsStaticExpressionFunction( QStringLiteral(
"now" ), 0, fcnNow, QStringLiteral(
"Date and Time" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"$now" ) )
6317 fcnAge, QStringLiteral(
"Date and Time" ) )
6331 fcnMakeDate, QStringLiteral(
"Date and Time" ) )
6335 fcnMakeTime, QStringLiteral(
"Date and Time" ) )
6342 fcnMakeDateTime, QStringLiteral(
"Date and Time" ) )
6350 fcnMakeInterval, QStringLiteral(
"Date and Time" ) )
6368 false, QSet< QString >(),
false, QStringList(), true )
6369 <<
new QgsStaticExpressionFunction( QStringLiteral(
"concat" ), -1, fcnConcat, QStringLiteral(
"String" ), QString(),
false, QSet<QString>(),
false, QStringList(), true )
6382 fcnColorMixRgb, QStringLiteral(
"Color" ) )
6386 fcnColorRgb, QStringLiteral(
"Color" ) )
6391 fncColorRgba, QStringLiteral(
"Color" ) )
6397 fcnCreateRamp, QStringLiteral(
"Color" ) )
6401 fcnColorHsl, QStringLiteral(
"Color" ) )
6406 fncColorHsla, QStringLiteral(
"Color" ) )
6410 fcnColorHsv, QStringLiteral(
"Color" ) )
6415 fncColorHsva, QStringLiteral(
"Color" ) )
6420 fcnColorCmyk, QStringLiteral(
"Color" ) )
6426 fncColorCmyka, QStringLiteral(
"Color" ) )
6429 fncColorPart, QStringLiteral(
"Color" ) )
6432 fncDarker, QStringLiteral(
"Color" ) )
6435 fncLighter, QStringLiteral(
"Color" ) )
6440 fcnBaseFileName, QStringLiteral(
"Files and Paths" ) )
6442 fcnFileSuffix, QStringLiteral(
"Files and Paths" ) )
6444 fcnFileExists, QStringLiteral(
"Files and Paths" ) )
6446 fcnFileName, QStringLiteral(
"Files and Paths" ) )
6448 fcnPathIsFile, QStringLiteral(
"Files and Paths" ) )
6450 fcnPathIsDir, QStringLiteral(
"Files and Paths" ) )
6452 fcnFilePath, QStringLiteral(
"Files and Paths" ) )
6454 fcnFileSize, QStringLiteral(
"Files and Paths" ) )
6458 fcnGenericHash, QStringLiteral(
"Conversions" ) )
6460 fcnHashMd5, QStringLiteral(
"Conversions" ) )
6462 fcnHashSha256, QStringLiteral(
"Conversions" ) )
6466 fcnToBase64, QStringLiteral(
"Conversions" ) )
6468 fcnFromBase64, QStringLiteral(
"Conversions" ) )
6474 geomFunc->setIsStatic(
false );
6475 functions << geomFunc;
6479 functions << areaFunc;
6485 functions << lengthFunc;
6489 functions << perimeterFunc;
6501 QMap< QString, QgsExpressionFunction::FcnEval > geometry_overlay_definitions
6503 { QStringLiteral(
"overlay_intersects" ), fcnGeomOverlayIntersects },
6504 { QStringLiteral(
"overlay_contains" ), fcnGeomOverlayContains },
6505 { QStringLiteral(
"overlay_crosses" ), fcnGeomOverlayCrosses },
6506 { QStringLiteral(
"overlay_equals" ), fcnGeomOverlayEquals },
6507 { QStringLiteral(
"overlay_touches" ), fcnGeomOverlayTouches },
6508 { QStringLiteral(
"overlay_disjoint" ), fcnGeomOverlayDisjoint },
6509 { QStringLiteral(
"overlay_within" ), fcnGeomOverlayWithin },
6511 QMapIterator< QString, QgsExpressionFunction::FcnEval > i( geometry_overlay_definitions );
6512 while ( i.hasNext() )
6525 functions << fcnGeomOverlayFunc;
6538 functions << fcnGeomOverlayNearestFunc;
6551 fcnNodesToPoints, QStringLiteral(
"GeometryGroup" ) )
6553 <<
new QgsStaticExpressionFunction( QStringLiteral(
"collect_geometries" ), -1, fcnCollectGeometries, QStringLiteral(
"GeometryGroup" ) )
6558 fcnMakePointM, QStringLiteral(
"GeometryGroup" ) )
6564 fcnMakeTriangle, QStringLiteral(
"GeometryGroup" ) )
6569 fcnMakeCircle, QStringLiteral(
"GeometryGroup" ) )
6576 fcnMakeEllipse, QStringLiteral(
"GeometryGroup" ) )
6582 fcnMakeRegularPolygon, QStringLiteral(
"GeometryGroup" ) )
6586 fcnMakeSquare, QStringLiteral(
"GeometryGroup" ) )
6592 fcnMakeRectangleFrom3Points, QStringLiteral(
"GeometryGroup" ) );
6595 functions << xAtFunc;
6599 functions << yAtFunc;
6614 fcnDisjoint, QStringLiteral(
"GeometryGroup" ) )
6617 fcnIntersects, QStringLiteral(
"GeometryGroup" ) )
6620 fcnTouches, QStringLiteral(
"GeometryGroup" ) )
6623 fcnCrosses, QStringLiteral(
"GeometryGroup" ) )
6626 fcnContains, QStringLiteral(
"GeometryGroup" ) )
6629 fcnOverlaps, QStringLiteral(
"GeometryGroup" ) )
6632 fcnWithin, QStringLiteral(
"GeometryGroup" ) )
6636 fcnTranslate, QStringLiteral(
"GeometryGroup" ) )
6640 fcnRotate, QStringLiteral(
"GeometryGroup" ) )
6644 fcnBuffer, QStringLiteral(
"GeometryGroup" ) )
6646 fcnForceRHR, QStringLiteral(
"GeometryGroup" ) )
6656 , fcnTaperedBuffer, QStringLiteral(
"GeometryGroup" ) )
6659 , fcnBufferByM, QStringLiteral(
"GeometryGroup" ) )
6665 fcnOffsetCurve, QStringLiteral(
"GeometryGroup" ) )
6671 fcnSingleSidedBuffer, QStringLiteral(
"GeometryGroup" ) )
6675 fcnExtend, QStringLiteral(
"GeometryGroup" ) )
6684 fcnInteriorRingN, QStringLiteral(
"GeometryGroup" ) )
6687 fcnGeometryN, QStringLiteral(
"GeometryGroup" ) )
6710 fcnOrientedBBox, QStringLiteral(
"GeometryGroup" ) )
6713 fcnMainAngle, QStringLiteral(
"GeometryGroup" ) )
6717 fcnMinimalCircle, QStringLiteral(
"GeometryGroup" ) )
6720 fcnDifference, QStringLiteral(
"GeometryGroup" ) )
6723 fcnDistance, QStringLiteral(
"GeometryGroup" ) )
6726 fcnHausdorffDistance, QStringLiteral(
"GeometryGroup" ) )
6729 fcnIntersection, QStringLiteral(
"GeometryGroup" ) )
6732 fcnSymDifference, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"symDifference" ) )
6735 fcnCombine, QStringLiteral(
"GeometryGroup" ) )
6738 fcnCombine, QStringLiteral(
"GeometryGroup" ) )
6741 fcnGeomToWKT, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"geomToWKT" ) )
6743 fcnGeomToWKB, QStringLiteral(
"GeometryGroup" ), QString(),
false, QSet<QString>(),
false )
6748 fcnTransformGeometry, QStringLiteral(
"GeometryGroup" ) )
6752 fcnExtrude, QStringLiteral(
"GeometryGroup" ), QString() )
6754 fcnGeomIsMultipart, QStringLiteral(
"GeometryGroup" ) )
6756 fcnZMax, QStringLiteral(
"GeometryGroup" ) )
6758 fcnZMin, QStringLiteral(
"GeometryGroup" ) )
6760 fcnMMax, QStringLiteral(
"GeometryGroup" ) )
6762 fcnMMin, QStringLiteral(
"GeometryGroup" ) );
6768 fcnOrderParts, QStringLiteral(
"GeometryGroup" ), QString() );
6773 const QList< QgsExpressionNode *> argList = node->
args()->list();
6776 if ( !argNode->isStatic( parent, context ) )
6782 QgsExpressionNode *argNode = node->args()->at( 1 );
6784 QString expString = argNode->eval( parent, context ).toString();
6786 QgsExpression e( expString );
6788 if ( e.rootNode() && e.rootNode()->isStatic( parent, context ) )
6799 QgsExpressionNode *argNode = node->args()->at( 1 );
6800 QString expression = argNode->eval( parent, context ).toString();
6801 QgsExpression e( expression );
6802 e.prepare( context );
6803 context->setCachedValue( expression, QVariant::fromValue( e ) );
6808 functions << orderPartsFunc;
6813 fcnClosestPoint, QStringLiteral(
"GeometryGroup" ) )
6816 fcnShortestLine, QStringLiteral(
"GeometryGroup" ) )
6835 functions << idFunc;
6839 functions << currentFeatureFunc;
6841 QgsStaticExpressionFunction *uuidFunc =
new QgsStaticExpressionFunction( QStringLiteral(
"uuid" ),
QgsExpressionFunction::ParameterList() <<
QgsExpressionFunction::Parameter( QStringLiteral(
"format" ),
true, QStringLiteral(
"WithBraces" ) ), fcnUuid, QStringLiteral(
"Record and Attributes" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"$uuid" ) );
6843 functions << uuidFunc;
6849 fcnGetFeature, QStringLiteral(
"Record and Attributes" ), QString(),
false, QSet<QString>(),
false, QStringList() << QStringLiteral(
"QgsExpressionUtils::getFeature" ) )
6852 fcnGetFeatureById, QStringLiteral(
"Record and Attributes" ), QString(),
false, QSet<QString>(),
false );
6857 functions << attributesFunc;
6860 QStringLiteral(
"maptip" ),
6863 QStringLiteral(
"Record and Attributes" ),
6869 functions << maptipFunc;
6872 QStringLiteral(
"display_expression" ),
6874 fcnFeatureDisplayExpression,
6875 QStringLiteral(
"Record and Attributes" ),
6881 functions << displayFunc;
6884 QStringLiteral(
"is_selected" ),
6887 QStringLiteral(
"Record and Attributes" ),
6893 functions << isSelectedFunc;
6897 QStringLiteral(
"num_selected" ),
6900 QStringLiteral(
"Record and Attributes" ),
6908 QStringLiteral(
"sqlite_fetch_and_increment" ),
6916 fcnSqliteFetchAndIncrement,
6917 QStringLiteral(
"Record and Attributes" )
6935 parent->
setEvalErrorString( tr(
"If represent_value is called with 1 parameter, it must be an attribute." ) );
6945 parent->
setEvalErrorString( tr(
"represent_value must be called with exactly 1 or 2 parameters." ) );
6951 functions << representValueFunc;
6957 fcnGetLayerProperty, QStringLiteral(
"General" ) )
6962 fcnDecodeUri, QStringLiteral(
"Map Layers" ) )
6979 QgsExpressionNode *argNode = node->args()->at( 0 );
6981 if ( !argNode->isStatic( parent, context ) )
6984 QString varName = argNode->eval( parent, context ).toString();
6986 const QgsExpressionContextScope *scope = context->activeScopeForVariable( varName );
6987 return scope ? scope->isStatic( varName ) : false;
7004 QgsExpressionNode *argNode = node->args()->at( 0 );
7006 if ( argNode->isStatic( parent, context ) )
7008 QString expString = argNode->eval( parent, context ).toString();
7010 QgsExpression e( expString );
7012 if ( e.rootNode() && e.rootNode()->isStatic( parent, context ) )
7020 functions << evalFunc;
7026 const QList< QgsExpressionNode *> argList = node->
args()->list();
7029 if ( !argNode->isStatic( parent, context ) )
7041 functions << attributeFunc;
7051 <<
new QgsStaticExpressionFunction( QStringLiteral(
"array" ), -1, fcnArray, QStringLiteral(
"Arrays" ), QString(),
false, QSet<QString>(),
false, QStringList(),
true )
7102 *sOwnedFunctions() << func;
7103 *sBuiltinFunctions() << func->name();
7104 sBuiltinFunctions()->append( func->aliases() );
7117 sFunctions()->append(
function );
7118 if ( transferOwnership )
7119 sOwnedFunctions()->append(
function );
7133 sFunctions()->removeAt( fnIdx );
7141 qDeleteAll( *sOwnedFunctions() );
7142 sOwnedFunctions()->clear();
7147 if ( sBuiltinFunctions()->isEmpty() )
7151 return *sBuiltinFunctions();
7159 QStringLiteral(
"Arrays" ) )
7170 if ( args->
count() < 2 )
7173 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7183 QVariantList result;
7185 if ( args->
count() < 2 )
7189 QVariantList array = args->
at( 0 )->
eval( parent, context ).toList();
7192 std::unique_ptr< QgsExpressionContext > tempContext;
7195 tempContext = qgis::make_unique< QgsExpressionContext >();
7196 subContext = tempContext.get();
7202 for ( QVariantList::const_iterator it = array.constBegin(); it != array.constEnd(); ++it )
7205 result << args->
at( 1 )->
eval( parent, subContext );
7230 if ( args->
count() < 2 )
7234 args->
at( 0 )->
prepare( parent, context );
7238 subContext = *context;
7244 args->
at( 1 )->
prepare( parent, &subContext );
7254 QStringLiteral(
"Arrays" ) )
7265 if ( args->
count() < 2 )
7268 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7278 QVariantList result;
7280 if ( args->
count() < 2 )
7284 const QVariantList array = args->
at( 0 )->
eval( parent, context ).toList();
7287 std::unique_ptr< QgsExpressionContext > tempContext;
7290 tempContext = qgis::make_unique< QgsExpressionContext >();
7291 subContext = tempContext.get();
7298 if ( args->
count() >= 3 )
7300 const QVariant limitVar = args->
at( 2 )->
eval( parent, context );
7302 if ( QgsExpressionUtils::isIntSafe( limitVar ) )
7304 limit = limitVar.toInt();
7312 for (
const QVariant &value : array )
7315 if ( args->
at( 1 )->
eval( parent, subContext ).toBool() )
7319 if ( limit > 0 && limit == result.size() )
7346 if ( args->
count() < 2 )
7350 args->
at( 0 )->
prepare( parent, context );
7354 subContext = *context;
7360 args->
at( 1 )->
prepare( parent, &subContext );
7369 QStringLiteral(
"General" ) )
7380 if ( args->
count() < 3 )
7384 if ( args->
at( 0 )->
isStatic( parent, context ) && args->
at( 1 )->
isStatic( parent, context ) )
7386 QVariant
name = args->
at( 0 )->
eval( parent, context );
7387 QVariant value = args->
at( 1 )->
eval( parent, context );
7390 appendTemporaryVariable( context,
name.toString(), value );
7391 if ( args->
at( 2 )->
isStatic( parent, context ) )
7393 popTemporaryVariable( context );
7404 if ( args->
count() < 3 )
7408 QVariant
name = args->
at( 0 )->
eval( parent, context );
7409 QVariant value = args->
at( 1 )->
eval( parent, context );
7412 std::unique_ptr< QgsExpressionContext > tempContext;
7413 if ( !updatedContext )
7415 tempContext = qgis::make_unique< QgsExpressionContext >();
7416 updatedContext = tempContext.get();
7419 appendTemporaryVariable( updatedContext,
name.toString(), value );
7420 result = args->
at( 2 )->
eval( parent, updatedContext );
7423 popTemporaryVariable( updatedContext );
7444 if ( args->
count() < 3 )
7449 QVariant value = args->
at( 1 )->
prepare( parent, context );
7452 std::unique_ptr< QgsExpressionContext > tempContext;
7453 if ( !updatedContext )
7455 tempContext = qgis::make_unique< QgsExpressionContext >();
7456 updatedContext = tempContext.get();
7459 appendTemporaryVariable( updatedContext,
name.toString(), value );
7460 args->
at( 2 )->
prepare( parent, updatedContext );
7463 popTemporaryVariable( updatedContext );
7468 void QgsWithVariableExpressionFunction::popTemporaryVariable(
const QgsExpressionContext *context )
const
7474 void QgsWithVariableExpressionFunction::appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &name,
const QVariant &value )
const
Abstract base class for all geometries.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
bool isMeasure() const SIP_HOLDGIL
Returns true if the geometry contains m values.
Aggregate
Available aggregates to calculate.
@ StringConcatenateUnique
Concatenate unique values with a joining string (string fields only). Specify the delimiter using set...
@ StringMaximumLength
Maximum length of string (string fields only)
@ ThirdQuartile
Third quartile (numeric fields only)
@ Range
Range of values (max - min) (numeric and datetime fields only)
@ ArrayAggregate
Create an array of values.
@ InterQuartileRange
Inter quartile range (IQR) (numeric fields only)
@ FirstQuartile
First quartile (numeric fields only)
@ Median
Median of values (numeric fields only)
@ GeometryCollect
Create a multipart geometry from aggregated geometries.
@ CountMissing
Number of missing (null) values.
@ StDevSample
Sample standard deviation of values (numeric fields only)
@ Majority
Majority of values.
@ StringConcatenate
Concatenate values with a joining string (string fields only). Specify the delimiter using setDelimit...
@ Mean
Mean of values (numeric fields only)
@ StringMinimumLength
Minimum length of string (string fields only)
@ CountDistinct
Number of distinct values.
@ Minority
Minority of values.
static Aggregate stringToAggregate(const QString &string, bool *ok=nullptr)
Converts a string to a aggregate type.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
Handles the array_filter(array, expression) expression function.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QgsArrayFilterExpressionFunction()
Handles the array_foreach(array, expression) expression function.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
QgsArrayForeachExpressionFunction()
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
Abstract base class for color ramps.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toProj() const
Returns a Proj string representation of this CRS.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
QString authid() const
Returns the authority identifier for the CRS.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
int ringCount(int part=0) const override SIP_HOLDGIL
Returns the number of rings of which this geometry is built.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
Abstract base class for curved geometry type.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual bool isClosed() const SIP_HOLDGIL
Returns true if the curve is closed.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
virtual QgsCurve * curveSubstring(double startDistance, double endDistance) const =0
Returns a new curve representing a substring of this curve.
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
double measureArea(const QgsGeometry &geometry) const
Measures the area of a geometry.
double measurePerimeter(const QgsGeometry &geometry) const
Measures the perimeter of a polygon geometry.
double measureLength(const QgsGeometry &geometry) const
Measures the length of a geometry.
double convertAreaMeasurement(double area, QgsUnitTypes::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
double convertLengthMeasurement(double length, QgsUnitTypes::DistanceUnit toUnits) const
Takes a length measurement calculated by this QgsDistanceArea object and converts it to a different d...
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
bool isStatic(const QString &name) const
Tests whether the variable with the specified name is static and can be cached.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void setCachedValue(const QString &key, const QVariant &value) const
Sets a value to cache within the expression context.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QgsExpressionContextScope * activeScopeForVariable(const QString &name)
Returns the currently active scope from the context for a specified variable name.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool hasCachedValue(const QString &key) const
Returns true if the expression context contains a cached value with a matching key.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QVariant cachedValue(const QString &key) const
Returns the matching cached value, if set.
bool hasFeature() const
Returns true if the context has a feature associated with it.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
Represents a single parameter passed to a function.
A abstract base class for defining QgsExpression functions.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
bool operator==(const QgsExpressionFunction &other) const
virtual bool isDeprecated() const
Returns true if the function is deprecated and should not be presented as a valid option to users in ...
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
virtual QStringList aliases() const
Returns a list of possible aliases for the function.
bool lazyEval() const
true if this function should use lazy evaluation.
static bool allParamsStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context)
This will return true if all the params for the provided function node are static within the constrai...
QString name() const
The name of the function.
virtual QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)
Evaluates the function, first evaluating all required arguments before passing them to the function's...
virtual QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)=0
Returns result of evaluating the function.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
virtual bool handlesNull() const
Returns true if the function handles NULL values in arguments by itself, and the default NULL value h...
virtual bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
This will be called during the prepare step() of an expression if it is not static.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
An expression node which takes it value from a feature's field.
QString name() const
The name of the column.
An expression node for expression functions.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
An expression node for literal values.
A list of expression nodes.
QgsExpressionNode * at(int i)
Gets the node at position i in the list.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
int count() const
Returns the number of nodes in the list.
Abstract base class for all nodes that can appear in an expression.
virtual QString dump() const =0
Dump this node into a serialized (part) of an expression.
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
bool prepare(QgsExpression *parent, const QgsExpressionContext *context)
Prepare this node for evaluation.
virtual QSet< QString > referencedColumns() const =0
Abstract virtual method which returns a list of columns required to evaluate this node.
virtual QSet< QString > referencedVariables() const =0
Returns a set of all variables which are used in this expression.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
static const QList< QgsExpressionFunction * > & Functions()
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine.
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static int functionIndex(const QString &name)
Returns index of the function in Functions array.
static const QStringList & BuiltinFunctions()
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes)
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...
QgsUnitTypes::AreaUnit areaUnits() const
Returns the desired areal units for calculations involving geomCalculator(), e.g.,...
static QString helpText(QString name)
Returns the help text for a specified function.
static bool unregisterFunction(const QString &name)
Unregisters a function from the expression engine.
QgsUnitTypes::DistanceUnit distanceUnits() const
Returns the desired distance units for calculations involving geomCalculator(), e....
void setEvalErrorString(const QString &str)
Sets evaluation error (used internally by evaluation functions)
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QVariant evaluate()
Evaluate the feature and return the result.
QgsDistanceArea * geomCalculator()
Returns calculator used for distance and area calculations (used by $length, $area and $perimeter fun...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
Represents a list of OrderByClauses, with the most important first and the least important last.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setRequestMayBeNested(bool requestMayBeNested)
In case this request may be run nested within another already running iteration on the same connectio...
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setTimeout(int timeout)
Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before...
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsVectorLayer * materialize(const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
Materializes a request (query) made against this feature source, by running it over the source and re...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isValid() const
Returns the validity of this feature.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Container of fields for a vector layer.
int count() const
Returns number of items.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
virtual bool removeGeometry(int nr)
Removes a geometry from the collection.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
int partCount() const override
Returns count of parts contained in the geometry.
static QVector< QgsLineString * > extractLineStrings(const QgsAbstractGeometry *geom)
Returns list of linestrings extracted from the passed geometry.
A geometry is the spatial representation of a feature.
double hausdorffDistanceDensify(const QgsGeometry &geom, double densifyFraction) const
Returns the Hausdorff distance between this geometry and geom.
JoinStyle
Join styles for buffers.
@ JoinStyleBevel
Use beveled joins.
@ JoinStyleRound
Use rounded joins.
double lineLocatePoint(const QgsGeometry &point) const
Returns a distance representing the location along this linestring of the closest point on this lines...
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsGeometry poleOfInaccessibility(double precision, double *distanceToBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
bool vertexIdFromVertexNr(int number, QgsVertexId &id) const
Calculates the vertex ID from a vertex number.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
bool touches(const QgsGeometry &geometry) const
Returns true if the geometry touches another geometry.
QgsGeometry nearestPoint(const QgsGeometry &other) const
Returns the nearest (closest) point on this geometry to another geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
OperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer for a (multi)linestring geometry, where the width at each node is ...
QgsMultiPointXY asMultiPoint() const
Returns the contents of the geometry as a multi-point.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
@ SideLeft
Buffer to left of line.
bool disjoint(const QgsGeometry &geometry) const
Returns true if the geometry is disjoint of another geometry.
QgsGeometry combine(const QgsGeometry &geometry) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
double distance(const QgsGeometry &geom) const
Returns the minimum distance between this geometry and another geometry.
QgsGeometry interpolate(double distance) const
Returns an interpolated point on the geometry at the specified distance.
QgsGeometry extrude(double x, double y)
Returns an extruded version of this geometry.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
QgsGeometry forceRHR() const
Forces geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon is t...
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
QgsWkbTypes::GeometryType type
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a variable width buffer ("tapered buffer") for a (multi)curve geometry.
bool within(const QgsGeometry &geometry) const
Returns true if the geometry is completely within another geometry.
QgsGeometry orientedMinimumBoundingBox(double &area, double &angle, double &width, double &height) const
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated r...
double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
bool crosses(const QgsGeometry &geometry) const
Returns true if the geometry crosses another geometry.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
double hausdorffDistance(const QgsGeometry &geom) const
Returns the Hausdorff distance between this geometry and geom.
QString lastError() const SIP_HOLDGIL
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry convexHull() const
Returns the smallest convex polygon that contains all the points in the geometry.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
QgsGeometry minimalEnclosingCircle(QgsPointXY ¢er, double &radius, unsigned int segments=36) const
Returns the minimal enclosing circle for the geometry.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsGeometry symDifference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
double distanceToVertex(int vertex) const
Returns the distance along this geometry from its first vertex to the specified vertex.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
QgsGeometry singleSidedBuffer(double distance, int segments, BufferSide side, JoinStyle joinStyle=JoinStyleRound, double miterLimit=2.0) const
Returns a single sided buffer for a (multi)line geometry.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry createWedgeBuffer(const QgsPoint ¢er, double azimuth, double angularWidth, double outerRadius, double innerRadius=0)
Creates a wedge shaped buffer from a center point.
QgsGeometry extendLine(double startDistance, double endDistance) const
Extends a (multi)line geometry by extrapolating out the start or end of the line by a specified dista...
QgsGeometry offsetCurve(double distance, int segments, JoinStyle joinStyle, double miterLimit) const
Returns an offset line at a given distance and side from an input line.
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
double interpolateAngle(double distance) const
Returns the angle parallel to the linestring or polygon boundary at the specified distance along the ...
double angleAtVertex(int vertex) const
Returns the bisector angle for this geometry at the specified vertex.
QgsGeometry smooth(unsigned int iterations=1, double offset=0.25, double minimumDistance=-1.0, double maxAngle=180.0) const
Smooths a geometry by rounding off corners using the Chaikin algorithm.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
bool overlaps(const QgsGeometry &geometry) const
Returns true if the geometry overlaps another geometry.
QgsGeometry shortestLine(const QgsGeometry &other) const
Returns the shortest line joining this geometry to another geometry.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
Represents a color stop within a QgsGradientColorRamp color ramp.
A representation of the interval between two datetime values.
bool isValid() const
Returns true if the interval is valid.
double days() const
Returns the interval duration in days.
double weeks() const
Returns the interval duration in weeks.
double months() const
Returns the interval duration in months (based on a 30 day month).
double seconds() const
Returns the interval duration in seconds.
double years() const
Returns the interval duration in years (based on an average year length)
double hours() const
Returns the interval duration in hours.
double minutes() const
Returns the interval duration in minutes.
Line string geometry type, with support for z-dimension and m-values.
void setPoints(const QgsPointSequence &points)
Resets the line string to match the specified list of points.
QgsLineString * clone() const override
Clones the geometry by performing a deep copy.
Base class for all map layer types.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QgsCoordinateReferenceSystem crs
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsLayerMetadata metadata
QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
virtual bool isEditable() const
Returns true if the layer can be edited.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
double minimumScale() const
Returns the minimum map scale (i.e.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
double maximumScale() const
Returns the maximum map scale (i.e.
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
@ Visvalingam
The simplification gives each point in a line an importance weighting, so that least important points...
@ SimplifyGeometry
The geometries can be simplified using the current map2pixel context state.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Multi line string geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
Multi point geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
static QgsGeometry geometryFromGML(const QString &xmlString, const QgsOgcUtils::Context &context=QgsOgcUtils::Context())
Static method that creates geometry from GML.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const SIP_HOLDGIL
Returns a new point which corresponds to this point projected by a specified distance with specified ...
double inclination(const QgsPoint &other) const SIP_HOLDGIL
Calculates Cartesian inclination between this point and other one (starting from zenith = 0 to nadir ...
bool isValid(QString &error, int flags=0) const override SIP_HOLDGIL
Checks validity of the geometry, and returns true if the geometry is valid.
QgsRelationManager * relationManager
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QList< QgsMapLayer * > mapLayersByName(const QString &layerName) const
Retrieve a list of matching registered layers by layer name.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Quadrilateral geometry type.
static QgsQuadrilateral squareFromDiagonal(const QgsPoint &p1, const QgsPoint &p2) SIP_HOLDGIL
Construct a QgsQuadrilateral as a square from a diagonal.
QgsPolygon * toPolygon(bool force2D=false) const
Returns the quadrilateral as a new polygon.
ConstructionOption
A quadrilateral can be constructed from 3 points where the second distance can be determined by the t...
@ Distance
Second distance is equal to the distance between 2nd and 3rd point.
@ Projected
Second distance is equal to the distance of the perpendicualr projection of the 3rd point on the segm...
static QgsQuadrilateral rectangleFrom3Points(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode) SIP_HOLDGIL
Construct a QgsQuadrilateral as a Rectangle from 3 points.
The RasterBandStats struct is a container for statistics about a single raster band.
double mean
The mean cell value for the band. NO_DATA values are excluded.
double stdDev
The standard deviation of the cell values.
double minimumValue
The minimum cell value in the raster band.
double sum
The sum of all cells in the band. NO_DATA values are excluded.
double maximumValue
The maximum cell value in the raster band.
double range
The range is the distance between min & max.
virtual double sample(const QgsPointXY &point, int band, bool *ok=nullptr, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Samples a raster value from the specified band found at the point position.
virtual QgsRasterBandStats bandStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
Represents a raster layer.
int bandCount() const
Returns the number of bands in this layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void grow(double delta)
Grows the rectangle in place by the specified amount.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Regular Polygon geometry type.
ConstructionOption
A regular polygon can be constructed inscribed in a circle or circumscribed about a circle.
@ CircumscribedCircle
Circumscribed about a circle (the radius is the distance from the center to the midpoints of the side...
@ InscribedCircle
Inscribed in a circle (the radius is the distance between the center and vertices)
QgsPolygon * toPolygon() const
Returns as a polygon.
QList< QgsRelation > relationsByName(const QString &name) const
Returns a list of relations with matching names.
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
QgsVectorLayer * referencedLayer
QgsVectorLayer * referencingLayer
QString getRelatedFeaturesFilter(const QgsFeature &feature) const
Returns a filter expression which returns all the features on the referencing (child) layer which hav...
A spatial index for QgsFeature objects.
@ FlagStoreFeatureGeometries
Indicates that the spatial index should also store feature geometries. This requires more memory,...
QList< QgsFeatureId > nearestNeighbor(const QgsPointXY &point, int neighbors=1, double maxDistance=0) const
Returns nearest neighbors to a point.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
static QString quotedIdentifier(const QString &identifier)
Returns a properly quoted version of identifier.
static QString quotedValue(const QVariant &value)
Returns a properly quoted and escaped version of value for use in SQL strings.
c++ helper class for defining QgsExpression functions.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
void setIsStaticFunction(const std::function< bool(const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext *) > &isStatic)
Set a function that will be called in the prepare step to determine if the function is static or not.
QStringList aliases() const override
Returns a list of possible aliases for the function.
void setPrepareFunction(const std::function< bool(const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext *)> &prepareFunc)
Set a function that will be called in the prepare step to determine if the function is static or not.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
void setIsStatic(bool isStatic)
Tag this function as either static or not static.
QgsStaticExpressionFunction(const QString &fnname, int params, FcnEval fcn, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext, using an unnamed list of parameter val...
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
static int hammingDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Hamming distance between two strings.
static QString soundex(const QString &string)
Returns the Soundex representation of a string.
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings.
static QString longestCommonSubstring(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the longest common substring between two strings.
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string.
const QgsColorRamp * colorRampRef(const QString &name) const
Returns a const pointer to a symbol (doesn't create new instance)
static QgsStyle * defaultStyle()
Returns default application-wide style.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
static bool runOnMainThread(const Func &func, QgsFeedback *feedback=nullptr)
Guarantees that func is executed on the main thread.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
QString displayExpression
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters ¶meters=QgsAggregateCalculator::AggregateParameters(), QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeatureIds *fids=nullptr) const
Calculates an aggregated value from the layer's features.
Handles the with_variable(name, value, node) expression function.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
QgsWithVariableExpressionFunction()
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
QString errorMessage() const
Returns the most recent error message encountered by the database.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
int exec(const QString &sql, QString &errorMessage) const
Executes the sql command in the database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
qlonglong columnAsInt64(int column) const
Gets column value from the current statement row as a long long integer (64 bits).
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
CORE_EXPORT QString build(const QVariantMap &map)
Build a hstore-formatted string from a QVariantMap.
CORE_EXPORT QVariantMap parse(const QString &string)
Returns a QVariantMap object containing the key and values from a hstore-formatted string.
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 allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
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
uint qHash(const QVariant &variant)
Hash for QVariant.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QVector< QgsRingSequence > QgsCoordinateSequence
QVector< QgsPointSequence > QgsRingSequence
QVector< QgsPoint > QgsPointSequence
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
bool(QgsGeometry::* RelationFunction)(const QgsGeometry &geometry) const
QList< QgsExpressionFunction * > ExpressionFunctionList
#define ENSURE_GEOM_TYPE(f, g, geomtype)
QVariant fcnRampColor(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction *)
#define ENSURE_NO_EVAL_ERROR
#define FEAT_FROM_CONTEXT(c, f)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
A bundle of parameters controlling aggregate calculation.
QString filter
Optional filter for calculating aggregate over a subset of features, or an empty string to use all fe...
QString delimiter
Delimiter to use for joining values with the StringConcatenate aggregate.
QgsFeatureRequest::OrderBy orderBy
Optional order by clauses.
Single variable definition for use within a QgsExpressionContextScope.
The Context struct stores the current layer and coordinate transform context.
const QgsMapLayer * layer
QgsCoordinateTransformContext transformContext
Utility class for identifying a unique vertex within a geometry.