List of Functions - QGIS Documentation Documentation
List of Functions - QGIS Documentation Documentation
List of functions
The functions, operators and variables available in QGIS are listed below, grouped by categories.
• Aggregates Functions
• Array Functions
• Color Functions
• Conditional Functions
• Conversions Functions
• Custom Functions
• Date and Time Functions
• Fields and Values
• Files and Paths Functions
• Form Functions
• Fuzzy Matching Functions
• General Functions
• Geometry Functions
• Layout Functions
• Map Layers
• Maps Functions
• Mathematical Functions
• Meshes Functions
• Operators
• Processing Functions
• Rasters Functions
• Record and Attributes Functions
• Relations
• String Functions
• User Expressions
• Variables
• Recent Functions
• aggregate
• array_agg
• collect
• concatenate
• concatenate_unique
• count
• count_distinct
• count_missing
• iqr
• majority
• max_length
• maximum
• mean
• median
• min_length
• minimum
• minority
• q1
• q3
• range
• relation_aggregate
• stdev
• sum
2. 13.2.1.1. aggregate
• aggregate(layer:='rail_stations',aggregate:='sum',expression:="passengers") → sum
of all values from the passengers field in the rail_stations layer
• aggregate('rail_stations','sum', "passengers"/7) → calculates a daily average of
Examples “passengers” by dividing the “passengers” field by 7 before summing the values
• aggregate(layer:='rail_stations',aggregate:='sum',expression:="passengers",filter:=
"class">3) → sums up all values from the “passengers” field from features where the “class”
attribute is greater than 3 only
• aggregate(layer:='rail_stations',aggregate:='concatenate', expression:="name",
concatenator:=',') → comma separated list of the name field for all features in the rail_stations
layer
• aggregate(layer:='countries', aggregate:='max', expression:="code",
filter:=intersects( $geometry, geometry(@parent) ) ) → The country code of an
intersecting country on the layer ‘countries’
• aggregate(layer:='rail_stations',aggregate:='sum',expression:="passengers",filter:=
contains( @atlas_geometry, $geometry ) ) → sum of all values from the passengers field in
the rail_stations within the current atlas feature
• aggregate(layer:='rail_stations', aggregate:='collect',
expression:=centroid($geometry), filter:="region_name" = attribute(@parent,'name')
) → aggregates centroid geometries of the rail_stations of the same region as current feature
3. 13.2.1.2. array_agg
4. 13.2.1.3. collect
5. 13.2.1.4. concatenate
6. 13.2.1.5. concatenate_unique
• concatenate_unique("town_name",group_by:="state",concatenator:=',') → comma
Examples separated list of unique town_names, grouped by state field
7. 13.2.1.6. count
8. 13.2.1.7. count_distinct
9. 13.2.1.8. count_missing
Returns the aggregate majority of values (most commonly occurring value) from a field or expression.
Returns the aggregate minority of values (least occurring value) from a field or expression.
Returns the aggregate range of values (maximum - minimum) from a field or expression.
Returns an aggregate value calculated using all matching child features from a layer relation.
relation_aggregate(relation, aggregate, expression, [concatenator=’’], [order_by])
Syntax
[] marks optional arguments
• relation - a string, representing a relation ID
• aggregate - a string corresponding to the aggregate to calculate. Valid options are:
o count
o count_distinct
o count_missing
o min
o max
o sum
o mean
o median
o stdev
o stdevsample
o range
o minority
Argument o majority
s o q1: first quartile
o q3: third quartile
o iqr: inter quartile range
o min_length: minimum string length
o max_length: maximum string length
o concatenate: join strings with a concatenator
o concatenate_unique: join unique strings with a concatenator
o collect: create an aggregated multipart geometry
o array_agg: create an array of aggregated values
• expression - sub expression or field name to aggregate
• concatenator - optional string to use to join values for ‘concatenate’ aggregate
• order_by - optional expression to order the features used for calculating the aggregate. Fields and
geometry are from the features on the joined layer. By default, the features will be returned in an
unspecified order.
• relation_aggregate(relation:='my_relation',aggregate:='mean',expression:="passenger
s") → mean value of all matching child features using the ‘my_relation’ relation
• relation_aggregate('my_relation','sum', "passengers"/7) → sum of the passengers field
divided by 7 for all matching child features using the ‘my_relation’ relation
• relation_aggregate('my_relation','concatenate', "towns", concatenator:=',') →
Examples
comma separated list of the towns field for all matching child features using the ‘my_relation’
relation
• relation_aggregate('my_relation','array_agg', "id") → array of the id field from all
matching child features using the ‘my_relation’ relation
• array
• array_all
• array_append
• array_cat
• array_contains
• array_count
• array_distinct
• array_filter
• array_find
• array_first
• array_foreach
• array_get
• array_insert
• array_intersect
• array_last
• array_length
• array_majority
• array_max
• array_mean
• array_median
• array_min
• array_minority
• array_prepend
• array_prioritize
• array_remove_all
• array_remove_at
• array_replace
• array_reverse
• array_slice
• array_sort
• array_sum
• array_to_string
• generate_series
• geometries_to_array
• regexp_matches
• string_to_array
• array(2,10) → [ 2, 10 ]
Examples • array(2,10)[0] → 2
• array_all(array(1,2,3),array(2,3)) → TRUE
Examples • array_all(array(1,2,3),array(1,2,4)) → FALSE
• array_append(array(1,2,3),4) → [ 1, 2, 3, 4 ]
Examples
• array_cat(array(1,2),array(2,3)) → [ 1, 2, 2, 3 ]
Examples
• array_contains(array(1,2,3),2) → TRUE
Examples
Syntax array_distinct(array)
• array - an array
Arguments
• array_distinct(array(1,2,3,2,1)) → [ 1, 2, 3 ]
Examples
Returns an array with only the items for which the expression evaluates to true.
Returns the lowest index (0 for the first one) of a value within an array. Returns -1 if the value is not found.
Syntax array_first(array)
• array - an array
Arguments
• array_first(array('a','b','c')) → ‘a’
Examples
Returns the Nth value (0 for the first one) or the last -Nth value (-1 for the last one) of an array.
Hint
You can also use the index operator ([]) to get a value from an array.
Returns an array with the given value added at the given position.
• array_insert(array(1,2,3),1,100) → [ 1, 100, 2, 3 ]
Examples
• array_intersect(array(1,2,3,4),array(4,0,2,5)) → TRUE
Examples
Syntax array_last(array)
• array - an array
Arguments
• array_last(array('a','b','c')) → ‘c’
Examples
Syntax array_length(array)
• array - an array
Arguments
• array_length(array(1,2,3)) →3
Examples
42. 13.2.2.17. array_majority
array_majority(array, [option=’all’])
Syntax
[] marks optional arguments
• array - an array
• option=’all’ - a string specifying the return values handling. Valid options are:
o all: Default, all most common values are returned in an array.
Arguments o any: Returns one of the most common values.
o median: Returns the median of the most common values. Non arithmetic values are ignored.
o real_majority: Returns the value which occurs more than half the size of the array.
• array_majority(array(0,1,42,42,43), 'all') → [ 42 ]
• array_majority(array(0,1,42,42,43,1), 'all') → [ 42, 1 ]
• array_majority(array(0,1,42,42,43,1), 'any') → 1 or 42
• array_majority(array(0,1,1,2,2), 'median') → 1.5
Examples
• array_majority(array(0,1,42,42,43), 'real_majority') → NULL
• array_majority(array(0,1,42,42,43,42), 'real_majority') → NULL
• array_majority(array(0,1,42,42,43,42,42), 'real_majority') → 42
Syntax array_max(array)
• array - an array
Arguments
• array_max(array(0,42,4,2)) → 42
Examples
Returns the mean of arithmetic values in an array. Non numeric values in the array are ignored.
Syntax array_mean(array)
• array - an array
Arguments
• array_mean(array(0,1,7,66.6,135.4)) → 42
Examples • array_mean(array(0,84,'a','b','c')) → 42
Returns the median of arithmetic values in an array. Non arithmetic values in the array are ignored.
Syntax array_median(array)
• array - an array
Arguments
• array_median(array(0,1,42,42,43)) → 42
Examples • array_median(array(0,1,2,42,'a','b')) → 1.5
Syntax array_min(array)
• array - an array
Arguments
• array_min(array(43,42,54)) → 42
Examples
array_minority(array, [option=’all’])
Syntax
[] marks optional arguments
• array - an array
• option=’all’ - a string specifying the return values handling. Valid options are:
o all: Default, all less common values are returned in an array.
Arguments o any: Returns one of the less common values.
o median: Returns the median of the less common values. Non arithmetic values are ignored.
o real_minority: Returns values which occur less than half the size of the array.
• array_minority(array(0,42,42), 'all') → [ 0 ]
• array_minority(array(0,1,42,42), 'all') → [ 0, 1 ]
• array_minority(array(0,1,42,42,43,1), 'any') → 0 or 43
• array_minority(array(1,2,3,3), 'median') → 1.5
Examples
• array_minority(array(0,1,42,42,43), 'real_minority') → [ 42, 43, 0, 1 ]
• array_minority(array(0,1,42,42,43,42), 'real_minority') → [ 42, 43, 0, 1 ]
• array_minority(array(0,1,42,42,43,42,42), 'real_minority') → [ 43, 0, 1 ]
• array_prepend(array(1,2,3),0) → [ 0, 1, 2, 3 ]
Examples
49. 13.2.2.24. array_prioritize
Returns an array sorted using the ordering specified in another array. Values which are present in the first array but are
missing from the second array will be added to the end of the result.
Returns an array with all the entries of the given value removed.
Returns an array with the item at the given index removed. Supports positive (0 for the first element) and negative (the
last -Nth value, -1 for the last element) index.
Returns an array with the supplied value, array, or map of values replaced.
Returns an array with the supplied value or array of values replaced by another value or an array of values.
Map variant
Returns an array with the supplied map keys replaced by their paired values.
Syntax array_reverse(array)
• array - an array
Arguments
• array_reverse(array(2,4,0,10)) → [ 10, 0, 4, 2 ]
Examples
Returns a portion of the array. The slice is defined by the start_pos and end_pos arguments.
• array_slice(array(1,2,3,4,5),0,3) → [ 1, 2, 3, 4 ]
• array_slice(array(1,2,3,4,5),0,-1) → [ 1, 2, 3, 4, 5 ]
• array_slice(array(1,2,3,4,5),-5,-1) → [ 1, 2, 3, 4, 5 ]
• array_slice(array(1,2,3,4,5),0,0) → [ 1 ]
• array_slice(array(1,2,3,4,5),-2,-1) → [ 4, 5 ]
Examples • array_slice(array(1,2,3,4,5),-1,-1) → [ 5 ]
• array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),1,2) → [ ‘Valmiera’,
‘Chugiak’ ]
• array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),-2,-1) → [ ‘Chugiak’,
‘Brighton’ ]
55. 13.2.2.30. array_sort
array_sort(array, [ascending=true])
Syntax
[] marks optional arguments
• array - an array
Arguments • ascending - set this parameter to false to sort the array in descending order
• array_sort(array(3,2,1)) → [ 1, 2, 3 ]
Examples
Returns the sum of arithmetic values in an array. Non numeric values in the array are ignored.
Syntax array_sum(array)
• array - an array
Arguments
• array_sum(array(0,1,39.4,1.6,'a')) → 42.0
Examples
Concatenates array elements into a string separated by a delimiter and using optional string for empty values.
• array_to_string(array('1','2','3')) → ‘1,2,3’
• array_to_string(array(1,2,3),'-') → ‘1-2-3’
Examples
• array_to_string(array('1','','3'),',','0') → ‘1,0,3’
Syntax geometries_to_array(geometry)
• geometry - the input geometry
Arguments
Returns an array of all strings captured by capturing groups, in the order the groups themselves appear in the supplied
regular expression against a string.
Splits string into an array using supplied delimiter and optional string for empty values.
• color_cmyk
• color_cmyka
• color_grayscale_average
• color_hsl
• color_hsla
• color_hsv
• color_hsva
• color_mix_rgb
• color_part
• color_rgb
• color_rgba
• create_ramp
• darker
• lighter
• project_color
• ramp_color
• set_color_part
Returns a string representation of a color based on its cyan, magenta, yellow and black components
• color_cmyk(100,50,0,10) → ‘0,115,230’
Examples
Returns a string representation of a color based on its cyan, magenta, yellow, black and alpha (transparency) components
• color_cmyka(100,50,0,10,200) → ‘0,115,230,200’
Examples
Applies a grayscale filter and returns a string representation from a provided color.
Syntax color_grayscale_average(color)
• color - a color string
Arguments
• color_grayscale_average('255,100,50') → ‘135,135,135,255’
Examples
Returns a string representation of a color based on its hue, saturation, and lightness attributes.
• color_hsl(100,50,70) → ‘166,217,140’
Examples
Returns a string representation of a color based on its hue, saturation, lightness and alpha (transparency) attributes
• color_hsla(100,50,70,200) → ‘166,217,140,200’
Examples
Returns a string representation of a color based on its hue, saturation, and value attributes.
• color_hsv(40,100,100) → ‘255,170,0’
Examples
Returns a string representation of a color based on its hue, saturation, value and alpha (transparency) attributes.
• color_hsva(40,100,100,200) → ‘255,170,0,200’
Examples
Returns a string representing a color mixing the red, green, blue, and alpha values of two provided colors based on a given
ratio.
• color_mix_rgb('0,0,0','255,255,255',0.5) → ‘127,127,127,255’
Examples
Returns a specific component from a color string, e.g., the red component or alpha component.
• color_part('200,10,30','green') → 10
Examples
Returns a string representation of a color based on its red, green, and blue components.
• color_rgb(255,127,0) → ‘255,127,0’
Examples
Returns a string representation of a color based on its red, green, blue, and alpha (transparency) components.
• color_rgba(255,127,0,200) → ‘255,127,0,200’
Examples
create_ramp(map, [discrete=false])
Syntax
[] marks optional arguments
• map - a map of color strings and steps
Arguments • discrete - set this parameter to true to create a discrete color ramp
• ramp_color(create_ramp(map(0,'0,0,0',1,'255,0,0')),1) → ‘255,0,0,255’
Examples
Syntax project_color(name)
• name - a color name
Arguments
• ramp_color('Spectral',0.3) → ‘253,190,115,255’
Examples
Note
The color ramps available vary between QGIS installations. This function may not give the expected results if you move
your QGIS project between installations.
• ramp_color(create_ramp(map(0,'0,0,0',1,'255,0,0')),1) → ‘255,0,0,255’
Examples
Further reading: Setting a Color Ramp, The color ramp drop-down shortcut
Sets a specific color component for a color string, e.g., the red component or alpha component.
• set_color_part('200,10,30','green',50) → ‘200,50,30,255’
Examples
• CASE
• coalesce
• if
• nullif
• regexp_match
• try
CASE is used to evaluate a series of conditions and return a result for the first condition met. The conditions are evaluated
sequentially, and if a condition is true, the evaluation stops, and the corresponding result is returned. If none of the
conditions are true, the value in the ELSE clause is returned. Furthermore, if no ELSE clause is set and none of the
conditions are met, NULL is returned.
CASE
[ …n ]
[ ELSE result ]
END
• CASE WHEN "name" IS NULL THEN 'None' END → Returns the string ‘None’ if the “name” field is
NULL
• CASE WHEN $area > 10000 THEN 'Big property' WHEN $area > 5000 THEN 'Medium
Examples property' ELSE 'Small property' END → Returns the string ‘Big property’ if the area is bigger
than 10000, ‘Medium property’ if the area is between 5000 and 10000, and ‘Small property’ for
others
• coalesce(NULL, 2) → 2
• coalesce(NULL, 2, 3) → 2
• coalesce(7, NULL, 3*2) → 7
Examples
• coalesce("fieldA", "fallbackField", 'ERROR') → value of fieldA if it is non-NULL else the
value of “fallbackField” or the string ‘ERROR’ if both are NULL
Tests a condition and returns a different result depending on the conditional check.
Returns a NULL value if value1 equals value2; otherwise it returns value1. This can be used to conditionally substitute
values with NULL.
Return the first matching position matching a regular expression within an unicode string, or 0 if the substring is not
found.
• regexp_match('QGIS ROCKS','\\sROCKS') →5
Examples • regexp_match('Budač','udač\\b') → 2
Tries an expression and returns its value if error-free. If the expression returns an error, an alternative value will be
returned when provided otherwise the function will return NULL.
try(expression, [alternative])
Syntax
[] marks optional arguments
Arguments • expression - the expression which should be run
• alternative - the result which will be returned if the expression returns an error.
• from_base64
• hash
• md5
• sha256
• to_base64
• to_date
• to_datetime
• to_decimal
• to_dm
• to_dms
• to_int
• to_interval
• to_real
• to_string
• to_time
Syntax from_base64(string)
• string - the string to decode
Arguments
• from_base64('UUdJUw==') → ‘QGIS’
Examples
Creates a hash from a string with a given method. One byte (8 bits) is represented with two hex ‘’digits’’, so ‘md4’ (16
bytes) produces a 16 * 2 = 32 character long hex string and ‘keccak_512’ (64 bytes) produces a 64 * 2 = 128 character
long hex string.
Syntax md5(string)
• string - the string to hash
Arguments
• md5('QGIS') → ‘57470aaa9e22adaefac7f5f342f1c6da’
Examples
Syntax sha256(string)
• string - the string to hash
Arguments
• sha256('QGIS') → ‘eb045cba7a797aaa06ac58830846e40c8e8c780bc0676d3393605fae50c05309’
Examples
Syntax to_base64(value)
• value - the binary value to encode
Arguments
• to_base64('QGIS') → ‘UUdJUw==’
Examples
Converts a string into a date object. An optional format string can be provided to parse the string; see QDate::fromString
or the documentation of the format_date function for additional documentation on the format. By default the current QGIS
user locale is used.
• to_date('2012-05-04') → 2012-05-04
• to_date('June 29, 2019','MMMM d, yyyy') → 2019-06-29, if the current locale uses the name
Examples ‘June’ for the sixth month, otherwise an error occurs
• to_date('29 juin, 2019','d MMMM, yyyy','fr') → 2019-06-29
Converts a string into a datetime object. An optional format string can be provided to parse the string; see
QDate::fromString, QTime::fromString or the documentation of the format_date function for additional documentation on
the format. By default the current QGIS user locale is used.
Syntax to_decimal(value)
• value - A degree, minute, second string.
Arguments
• to_decimal('6°21\'16.445') → 6.3545680555
Examples
Converts a string to integer number. Nothing is returned if a value cannot be converted to integer (e.g ‘123asd’ is invalid).
Syntax to_int(string)
• string - string to convert to integer number
Arguments
• to_int('123') → 123
Examples
99. 13.2.5.12. to_interval
Converts a string to an interval type. Can be used to take days, hours, month, etc of a date.
Syntax to_interval(string)
• string - a string representing an interval. Allowable formats include {n} days {n} hours {n} months.
Arguments
Converts a string to a real number. Nothing is returned if a value cannot be converted to real (e.g ‘123.56asd’ is invalid).
Numbers are rounded after saving changes if the precision is smaller than the result of the conversion.
Syntax to_real(string)
• string - string to convert to real number
Arguments
• to_real('123.45') → 123.45
Examples
Syntax to_string(number)
• number - Integer or real value. The number to convert to string.
Arguments
• to_string(123) → ‘123’
Examples
Converts a string into a time object. An optional format string can be provided to parse the string; see QTime::fromString
for additional documentation on the format.
• to_time('12:30:01') → 12:30:01
Examples
• to_time('12:34','HH:mm') → 12:34:00
• to_time('12:34','HH:mm','fr') → 12:34:00
Note
The ability to store date, time and datetime values directly on fields depends on the data source’s provider (e.g., Shapefile
accepts date format, but not datetime or time format). The following are some suggestions to overcome this limitation:
• date, datetime and time can be converted and stored in text type fields using the format_date() function.
• Intervals can be stored in integer or decimal type fields after using one of the date extraction functions (e.g., day()
to get the interval expressed in days)
• age
• datetime_from_epoch
• day
• day_of_week
• epoch
• format_date
• hour
• make_date
• make_datetime
• make_interval
• make_time
• minute
• month
• now
• second
• to_date
• to_datetime
• to_interval
• to_time
• week
• year
The difference is returned as an Interval and needs to be used with one of the following functions in order to extract
useful information:
• year
• month
• week
• day
• hour
• minute
• second
• day(age('2012-05-12','2012-05-02')) → 10
Examples • hour(age('2012-05-12','2012-05-02')) → 240
Returns a datetime whose date and time are the number of milliseconds, msecs, that have passed since 1970-01-
01T00:00:00.000, Coordinated Universal Time (Qt.UTC), and converted to Qt.LocalTime.
Syntax datetime_from_epoch(int)
• int - number (milliseconds)
Arguments
• datetime_from_epoch(1483225200000) → 2017-01-01T00:00:00
Examples
Extracts the day from a date, or the number of days from an interval.
Date variant
Syntax day(date)
• date - a date or datetime value
Arguments
• day('2012-05-12') → 12
Examples
Interval variant
Syntax day(interval)
• interval - interval value to return number of days from
Arguments
• day(to_interval('3 days')) → 3
Examples
• day(to_interval('3 weeks 2 days')) → 23
• day(age('2012-01-01','2010-01-01')) → 730
Returns the day of the week for a specified date or datetime. The returned value ranges from 0 to 6, where 0 corresponds
to a Sunday and 6 to a Saturday.
Syntax day_of_week(date)
• date - date or datetime value
Arguments
• day_of_week(to_date('2015-09-21')) →1
Examples
Returns the interval in milliseconds between the unix epoch and a given date value.
Syntax epoch(date)
• date - a date or datetime value
Arguments
• epoch(to_date('2017-01-01')) → 1483203600000
Examples
Formats a date type or string into a custom string format. Uses Qt date/time format strings. See QDateTime::toString.
Expression Output
d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. ‘Mon’ to ‘Sun’)
dddd the long localized day name (e.g. ‘Monday’ to ‘Sunday’)
Arguments M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. ‘Jan’ to ‘Dec’)
MMMM the long localized month name (e.g. ‘January’ to ‘December’)
yy the year as two digit number (00-99)
yyyy the year as four digit number
• These expressions may be used for the time part of the format string:
Expression Output
h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H the hour without a leading zero (0 to 23, even with AM/PM display)
HH the hour with a leading zero (00 to 23, even with AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without trailing zeroes (0 to 999)
zzz the milliseconds with trailing zeroes (000 to 999)
AP or A interpret as an AM/PM time. AP must be either ‘AM’ or ‘PM’.
ap or a Interpret as an AM/PM time. ap must be either ‘am’ or ‘pm’.
• language - language (lowercase, two- or three-letter, ISO 639 language code) used to format the date
into a custom string. By default the current QGIS user locale is used.
• format_date('2012-05-15','dd.MM.yyyy') → ‘15.05.2012’
• format_date('2012-05-15','d MMMM yyyy','fr') → ‘15 mai 2012’
• format_date('2012-05-15','dddd') → ‘Tuesday’, if the current locale is an English variant
Examples
• format_date('2012-05-15 13:54:20','dd.MM.yy') → ‘15.05.12’
• format_date('13:54:20','hh:mm AP') → ‘01:54 PM’
Extracts the hour part from a datetime or time, or the number of hours from an interval.
Time variant
Syntax hour(datetime)
• datetime - a time or datetime value
Arguments
Interval variant
Syntax hour(interval)
• interval - interval value to return number of hours from
Arguments
• hour(to_interval('3 hours')) → 3
• hour(age('2012-07-22T13:00:00','2012-07-22T10:00:00')) →3
Examples
• hour(age('2012-01-01','2010-01-01')) → 17520
112. 13.2.7.8. make_date
Creates a datetime value from year, month, day, hour, minute and second numbers.
Creates an interval value from year, month, weeks, days, hours, minute and seconds values.
Extracts the minutes part from a datetime or time, or the number of minutes from an interval.
Time variant
Syntax minute(datetime)
• datetime - a time or datetime value
Arguments
Interval variant
Syntax minute(interval)
• interval - interval value to return number of minutes from
Arguments
• minute(to_interval('3 minutes')) → 3
• minute(age('2012-07-22T00:20:00','2012-07-22T00:00:00')) → 20
Examples
• minute(age('2012-01-01','2010-01-01')) → 1051200
Extracts the month part from a date, or the number of months from an interval.
Date variant
Syntax month(date)
• date - a date or datetime value
Arguments
• month('2012-05-12') → 05
Examples
Interval variant
Calculates the length in months of an interval.
Syntax month(interval)
• interval - interval value to return number of months from
Arguments
• month(to_interval('3 months')) → 3
Examples • month(age('2012-01-01','2010-01-01')) → 4.03333
Returns the current date and time. The function is static and will return consistent results while evaluating. The time
returned is the time when the expression is prepared.
Syntax now()
• now() → 2012-07-22T13:24:57
Examples
Extracts the seconds part from a datetime or time, or the number of seconds from an interval.
Time variant
Syntax second(datetime)
• datetime - a time or datetime value
Arguments
Interval variant
Syntax second(interval)
• interval - interval value to return number of seconds from
Arguments
Converts a string into a date object. An optional format string can be provided to parse the string; see QDate::fromString
or the documentation of the format_date function for additional documentation on the format. By default the current QGIS
user locale is used.
to_date(string, [format], [language])
Syntax
[] marks optional arguments
• string - string representing a date value
• format - format used to convert the string into a date
Arguments • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the
string into a date. By default the current QGIS user locale is used.
• to_date('2012-05-04') → 2012-05-04
• to_date('June 29, 2019','MMMM d, yyyy') → 2019-06-29, if the current locale uses the name
Examples ‘June’ for the sixth month, otherwise an error occurs
• to_date('29 juin, 2019','d MMMM, yyyy','fr') → 2019-06-29
Converts a string into a datetime object. An optional format string can be provided to parse the string; see
QDate::fromString, QTime::fromString or the documentation of the format_date function for additional documentation on
the format. By default the current QGIS user locale is used.
Converts a string to an interval type. Can be used to take days, hours, month, etc of a date.
Syntax to_interval(string)
• string - a string representing an interval. Allowable formats include {n} days {n} hours {n} months.
Arguments
Converts a string into a time object. An optional format string can be provided to parse the string; see QTime::fromString
for additional documentation on the format.
to_time(string, [format], [language])
Syntax
[] marks optional arguments
• string - string representing a time value
• format - format used to convert the string into a time
Arguments • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the
string into a time
• to_time('12:30:01') → 12:30:01
• to_time('12:34','HH:mm') → 12:34:00
Examples
• to_time('12:34','HH:mm','fr') → 12:34:00
Extracts the week number from a date, or the number of weeks from an interval.
Date variant
Syntax week(date)
• date - a date or datetime value
Arguments
• week('2012-05-12') → 19
Examples
Interval variant
Syntax week(interval)
• interval - interval value to return number of months from
Arguments
• week(to_interval('3 weeks')) → 3
Examples • week(age('2012-01-01','2010-01-01')) → 104.285
Extracts the year part from a date, or the number of years from an interval.
Date variant
Syntax year(date)
• date - a date or datetime value
Arguments
• year('2012-05-12') → 2012
Examples
Interval variant
Syntax year(interval)
• interval - interval value to return number of years from
Arguments
• year(to_interval('3 years')) → 3
Examples • year(age('2012-01-01','2010-01-01')) → 1.9986
Some examples:
Besides these functions, subtracting dates, datetimes or times using the - (minus) operator will return an interval.
Adding or subtracting an interval to dates, datetimes or times, using the + (plus) and - (minus) operators, will return a
datetime.
Double-click a field name to have it added to your expression. You can also type the field name (preferably inside double
quotes) or its alias.
To retrieve fields values to use in an expression, select the appropriate field and, in the shown widget, choose between 10
Samples and All Unique. Requested values are then displayed and you can use the Search box at the top of the list to filter
the result. Sample values can also be accessed via right-clicking on a field.
To add a value to the expression you are writing, double-click on it in the list. If the value is of a string type, it should be
simple quoted, otherwise no quote is needed.
• NULL
127. 13.2.8.1. NULL
Syntax NULL
• NULL → a NULL value
Examples
Note
• base_file_name
• exif
• file_exists
• file_name
• file_path
• file_size
• file_suffix
• is_directory
• is_file
Returns the base name of the file without the directory or file suffix.
Syntax base_file_name(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• base_file_name('/home/qgis/data/country_boundaries.shp') → ‘country_boundaries’
Examples
exif(path, [tag])
Syntax
[] marks optional arguments
• path - An image file path or a map layer value. If a map layer value is specified then the file source
of the layer will be used.
Arguments
• tag - The tag to return. If empty, a map with all exif tag values will be returned.
• exif('/my/photo.jpg','Exif.Image.Orientation') →0
Examples
131. 13.2.9.3. file_exists
Syntax file_exists(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• file_exists('/home/qgis/data/country_boundaries.shp') → TRUE
Examples
Returns the name of a file (including the file extension), excluding the directory.
Syntax file_name(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• file_name('/home/qgis/data/country_boundaries.shp') → ‘country_boundaries.shp’
Examples
Returns the directory component of a file path. This does not include the file name.
Syntax file_path(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• file_path('/home/qgis/data/country_boundaries.shp') → ‘/home/qgis/data’
Examples
Syntax file_size(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• file_size('/home/qgis/data/country_boundaries.geojson') → 5674
Examples
Syntax file_suffix(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• file_suffix('/home/qgis/data/country_boundaries.shp') → ‘shp’
Examples
Syntax is_directory(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• is_directory('/home/qgis/data/country_boundaries.shp') → FALSE
Examples • is_directory('/home/qgis/data/') → TRUE
Syntax is_file(path)
• path - a file path or a map layer value. If a map layer value is specified then the file source of the
Arguments layer will be used.
• is_file('/home/qgis/data/country_boundaries.shp') → TRUE
Examples • is_file('/home/qgis/data/') → FALSE
• current_parent_value
• current_value
Only usable in an embedded form context, this function returns the current, unsaved value of a field in the parent form
currently being edited. This will differ from the parent feature’s actual attribute values for features which are currently
being edited or have not yet been added to a parent layer. When used in a value-relation widget filter expression, this
function should be wrapped into a ‘coalesce()’ that can retrieve the actual parent feature from the layer when the form is
not used in an embedded context.
Syntax current_parent_value(field_name)
• field_name - a field name in the current parent form
Arguments
• current_parent_value( 'FIELD_NAME' ) → The current value of a field ‘FIELD_NAME’ in the
Examples parent form.
Returns the current, unsaved value of a field in the form or table row currently being edited. This will differ from the
feature’s actual attribute values for features which are currently being edited or have not yet been added to a layer.
Syntax current_value(field_name)
• field_name - a field name in the current form or table row
Arguments
• hamming_distance
• levenshtein
• longest_common_substring
• soundex
Returns the Hamming distance between two strings. This equates to the number of characters at corresponding positions
within the input strings where the characters are different. The input strings must be the same length, and the comparison
is case-sensitive.
• hamming_distance('abc','xec') → 2
• hamming_distance('abc','ABc') → 2
Examples • hamming_distance(upper('abc'),upper('ABC')) →0
• hamming_distance('abc','abcd') → NULL
Returns the Levenshtein edit distance between two strings. This equates to the minimum number of character edits
(insertions, deletions or substitutions) required to change one string to another.
The Levenshtein distance is a measure of the similarity between two strings. Smaller distances mean the strings are more
similar, and larger distances indicate more different strings. The distance is case sensitive.
• levenshtein('kittens','mitten') → 2
• levenshtein('Kitten','kitten') → 1
Examples
• levenshtein(upper('Kitten'),upper('kitten')) →0
Returns the longest common substring between two strings. This substring is the longest string that is a substring of the
two input strings. For example, the longest common substring of “ABABC” and “BABCA” is “BABC”. The substring is
case sensitive.
• longest_common_substring('ABABC','BABCA') → ‘BABC’
• longest_common_substring('abcDeF','abcdef') → ‘abc’
Examples
• longest_common_substring(upper('abcDeF'),upper('abcdex')) → ‘ABCDE’
Returns the Soundex representation of a string. Soundex is a phonetic matching algorithm, so strings with similar sounds
should be represented by the same Soundex code.
Syntax soundex(string)
• string - a string
Arguments
• soundex('robert') → ‘R163’
• soundex('rupert') → ‘R163’
Examples
• soundex('rubin') → ‘R150’
• env
• eval
• eval_template
• is_layer_visible
• mime_type
• var
• with_variable
Gets an environment variable and returns its content as a string. If the variable is not found, NULL will be returned. This
is handy to inject system specific configuration like drive letters or path prefixes. Definition of environment variables
depends on the operating system, please check with your system administrator or the operating system documentation
how this can be set.
Syntax env(name)
• name - The name of the environment variable which should be retrieved.
Arguments
Evaluates an expression which is passed in a string. Useful to expand dynamic parameters passed as context variables or
fields.
Syntax eval(expression)
• expression - an expression string
Arguments
• eval('\'nice\'') → ‘nice’
Examples • eval(@expression_var) → [whatever the result of evaluating @expression_var might be…]
Evaluates a template which is passed in a string. Useful to expand dynamic parameters passed as context variables or
fields.
Syntax eval_template(template)
• template - a template string
Arguments
Syntax is_layer_visible(layer)
• layer - a string, representing either a layer name or layer ID
Arguments
• is_layer_visible('baseraster') → TRUE
Examples
Syntax mime_type(bytes)
• bytes - the binary data
Arguments
• mime_type('<html><body></body></html>') → text/html
• mime_type(from_base64('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAIAOw==')) →
Examples
image/gif
Syntax var(name)
• name - a variable name
Arguments
• var('qgis_version') → ‘2.12’
Examples
This function sets a variable for any expression code that will be provided as 3rd argument. This is only useful for
complicated expressions, where the same calculated value needs to be used in different places.
• affine_transform
• angle_at_vertex
• apply_dash_pattern
• $area
• area
• azimuth
• boundary
• bounds
• bounds_height
• bounds_width
• buffer
• buffer_by_m
• centroid
• close_line
• closest_point
• collect_geometries
• combine
• concave_hull
• contains
• convex_hull
• crosses
• densify_by_count
• densify_by_distance
• difference
• disjoint
• distance
• distance_to_vertex
• end_point
• exif_geotag
• extend
• exterior_ring
• extrude
• flip_coordinates
• force_polygon_ccw
• force_polygon_cw
• force_rhr
• geom_from_gml
• geom_from_wkb
• geom_from_wkt
• geom_to_wkb
• geom_to_wkt
• $geometry
• geometry
• geometry_n
• geometry_type
• hausdorff_distance
• inclination
• interior_ring_n
• intersection
• intersects
• intersects_bbox
• is_closed
• is_empty
• is_empty_or_null
• is_multipart
• is_valid
• $length
• length
• length3D
• line_interpolate_angle
• line_interpolate_point
• line_locate_point
• line_merge
• line_substring
• m
• m_max
• m_min
• main_angle
• make_circle
• make_ellipse
• make_line
• make_point
• make_point_m
• make_polygon
• make_rectangle_3points
• make_regular_polygon
• make_square
• make_triangle
• make_valid
• minimal_circle
• nodes_to_points
• num_geometries
• num_interior_rings
• num_points
• num_rings
• offset_curve
• order_parts
• oriented_bbox
• overlaps
• overlay_contains
• overlay_crosses
• overlay_disjoint
• overlay_equals
• overlay_intersects
• overlay_nearest
• overlay_touches
• overlay_within
• $perimeter
• perimeter
• point_n
• point_on_surface
• pole_of_inaccessibility
• project
• relate
• reverse
• rotate
• roundness
• scale
• segments_to_lines
• shared_paths
• shortest_line
• simplify
• simplify_vw
• single_sided_buffer
• sinuosity
• smooth
• square_wave
• square_wave_randomized
• start_point
• straight_distance_2d
• sym_difference
• tapered_buffer
• touches
• transform
• translate
• triangular_wave
• triangular_wave_randomized
• union
• wave
• wave_randomized
• wedge_buffer
• within
• $x
• x
• $x_at
• x_max
• x_min
• $y
• y
• $y_at
• y_max
• y_min
• $z
• z
• z_max
• z_min
Returns the geometry after an affine transformation. Calculations are in the Spatial Reference System of this geometry.
The operations are performed in a scale, rotation, translation order. If there is a Z or M offset but the coordinate is not
present in the geometry, it will be added.
• geom_to_wkt(affine_transform(geom_from_wkt('LINESTRING(1 1, 2 2)'), 2, 2, 0, 1,
1)) → ‘LineString (3 3, 4 4)’
• geom_to_wkt(affine_transform(geom_from_wkt('POLYGON((0 0, 0 3, 2 2, 0 0))'), 0, 0,
Examples -90, 1, 2)) → ‘Polygon ((0 0, 6 0, 4 -2, 0 0))’
• geom_to_wkt(affine_transform(geom_from_wkt('POINT(3 1)'), 0, 0, 0, 1, 1, 5, 0)) →
‘PointZ (3 1 5)’
Returns the bisector angle (average angle) to the geometry for a specified vertex on a linestring geometry. Angles are in
degrees clockwise from north.
Syntax angle_at_vertex(geometry, vertex)
• geometry - a linestring geometry
• vertex - vertex index, starting from 0; if the value is negative, the selected vertex index will be its
Arguments
total count minus the absolute value
• angle_at_vertex(geometry:=geom_from_wkt('LineString(0 0, 10 0, 10 10)'),vertex:=1)
Examples → 45.0
Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the input geometry stroked along
each line/ring with the specified pattern.
Returns the area of the current feature. The area calculated by this function respects both the current project’s ellipsoid
setting and area unit settings. For example, if an ellipsoid has been set for the project then the calculated area will be
ellipsoidal, and if no ellipsoid is set then the calculated area will be planimetric.
Syntax $area
• $area → 42
Examples
Returns the area of a geometry polygon object. Calculations are always planimetric in the Spatial Reference System (SRS)
of this geometry, and the units of the returned area will match the units for the SRS. This differs from the calculations
performed by the $area function, which will perform ellipsoidal calculations based on the project’s ellipsoid and area unit
settings.
Syntax area(geometry)
• geometry - polygon geometry object
Arguments
Returns the north-based azimuth as the angle in radians measured clockwise from the vertical on point_a to point_b.
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry). For
instance, a polygon geometry will have a boundary consisting of the linestrings for each ring in the polygon. Some
geometry types do not have a defined boundary, e.g., points or geometry collections, and will return NULL.
Syntax boundary(geometry)
• geometry - a geometry
Arguments
• geom_to_wkt(boundary(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))'))) →
‘LineString(1 1,0 0,-1 1,1 1)’
Examples • geom_to_wkt(boundary(geom_from_wkt('LineString(1 1,0 0,-1 1)'))) → ‘MultiPoint ((1
1),(-1 1))’
Returns a geometry which represents the bounding box of an input geometry. Calculations are in the Spatial Reference
System of this geometry.
Syntax bounds(geometry)
• geometry - a geometry
Arguments
Returns the height of the bounding box of a geometry. Calculations are in the Spatial Reference System of this geometry.
Syntax bounds_height(geometry)
• geometry - a geometry
Arguments
Returns the width of the bounding box of a geometry. Calculations are in the Spatial Reference System of this geometry.
Syntax bounds_width(geometry)
• geometry - a geometry
Arguments
Returns a geometry that represents all points whose distance from this geometry is less than or equal to distance.
Calculations are in the Spatial Reference System of this geometry.
• buffer($geometry, 10.5) → polygon of the current feature’s geometry buffered by 10.5 units
Examples
Fig. 13.5 Buffer (in yellow) of points, line, polygon with positive buffer, and polygon with negative buffer
Creates a buffer along a line geometry where the buffer diameter varies according to the m-values at the line vertices.
buffer_by_m(geometry, [segments=8])
Syntax
[] marks optional arguments
• geometry - input geometry. Must be a (multi)line geometry with m values.
Arguments • segments - number of segments to approximate quarter-circle curves in the buffer.
• buffer_by_m(geometry:=geom_from_wkt('LINESTRINGM(1 2 0.5, 4 2 0.2)'),segments:=8)
→ A variable width buffer starting with a diameter of 0.5 and ending with a diameter of 0.2 along the
Examples
linestring geometry.
Fig. 13.6 Buffering line features using the m value on the vertices
Syntax centroid(geometry)
• geometry - a geometry
Arguments
Returns a closed line string of the input line string by appending the first point to the end of the line, if it is not already
closed. If the geometry is not a line string or multi line string then the result will be NULL.
Syntax close_line(geometry)
• geometry - a line string geometry
Arguments
Array variant
Syntax collect_geometries(array)
• array - array of geometry objects
Arguments
• geom_to_wkt(collect_geometries(array(make_point(1,2), make_point(3,4),
Examples make_point(5,6)))) → ‘MultiPoint ((1 2),(3 4),(5 6))’
Returns a possibly concave polygon that contains all the points in the geometry
Tests whether a geometry contains another. Returns TRUE if and only if no points of geometry2 lie in the exterior of
geometry1, and at least one point of the interior of geometry2 lies in the interior of geometry1.
Returns the convex hull of a geometry. It represents the minimum convex geometry that encloses all geometries within the
set.
Syntax convex_hull(geometry)
• geometry - a geometry
Arguments
Tests whether a geometry crosses another. Returns TRUE if the supplied geometries have some, but not all, interior points
in common.
Takes a polygon or line layer geometry and generates a new one in which the geometries have a larger number of vertices
than the original one.
Returns a geometry that represents that part of geometry1 that does not intersect with geometry2.
Tests whether geometries do not spatially intersect. Returns TRUE if the geometries do not share any space together.
Returns the minimum distance (based on spatial reference) between two geometries in projected units.
• distance_to_vertex(geometry:=geom_from_wkt('LineString(0 0, 10 0, 10
Examples 10)'),vertex:=1) → 10.0
Syntax end_point(geometry)
• geometry - geometry object
Arguments
Syntax exif_geotag(path)
• path - An image file path or a map layer value. If a map layer value is specified then the file source
Arguments of the layer will be used.
Extends the start and end of a linestring geometry by a specified amount. Lines are extended using the bearing of the first
and last segment in the line. For a multilinestring, all the parts are extended. Distances are in the Spatial Reference System
of this geometry.
Returns a line string representing the exterior ring of a polygon geometry. If the geometry is not a polygon then the result
will be NULL.
Syntax exterior_ring(geometry)
• geometry - a polygon geometry
Arguments
Returns an extruded version of the input (Multi-)Curve or (Multi-)Linestring geometry with an extension specified by x
and y.
Syntax extrude(geometry, x, y)
• geometry - a curve or linestring geometry
• x - x extension, numeric value
Arguments
• y - y extension, numeric value
Returns a copy of the geometry with the x and y coordinates swapped. Useful for repairing geometries which have had
their latitude and longitude values reversed.
Syntax flip_coordinates(geometry)
• geometry - a geometry
Arguments
Forces a geometry to respect the convention where exterior rings are counter-clockwise, interior rings are clockwise.
Syntax force_polygon_ccw(geometry)
• geometry - a geometry. Any non-polygon geometries are returned unchanged.
Arguments
Forces a geometry to respect the convention where exterior rings are clockwise, interior rings are counter-clockwise.
Syntax force_polygon_cw(geometry)
• geometry - a geometry. Any non-polygon geometries are returned unchanged.
Arguments
• geom_to_wkt(force_polygon_cw(geometry:=geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0
Examples 2, -1 -1))'))) → ‘Polygon ((-1 -1, 0 2, 4 2, 4 0, -1 -1))’
Forces a geometry to respect the Right-Hand-Rule, in which the area that is bounded by a polygon is to the right of the
boundary. In particular, the exterior ring is oriented in a clockwise direction and the interior rings in a counter-clockwise
direction. Due to the inconsistency in the definition of the Right-Hand-Rule in some contexts it is recommended to use the
explicit force_polygon_cw function instead.
Syntax force_rhr(geometry)
• geometry - a geometry. Any non-polygon geometries are returned unchanged.
Arguments
• geom_to_wkt(force_rhr(geometry:=geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -
Examples 1))'))) → ‘Polygon ((-1 -1, 0 2, 4 2, 4 0, -1 -1))’
Syntax geom_from_gml(gml)
• gml - GML representation of a geometry as a string
Arguments
• geom_from_gml('<gml:LineString srsName="EPSG:4326"><gml:coordinates>4,4 5,5
Examples 6,6</gml:coordinates></gml:LineString>') → a line geometry object
Syntax geom_from_wkb(binary)
• binary - Well-Known Binary (WKB) representation of a geometry (as a binary blob)
Arguments
Syntax geom_from_wkt(text)
• text - Well-Known Text (WKT) representation of a geometry
Arguments
Syntax geom_to_wkb(geometry)
• geometry - a geometry
Arguments
Returns the Well-Known Text (WKT) representation of the geometry without SRID metadata.
geom_to_wkt(geometry, [precision=8])
Syntax
[] marks optional arguments
• geometry - a geometry
Arguments • precision - numeric precision
Returns the geometry of the current feature. Can be used for processing with other functions. WARNING: This function
is deprecated. It is recommended to use the replacement @geometry variable instead.
Syntax $geometry
• geom_to_wkt( $geometry ) → ‘POINT(6 50)’
Examples
Syntax geometry(feature)
• feature - a feature object
Arguments
• `` geometry( $currentfeature )`` → the geometry of the current feature. Prefer using $geometry.
• geom_to_wkt( geometry( get_feature_by_id( 'streets', 1 ) ) ) → the geometry in WKT
of the feature with the id 1 on the layer “streets”, e.g. ‘POINT(6 50)’
Examples
• intersects( $geometry, geometry( get_feature( 'streets', 'name', 'Main St.' ) ) )
→ TRUE if the current feature spatially intersects the ‘Main St.’ named feature in the “streets” layer
Returns a specific geometry from a geometry collection, or NULL if the input geometry is not a collection. Also returns a
part from a multipart geometry.
Returns a string value describing the type of a geometry (Point, Line or Polygon)
Syntax geometry_type(geometry)
• geometry - a geometry
Arguments
Returns the Hausdorff distance between two geometries. This is basically a measure of how similar or dissimilar 2
geometries are, with a lower distance indicating more similar geometries.
The function can be executed with an optional densify fraction argument. If not specified, an approximation to the
standard Hausdorff distance is used. This approximation is exact or close enough for a large subset of useful cases.
Examples of these are:
• computing distance between Linestrings that are roughly parallel to each other, and roughly equal in length. This
occurs in matching linear networks.
• Testing similarity of geometries.
If the default approximate provided by this method is insufficient, specify the optional densify fraction argument.
Specifying this argument performs a segment densification before computing the discrete Hausdorff distance. The
parameter sets the fraction by which to densify each segment. Each segment will be split into a number of equal-length
subsegments, whose fraction of the total length is closest to the given fraction. Decreasing the densify fraction parameter
will make the distance returned approach the true Hausdorff distance for the geometries.
Returns the inclination measured from the zenith (0) to the nadir (180) on point_a to point_b.
Returns a specific interior ring from a polygon geometry, or NULL if the geometry is not a polygon.
• geom_to_wkt(interior_ring_n(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -
1),(-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1),(-1 -1, 4 0, 4 2, 0 2, -1 -
Examples 1))'),1)) → ‘LineString (-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1))’
Tests whether a geometry intersects another. Returns TRUE if the geometries spatially intersect (share any portion of
space) and false if they do not.
Tests whether a geometry’s bounding box overlaps another geometry’s bounding box. Returns TRUE if the geometries
spatially intersect the bounding box defined and false if they do not.
Syntax intersects_bbox(geometry1, geometry2)
• geometry1 - a geometry
Arguments • geometry2 - a geometry
Returns TRUE if a line string is closed (start and end points are coincident), or false if a line string is not closed. If the
geometry is not a line string then the result will be NULL.
Syntax is_closed(geometry)
• geometry - a line string geometry
Arguments
Returns TRUE if a geometry is empty (without coordinates), false if the geometry is not empty and NULL if there is no
geometry. See also is_empty_or_null.
Syntax is_empty(geometry)
• geometry - a geometry
Arguments
Returns TRUE if a geometry is NULL or empty (without coordinates) or false otherwise. This function is like the
expression ‘$geometry IS NULL or is_empty($geometry)’
Syntax is_empty_or_null(geometry)
• geometry - a geometry
Arguments
• is_empty_or_null(NULL) → TRUE
• is_empty_or_null(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')) → FALSE
Examples
• is_empty_or_null(geom_from_wkt('LINESTRING EMPTY')) → TRUE
• is_empty_or_null(geom_from_wkt('POINT(7 4)')) → FALSE
• is_empty_or_null(geom_from_wkt('POINT EMPTY')) → TRUE
Syntax is_multipart(geometry)
• geometry - a geometry
Arguments
Syntax is_valid(geometry)
• geometry - a geometry
Arguments
Returns the length of a linestring. If you need the length of a border of a polygon, use $perimeter instead. The length
calculated by this function respects both the current project’s ellipsoid setting and distance unit settings. For example, if
an ellipsoid has been set for the project then the calculated length will be ellipsoidal, and if no ellipsoid is set then the
calculated length will be planimetric.
Syntax $length
• $length → 42.4711
Examples
String variant
Syntax length(string)
• string - string to count length of
Arguments
• length('hello') →5
Examples
Geometry variant
Calculate the length of a geometry line object. Calculations are always planimetric in the Spatial Reference System (SRS)
of this geometry, and the units of the returned length will match the units for the SRS. This differs from the calculations
performed by the $length function, which will perform ellipsoidal calculations based on the project’s ellipsoid and
distance unit settings.
Syntax length(geometry)
• geometry - line geometry object
Arguments
Calculates the 3D length of a geometry line object. If the geometry is not a 3D line object, it returns its 2D length.
Calculations are always planimetric in the Spatial Reference System (SRS) of this geometry, and the units of the returned
length will match the units for the SRS. This differs from the calculations performed by the $length function, which will
perform ellipsoidal calculations based on the project’s ellipsoid and distance unit settings.
Syntax length3D(geometry)
• geometry - line geometry object
Arguments
Returns the angle parallel to the geometry at a specified distance along a linestring geometry. Angles are in degrees
clockwise from north.
• line_interpolate_angle(geometry:=geom_from_wkt('LineString(0 0, 10
Examples 0)'),distance:=5) → 90.0
• geom_to_wkt(line_interpolate_point(geometry:=geom_from_wkt('LineString(0 0, 8
0)'), distance:=5)) → ‘Point (5 0)’
• geom_to_wkt(line_interpolate_point(geometry:=geom_from_wkt('LineString(0 0, 1 1, 2
Examples 0)'), distance:=2.1)) → ‘Point (1.48492424 0.51507576)’
• geom_to_wkt(line_interpolate_point(geometry:=geom_from_wkt('LineString(0 0, 1
0)'), distance:=2)) → NULL
Returns the distance along a linestring corresponding to the closest position the linestring comes to a specified point
geometry.
• line_locate_point(geometry:=geom_from_wkt('LineString(0 0, 10
Examples 0)'),point:=geom_from_wkt('Point(5 0)')) → 5.0
Returns a LineString or MultiLineString geometry, where any connected LineStrings from the input geometry have been
merged into a single linestring. This function will return NULL if passed a geometry which is not a
LineString/MultiLineString.
Syntax line_merge(geometry)
• geometry - a LineString/MultiLineString geometry
Arguments
Returns the portion of a line (or curve) geometry which falls between the specified start and end distances (measured from
the beginning of the line). Z and M values are linearly interpolated from existing values.
• geom_to_wkt(line_substring(geometry:=geom_from_wkt('LineString(0 0, 10
Examples 0)'),start_distance:=2,end_distance:=6)) → ‘LineString (2 0,6 0)’
219. 13.2.13.65. m
Syntax m(geometry)
• geometry - a point geometry
Arguments
Syntax m_max(geometry)
• geometry - a geometry containing m values
Arguments
Syntax m_min(geometry)
• geometry - a geometry containing m values
Arguments
Returns the angle of the long axis (clockwise, in degrees from North) of the oriented minimal bounding rectangle, which
completely covers the geometry.
Syntax main_angle(geometry)
• geometry - a geometry
Arguments
Array variant
Syntax make_line(array)
• array - array of points
Arguments
• geom_to_wkt(make_line(array(make_point(2,4),make_point(3,5),make_point(9,7)))) →
Examples ‘LineString (2 4, 3 5, 9 7)’
Syntax make_point_m(x, y, m)
• x - x coordinate of point
• y - y coordinate of point
Arguments
• m - m value of point
Creates a polygon geometry from an outer ring and optional series of inner ring geometries.
• geom_to_wkt(make_polygon(geom_from_wkt('LINESTRING( 0 0, 0 1, 1 1, 1 0, 0 0 )')))
→ ‘Polygon ((0 0, 0 1, 1 1, 1 0, 0 0))’
• geom_to_wkt(make_polygon(geom_from_wkt('LINESTRING( 0 0, 0 1, 1 1, 1 0, 0 0
)'),geom_from_wkt('LINESTRING( 0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2 0.1, 0.1 0.1
Examples )'),geom_from_wkt('LINESTRING( 0.8 0.8, 0.8 0.9, 0.9 0.9, 0.9 0.8, 0.8 0.8 )'))) →
‘Polygon ((0 0, 0 1, 1 1, 1 0, 0 0),(0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2 0.1, 0.1 0.1),(0.8 0.8, 0.8 0.9, 0.9 0.9,
0.9 0.8, 0.8 0.8))’
Returns a valid geometry or an empty geometry if the geometry could not be made valid.
• geom_to_wkt(make_valid(geom_from_wkt('POLYGON((3 2, 4 1, 5 8, 3 2, 4 2))'))) →
‘Polygon ((3 2, 5 8, 4 1, 3 2))’
• geom_to_wkt(make_valid(geom_from_wkt('POLYGON((3 2, 4 1, 5 8, 3 2, 4 2))'),
'linework')) → ‘GeometryCollection (Polygon ((5 8, 4 1, 3 2, 5 8)),LineString (3 2, 4 2))’
Examples • geom_to_wkt(make_valid(geom_from_wkt('POLYGON((3 2, 4 1, 5 8))'),
method:='linework')) → ‘Polygon ((3 2, 4 1, 5 8, 3 2))’
• make_valid(geom_from_wkt('LINESTRING(0 0)')) → An empty geometry
Returns the minimal enclosing circle of a geometry. It represents the minimum circle that encloses all geometries within
the set.
minimal_circle(geometry, [segments=36])
Syntax
[] marks optional arguments
• geometry - a geometry
Arguments • segments - optional argument for polygon segmentation. By default this value is 36
nodes_to_points(geometry, [ignore_closing_nodes=false])
Syntax
[] marks optional arguments
• geometry - geometry object
• ignore_closing_nodes - optional argument specifying whether to include duplicate nodes which
Arguments close lines or polygons rings. Defaults to false, set to true to avoid including these duplicate nodes in
the output collection.
• geom_to_wkt(nodes_to_points(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))) →
‘MultiPoint ((0 0),(1 1),(2 2))’
Examples • geom_to_wkt(nodes_to_points(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -
1))'),true)) → ‘MultiPoint ((-1 -1),(4 0),(4 2),(0 2))’
Returns the number of geometries in a geometry collection, or the number of parts in a multi-part geometry. The function
returns NULL if the input geometry is not a collection.
Syntax num_geometries(geometry)
• geometry - geometry collection or multi-part geometry
Arguments
Returns the number of interior rings in a polygon or geometry collection, or NULL if the input geometry is not a polygon
or collection.
Syntax num_interior_rings(geometry)
• geometry - input geometry
Arguments
Syntax num_points(geometry)
• geometry - a geometry
Arguments
Returns the number of rings (including exterior rings) in a polygon or geometry collection, or NULL if the input geometry
is not a polygon or collection.
Syntax num_rings(geometry)
• geometry - input geometry
Arguments
• geom_to_wkt(order_parts(geom_from_wkt('MultiPolygon (((1 1, 5 1, 5 5, 1 5, 1
1)),((1 1, 9 1, 9 9, 1 9, 1 1)))'), 'area($geometry)', False)) → ‘MultiPolygon (((1 1,
9 1, 9 9, 1 9, 1 1)),((1 1, 5 1, 5 5, 1 5, 1 1)))’
Examples
• geom_to_wkt(order_parts(geom_from_wkt('LineString(1 2, 3 2, 4 3)'), '1', True)) →
‘LineString(1 2, 3 2, 4 3)’
Returns a geometry which represents the minimal oriented bounding box of an input geometry.
Syntax oriented_bbox(geometry)
• geometry - a geometry
Arguments
Tests whether a geometry overlaps another. Returns TRUE if the geometries share space, are of the same dimension, but
are not completely contained by each other.
Returns whether the current feature spatially contains at least one feature from a target layer, or an array of expression-
based results for the features in the target layer contained in the current feature.
Read more on the underlying GEOS “Contains” predicate, as described in PostGIS ST_Contains function.
Returns whether the current feature spatially crosses at least one feature from a target layer, or an array of expression-
based results for the features in the target layer crossed by the current feature.
Read more on the underlying GEOS “Crosses” predicate, as described in PostGIS ST_Crosses function.
Returns whether the current feature is spatially disjoint from all the features of a target layer, or an array of expression-
based results for the features in the target layer that are disjoint from the current feature.
Read more on the underlying GEOS “Disjoint” predicate, as described in PostGIS ST_Disjoint function.
• overlay_disjoint('regions') → TRUE if the current feature is spatially disjoint from all the
regions
• overlay_disjoint('regions', filter:= population > 10000) → TRUE if the current feature
is spatially disjoint from all the regions with a population greater than 10000
• overlay_disjoint('regions', name) → an array of names, for the regions spatially disjoint from
the current feature
• array_to_string(overlay_disjoint('regions', name)) → a string as a comma separated list of
Examples
names, for the regions spatially disjoint from the current feature
• array_sort(overlay_disjoint(layer:='regions', expression:="name", filter:=
population > 10000)) → an ordered array of names, for the regions spatially disjoint from the
current feature and with a population greater than 10000
• overlay_disjoint(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2)
→ an array of geometries (in WKT), for up to two regions spatially disjoint from the current feature
Returns whether the current feature spatially equals to at least one feature from a target layer, or an array of expression-
based results for the features in the target layer that are spatially equal to the current feature.
Read more on the underlying GEOS “Equals” predicate, as described in PostGIS ST_Equals function.
Returns whether the current feature spatially intersects at least one feature from a target layer, or an array of expression-
based results for the features in the target layer intersected by the current feature.
Read more on the underlying GEOS “Intersects” predicate, as described in PostGIS ST_Intersects function.
• return_details - Set this to true to return a list of maps containing (key names in quotes) the feature
‘id’, the expression ‘result’ and the ‘overlap’ value. The ‘radius’ of the maximum inscribed circle is
also returned when the target layer is a polygon. Only valid when used with the expression parameter
• sort_by_intersection_size - only valid when used with an expression, set this to ‘des’ to return the
results ordered by the overlap value in descending order or set this to ‘asc’ for ascending order.
Returns whether the current feature has feature(s) from a target layer within a given distance, or an array of expression-
based results for the features in the target layer within a distance from the current feature.
Note: This function can be slow and consume a lot of memory for large layers.
Returns whether the current feature spatially touches at least one feature from a target layer, or an array of expression-
based results for the features in the target layer touched by the current feature.
Read more on the underlying GEOS “Touches” predicate, as described in PostGIS ST_Touches function.
Returns whether the current feature is spatially within at least one feature from a target layer, or an array of expression-
based results for the features in the target layer that contain the current feature.
Read more on the underlying GEOS “Within” predicate, as described in PostGIS ST_Within function.
Returns the perimeter length of the current feature. The perimeter calculated by this function respects both the current
project’s ellipsoid setting and distance unit settings. For example, if an ellipsoid has been set for the project then the
calculated perimeter will be ellipsoidal, and if no ellipsoid is set then the calculated perimeter will be planimetric.
Syntax $perimeter
• $perimeter → 42
Examples
Returns the perimeter of a geometry polygon object. Calculations are always planimetric in the Spatial Reference System
(SRS) of this geometry, and the units of the returned perimeter will match the units for the SRS. This differs from the
calculations performed by the $perimeter function, which will perform ellipsoidal calculations based on the project’s
ellipsoid and distance unit settings.
Syntax perimeter(geometry)
• geometry - polygon geometry object
Arguments
• geom_to_wkt(point_n(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))'),2)) →
Examples ‘Point (4 0)’
Syntax point_on_surface(geometry)
• geometry - a geometry
Arguments
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary
of the surface. This function uses the ‘polylabel’ algorithm (Vladimir Agafonkin, 2016), which is an iterative approach
guaranteed to find the true pole of inaccessibility within a specified tolerance. More precise tolerances require more
iterations and will take longer to calculate.
Returns a point projected from a start point using a distance, a bearing (azimuth) and an elevation in radians.
Tests the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the relationship between two
geometries.
Relationship variant
Returns the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the relationship between two
geometries.
Tests whether the DE-9IM relationship between two geometries matches a specified pattern.
Reverses the direction of a line string by reversing the order of its vertices.
Syntax reverse(geometry)
• geometry - a geometry
Arguments
Returns a rotated version of a geometry. Calculations are in the Spatial Reference System of this geometry.
Calculates how close a polygon shape is to a circle. The function Returns TRUE when the polygon shape is a perfect
circle and 0 when it is completely flat.
Syntax roundness(geometry)
• geometry - a polygon
Arguments
Returns a scaled version of a geometry. Calculations are in the Spatial Reference System of this geometry.
Returns a multi line geometry consisting of a line for every segment in the input geometry.
Syntax segments_to_lines(geometry)
• geometry - geometry object
Arguments
• geom_to_wkt(segments_to_lines(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))) →
Examples ‘MultiLineString ((0 0, 1 1),(1 1, 2 2))’
Returns a collection containing paths shared by the two input geometries. Those going in the same direction are in the first
element of the collection, those going in the opposite direction are in the second element. The paths themselves are given
in the direction of the first geometry.
Returns the shortest line joining geometry1 to geometry2. The resultant line will start at geometry1 and end at geometry2.
Simplifies a geometry by removing nodes using a distance based threshold (ie, the Douglas Peucker algorithm). The
algorithm preserves large deviations in geometries and reduces the number of vertices in nearly straight segments.
• geom_to_wkt(simplify(geometry:=geom_from_wkt('LineString(0 0, 5 0.1, 10
Examples 0)'),tolerance:=5)) → ‘LineString(0 0, 10 0)’
Simplifies a geometry by removing nodes using an area based threshold (ie, the Visvalingam-Whyatt algorithm). The
algorithm removes vertices which create small areas in geometries, e.g., narrow spikes or nearly straight segments.
Returns a geometry formed by buffering out just one side of a linestring geometry. Distances are in the Spatial Reference
System of this geometry.
Returns the sinuosity of a curve, which is the ratio of the curve length to the straight (2D) distance between its endpoints.
Syntax sinuosity(geometry)
• geometry - Input curve (circularstring, linestring)
Arguments
Smooths a geometry by adding extra nodes which round off corners in the geometry. If input geometries contain Z or M
values, these will also be smoothed and the output geometry will retain the same dimensionality as the input geometry.
Syntax start_point(geometry)
• geometry - geometry object
Arguments
Returns the direct/euclidean distance between the first and last vertex of a geometry. The geometry must be a curve
(circularstring, linestring).
Syntax straight_distance_2d(geometry)
• geometry - The geometry.
Arguments
• straight_distance_2d(geom_from_wkt('LINESTRING(1 0, 1 1)')) → 1
Examples • round(straight_distance_2d(geom_from_wkt('LINESTRING(1 4, 3 5, 5 0)')), 3) → 5.657
Returns a geometry that represents the portions of two geometries that do not intersect.
Creates a buffer along a line geometry where the buffer diameter varies evenly over the length of the line.
Tests whether a geometry touches another. Returns TRUE if the geometries have at least one point in common, but their
interiors do not intersect.
Returns a translated version of a geometry. Calculations are in the Spatial Reference System of this geometry.
• translate($geometry, 5, 10) → a geometry of the same type like the original one
Examples
Returns a geometry that represents the point set union of the geometries.
• wedge_buffer(center:=geom_from_wkt('POINT(1
2)'),azimuth:=90,width:=180,outer_radius:=1) → A wedge shaped buffer centered on the
Examples
point (1,2), facing to the East, with a width of 180 degrees and outer radius of 1.
Tests whether a geometry is within another. Returns TRUE if the geometry1 is completely within geometry2.
Returns the x coordinate of the current point feature. If the feature is a multipoint feature, then the x-coordinate of the first
point will be returned.
Syntax $x
• $x → 42
Examples
288. 13.2.13.134. x
Returns the x coordinate of a point geometry, or the x coordinate of the centroid for a non-point geometry.
Syntax x(geometry)
• geometry - a geometry
Arguments
Syntax $x_at(i)
• i - index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)
Arguments
• $x_at(1) →5
Examples
Returns the maximum x coordinate of a geometry. Calculations are in the spatial reference system of this geometry.
Syntax x_max(geometry)
• geometry - a geometry
Arguments
Returns the minimum x coordinate of a geometry. Calculations are in the spatial reference system of this geometry.
Syntax x_min(geometry)
• geometry - a geometry
Arguments
Returns the y coordinate of the current point feature. If the feature is a multipoint feature, then the y-coordinate of the first
point will be returned.
Syntax $y
• $y → 42
Examples
293. 13.2.13.139. y
Returns the y coordinate of a point geometry, or the y coordinate of the centroid for a non-point geometry.
Syntax y(geometry)
• geometry - a geometry
Arguments
Syntax $y_at(i)
• i - index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)
Arguments
• $y_at(1) →2
Examples
Returns the maximum y coordinate of a geometry. Calculations are in the spatial reference system of this geometry.
Syntax y_max(geometry)
• geometry - a geometry
Arguments
Returns the minimum y coordinate of a geometry. Calculations are in the spatial reference system of this geometry.
Syntax y_min(geometry)
• geometry - a geometry
Arguments
Returns the z value of the current point feature if it is 3D. If the feature is a multipoint feature, then the z value of the first
point will be returned.
Syntax $z
• $z → 123
Examples
298. 13.2.13.144. z
Returns the z coordinate of a point geometry, or NULL if the geometry has no z value.
Syntax z(geometry)
• geometry - a point geometry
Arguments
Returns the maximum z coordinate of a geometry, or NULL if the geometry has no z value.
Syntax z_max(geometry)
• geometry - a geometry with z coordinate
Arguments
Returns the minimum z coordinate of a geometry, or NULL if the geometry has no z value.
Syntax z_min(geometry)
• geometry - a geometry with z coordinate
Arguments
• item_variables
• map_credits
Returns a map of variables from a layout item inside this print layout.
Syntax item_variables(id)
• id - layout item ID
Arguments
• map_get( item_variables('Map 0'), 'map_scale') → scale of the item ‘Map 0’ in the current
Examples print layout
Returns a list of credit (usage rights) strings for the layers shown in a layout map item.
• array_to_string( map_credits( 'Main Map' ) ) → comma separated list of layer credits for
Examples
layers shown in the ‘Main Map’ layout item, e.g ‘CC-BY-NC, CC-BY-SA’
• array_to_string( map_credits( 'Main Map', include_layer_names := true,
layer_name_separator := ': ' ) ) → comma separated list of layer names and their credits for
layers shown in the ‘Main Map’ layout item, e.g. ‘Railway lines: CC-BY-NC, Basemap: CC-BY-SA’
This function requires the Access metadata properties of the layers to have been filled.
• decode_uri
• layer_property
Takes a layer and decodes the uri of the underlying data provider. It depends on the dataprovider, which data is available.
decode_uri(layer, [part])
Syntax
[] marks optional arguments
• layer - The layer for which the uri should be decoded.
Arguments • part - The part of the uri to return. If unspecified, a map with all uri parts will be returned.
• from_json
• hstore_to_map
• map
• map_akeys
• map_avals
• map_concat
• map_delete
• map_exist
• map_get
• map_insert
• map_prefix_keys
• map_to_hstore
• to_json
• url_encode
Syntax from_json(string)
• string - JSON string
Arguments
Syntax hstore_to_map(string)
• string - the input string
Arguments
Returns a map containing all the keys and values passed as pair of parameters.
Syntax map_akeys(map)
• map - a map
Arguments
Syntax map_avals(map)
• map - a map
Arguments
Returns a map containing all the entries of the given maps. If two maps contain the same key, the value of the second map
is taken.
Returns a map with the given key and its corresponding value deleted.
• map_exist(map('1','one','2','two'),'3') → FALSE
Examples
Returns the value of a map, given its key. Returns NULL if the key does not exist.
• map_get(map('1','one','2','two'),'2') → ‘two’
• map_get( item_variables('Map 0'), 'map_scale') → scale of the item ‘Map 0’ (if it exists) in
Examples
the current print layout
Hint
You can also use the index operator ([]) to get a value from a map.
Returns a map with an added key/value. If the key already exists, its value is overridden.
Syntax map_to_hstore(map)
• map - the input map
Arguments
• map_to_hstore(map('qgis','rocks')) → ‘“qgis”=>”rocks”’
Examples
Syntax to_json(value)
• value - The input value
Arguments
• to_json(map('qgis','rocks')) → {“qgis”:”rocks”}
Examples • to_json(array(1,2,3)) → [1,2,3]
Returns an URL encoded string from a map. Transforms all characters in their properly-encoded form producing a fully-
compliant query string.
Syntax url_encode(map)
• map - a map.
Arguments
• abs
• acos
• asin
• atan
• atan2
• ceil
• clamp
• cos
• degrees
• exp
• floor
• ln
• log
• log10
• max
• min
• pi
• radians
• rand
• randf
• round
• scale_exp
• scale_linear
• sin
• sqrt
• tan
Syntax abs(value)
• value - a number
Arguments
• abs(-2) →2
Examples
Syntax acos(value)
• value - cosine of an angle in radians
Arguments
• acos(0.5) → 1.0471975511966
Examples
Syntax asin(value)
• value - sine of an angle in radians
Arguments
• asin(1.0) → 1.5707963267949
Examples
Syntax atan(value)
• value - tan of an angle in radians
Arguments
• atan(0.5) → 0.463647609000806
Examples
Returns the inverse tangent of dy/dx by using the signs of the two arguments to determine the quadrant of the result.
Syntax ceil(value)
• value - a number
Arguments
• ceil(4.9) → 5
Examples • ceil(-4.9) → -4
• clamp(1,5,10) →5
• clamp(1,0,10) →1
Examples
input is less than minimum value of 1, so function returns 1
• clamp(1,11,10) → 10
Syntax cos(angle)
• angle - angle in radians
Arguments
• cos(1.571) → 0.000796326710733263
Examples
Syntax degrees(radians)
• radians - numeric value
Arguments
• degrees(3.14159) → 180
Examples • degrees(1) → 57.2958
Syntax exp(value)
• value - number to return exponent of
Arguments
• exp(1.0) → 2.71828182845905
Examples
333. 13.2.17.11. floor
Syntax floor(value)
• value - a number
Arguments
• floor(4.9) → 4
Examples • floor(-4.9) → -5
Syntax ln(value)
• value - numeric value
Arguments
• ln(1) → 0
Examples • ln(2.7182818284590452354) →1
Returns the value of the logarithm of the passed value and base.
• log(2, 32) → 5
Examples • log(0.5, 32) → -5
Syntax log10(value)
• value - any positive number
Arguments
• log10(1) → 0
Examples • log10(100) → 2
• max(2,10.2,5.5) → 10.2
Examples • max(20.5,NULL,6.2) → 20.5
• min(20.5,10,6.2) → 6.2
Examples • min(2,-10.3,NULL) → -10.3
Syntax pi()
• pi() → 3.14159265358979
Examples
Syntax radians(degrees)
• degrees - numeric value
Arguments
• radians(180) → 3.14159
Examples • radians(57.2958) → 1
Returns a random integer within the range specified by the minimum and maximum argument (inclusive). If a seed is
provided, the returned will always be the same, depending on the seed.
Returns a random float within the range specified by the minimum and maximum argument (inclusive). If a seed is
provided, the returned will always be the same, depending on the seed.
round(value, [places=0])
Syntax
[] marks optional arguments
• value - decimal number to be rounded
Arguments • places - Optional integer representing number of places to round decimals to. Can be negative.
• round(1234.567, 2) → 1234.57
• round(1234.567) → 1235
Examples
• round(1234.567, -1) → 1230
Transforms a given value from an input domain to an output range using an exponential curve. This function can be used
to ease values in or out of the specified output range.
• scale_exp(5,0,10,0,100,2) → 25
Transforms a given value from an input domain to an output range using linear interpolation.
• scale_linear(5,0,10,0,100) → 50
• scale_linear(0.2,0,1,0,360) → 72
scaling a population which varies between 1000 and 10000 to a font size between 9 and 20
Syntax sin(angle)
• angle - angle in radians
Arguments
• sin(1.571) → 0.999999682931835
Examples
• sqrt(9) →3
Examples
Syntax tan(angle)
• angle - angle in radians
Arguments
• tan(1.0) → 1.5574077246549
Examples
• $face_area
• $face_index
• $vertex_as_point
• $vertex_index
• $vertex_x
• $vertex_y
• $vertex_z
Returns the area of the current mesh face. The area calculated by this function respects both the current project’s ellipsoid
setting and area unit settings. For example, if an ellipsoid has been set for the project then the calculated area will be
ellipsoidal, and if no ellipsoid is set then the calculated area will be planimetric.
Syntax $face_area
• $face_area → 42
Examples
Syntax $face_index
• $face_index → 4581
Examples
Syntax $vertex_index
• $vertex_index → 9874
Examples
Syntax $vertex_x
• $vertex_x → 42.12
Examples
Syntax $vertex_y
• $vertex_y → 12.24
Examples
Syntax $vertex_z
• $vertex_z → 42
Examples
• %
• *
• +
• -
• /
• <
• <=
• <>
• =
• >
• >=
• AND
• BETWEEN
• ILIKE
• IN
• IS
• IS NOT
• LIKE
• NOT
• NOT BETWEEN
• OR
• []
• ^
• ||
• ~
358. 13.2.19.1. %
Syntax a%b
• a - value
Arguments • b - value
• 9 % 2→1
• 9 % -2 → 1
Examples • -9 % 2 → -1
• 5 % NULL → NULL
359. 13.2.19.2. *
Syntax a*b
• a - value
Arguments • b - value
• 5 * 4 → 20
Examples • 5 * NULL → NULL
360. 13.2.19.3. +
Addition of two values. If one of the values is NULL the result will be NULL.
Syntax a+b
• a - value
Arguments • b - value
Examples • 5 + 4 →9
• 5 + NULL → NULL
• 'QGIS ' + 'ROCKS' → ‘QGIS ROCKS’
• to_datetime('2020-08-01 12:00:00') + '1 day 2 hours' → 2020-08-02T14:00:00
361. 13.2.19.4. -
Subtraction of two values. If one of the values is NULL the result will be NULL.
Syntax a-b
• a - value
Arguments • b - value
• 5 - 4→1
• 5 - NULL → NULL
Examples • to_datetime('2012-05-05 12:00:00') - to_interval('1 day 2 hours') → 2012-05-
04T10:00:00
362. 13.2.19.5. /
Syntax a/b
• a - value
Arguments • b - value
• 5 / 4 → 1.25
Examples • 5 / NULL → NULL
Compares two values and evaluates to 1 if the left value is less than the right value.
Syntax a<b
• a - value
Arguments • b - value
• 5 < 4 → FALSE
• 5 < 5 → FALSE
Examples
• 4 < 5 → TRUE
Compares two values and evaluates to 1 if the left value is less or equal than the right value.
Syntax a <= b
• a - value
Arguments • b - value
• 5 <= 4 → FALSE
• 5 <= 5 → TRUE
Examples
• 4 <= 5 → TRUE
Syntax a <> b
• a - value
Arguments • b - value
• 5 <> 4 → TRUE
• 4 <> 4 → FALSE
Examples • 5 <> NULL → NULL
• NULL <> NULL → NULL
366. 13.2.19.9. =
Syntax a=b
• a - value
Arguments • b - value
• 5 = 4 → FALSE
• 4 = 4 → TRUE
Examples • 5 = NULL → NULL
• NULL = NULL → NULL
Compares two values and evaluates to 1 if the left value is greater than the right value.
Syntax a>b
• a - value
Arguments • b - value
• 5 > 4 → TRUE
• 5 > 5 → FALSE
Examples
• 4 > 5 → FALSE
368. 13.2.19.11. >=
Compares two values and evaluates to 1 if the left value is greater or equal than the right value.
Syntax a >= b
• a - value
Arguments • b - value
• 5 >= 4 → TRUE
• 5 >= 5 → TRUE
Examples
• 4 >= 5 → FALSE
Syntax a AND b
• a - condition
Arguments • b - condition
Returns TRUE if value is within the specified range. The range is considered inclusive of the bounds. To test for
exclusion NOT BETWEEN can be used.
Note
value BETWEEN lower_bound AND higher_bound is the same as “value >= lower_bound AND value <=
higher_bound”.
Syntax a IN b
• a - value
Arguments • b - list of values
Syntax a IS b
• a - any value
Arguments • b - any value
Syntax a IS NOT b
• a - value
Arguments • b - value
Returns TRUE if the first parameter matches the supplied pattern. Works with numbers also.
Negates a condition.
Syntax NOT a
• a - condition
Arguments
• NOT 1 → FALSE
Examples • NOT 0 → TRUE
Returns TRUE if value is not within the specified range. The range is considered inclusive of the bounds.
Note
value NOT BETWEEN lower_bound AND higher_bound is the same as “value < lower_bound OR value >
higher_bound”.
Syntax a OR b
• a - condition
Arguments • b - condition
• 4 = 2+2 OR 1 = 1 → TRUE
• 4 = 2+2 OR 1 = 2 → TRUE
Examples
• 4 = 2 OR 1 = 2 → FALSE
Syntax [index]
• index - array index or map key value
Arguments
• array(1,2,3)[0] → 1
• array(1,2,3)[2] → 3
• array(1,2,3)[-1] → 3
Examples
• map('a',1,'b',2)['a'] →1
• map('a',1,'b',2)['b'] →2
380. 13.2.19.23. ^
Syntax a^b
• a - value
Arguments • b - value
• 5 ^ 4 → 625
Examples • 5 ^ NULL → NULL
If one of the values is NULL the result will be NULL. See the CONCAT function for a different behavior.
Syntax a || b
• a - value
Arguments • b - value
382. 13.2.19.25. ~
Performs a regular expression match on a string value. Backslash characters must be double escaped (e.g., “\\s” to match a
white space character).
• parameter
• parameter('BUFFER_SIZE') → 5.6
Examples
• raster_statistic
• raster_value
• raster_value('dem', 1, make_point(1,1)) → 25
Examples
• attribute
• attributes
• $currentfeature
• display_expression
• get_feature
• get_feature_by_id
• $id
• is_selected
• maptip
• num_selected
• represent_attributes
• represent_value
• sqlite_fetch_and_increment
• uuid
Variant 1
Syntax attribute(attribute_name)
• attribute_name - name of attribute to be returned
Arguments
• attribute( 'name' ) → value stored in ‘name’ attribute for the current feature
Examples
Variant 2
• attribute( @atlas_feature, 'name' ) → value stored in ‘name’ attribute for the current atlas
Examples feature
Returns a map containing all attributes from a feature, with field names as map keys.
Variant 1
Syntax attributes()
• attributes()['name'] → value stored in ‘name’ attribute for the current feature
Examples
Variant 2
Syntax attributes(feature)
• feature - a feature
Arguments
• attributes( @atlas_feature )['name'] → value stored in ‘name’ attribute for the current atlas
Examples feature
Returns the current feature being evaluated. This can be used with the ‘attribute’ function to evaluate attribute values from
the current feature. WARNING: This function is deprecated. It is recommended to use the replacement @feature
variable instead.
Syntax $currentfeature
• attribute( $currentfeature, 'name' ) → value stored in ‘name’ attribute for the current feature
Examples
Returns the display expression for a given feature in a layer. The expression is evaluated by default. Can be used with
zero, one or more arguments, see below for details.
No parameters
If called with no parameters, the function will evaluate the display expression of the current feature in the current layer.
Syntax display_expression()
• display_expression() → The display expression of the current feature in the current layer.
Examples
If called with a ‘feature’ parameter only, the function will evaluate the specified feature from the current layer.
Syntax display_expression(feature)
• feature - The feature which should be evaluated.
Arguments
If the function is called with both a layer and a feature, it will evaluate the specified feature from the specified layer.
display_expression(layer, feature, [evaluate=true])
Syntax
[] marks optional arguments
• layer - The layer (or its ID or name)
• feature - The feature which should be evaluated.
Arguments • evaluate - If the expression must be evaluated. If false, the expression will be returned as a string
literal only (which could potentially be later evaluated using the ‘eval’ function).
Along with the layer ID, a single column and value are specified.
Map variant
Along with the layer ID, a map containing the columns (key) and their respective value to be used.
Returns the feature id of the current row. WARNING: This function is deprecated. It is recommended to use the
replacement @id variable instead.
Syntax $id
• $id → 42
Examples
Returns TRUE if a feature is selected. Can be used with zero, one or two arguments, see below for details.
No parameters
If called with no parameters, the function will return TRUE if the current feature in the current layer is selected.
Syntax is_selected()
• is_selected() → TRUE if the current feature in the current layer is selected.
Examples
If called with a ‘feature’ parameter only, the function returns TRUE if the specified feature from the current layer is
selected.
Syntax is_selected(feature)
• feature - The feature which should be checked for selection.
Arguments
Two parameters
If the function is called with both a layer and a feature, it will return TRUE if the specified feature from the specified layer
is selected.
Returns the maptip for a given feature in a layer. The expression is evaluated by default. Can be used with zero, one or
more arguments, see below for details.
No parameters
If called with no parameters, the function will evaluate the maptip of the current feature in the current layer.
Syntax maptip()
• maptip() → The maptip of the current feature in the current layer.
Examples
If called with a ‘feature’ parameter only, the function will evaluate the specified feature from the current layer.
Syntax maptip(feature)
• feature - The feature which should be evaluated.
Arguments
If the function is called with both a layer and a feature, it will evaluate the specified feature from the specified layer.
num_selected([layer=current layer])
Syntax
[] marks optional arguments
• layer - The layer (or its id or name) on which the selection will be checked.
Arguments
Returns a map with the attribute names as keys and the configured representation values as values. The representation
value for the attributes depends on the configured widget type for each attribute. Can be used with zero, one or more
arguments, see below for details.
No parameters
If called with no parameters, the function will return the representation of the attributes of the current feature in the
current layer.
Syntax represent_attributes()
• represent_attributes() → The representation of the attributes for the current feature.
Examples
If called with a ‘feature’ parameter only, the function will return the representation of the attributes of the specified feature
from the current layer.
Syntax represent_attributes(feature)
• feature - The feature which should be evaluated.
Arguments
If called with a ‘layer’ and a ‘feature’ parameter, the function will return the representation of the attributes of the
specified feature from the specified layer.
Returns the configured representation value for a field value. It depends on the configured widget type. Often, this is
useful for ‘Value Map’ widgets.
represent_value(value, [fieldName])
Syntax
[] marks optional arguments
• value - The value which should be resolved. Most likely a field.
Arguments • fieldName - The field name for which the widget configuration should be loaded.
SQlite default values can only be applied on insert and not prefetched.
This makes it impossible to acquire an incremented primary key via AUTO_INCREMENT before creating the row in the
database. Sidenote: with postgres, this works via the option evaluate default values.
When adding new features with relations, it is really nice to be able to already add children for a parent, while the parents
form is still open and hence the parent feature uncommitted.
To get around this limitation, this function can be used to manage sequence values in a separate table on sqlite based
formats like gpkg.
The sequence table will be filtered for a sequence id (filter_attribute and filter_value) and the current value of the id_field
will be incremented by 1 and the incremented value returned.
If additional columns require values to be specified, the default_values map can be used for this purpose.
Note
This function modifies the target sqlite table. It is intended for usage with default value configurations for attributes.
When the database parameter is a layer and the layer is in transaction mode, the value will only be retrieved once during
the lifetime of a transaction and cached and incremented. This makes it unsafe to work on the same database from several
processes in parallel.
Further reading: Data Sources Properties, Creating one or many to many relations
Generates a Universally Unique Identifier (UUID) for each row using the Qt QUuid::createUuid method.
uuid([format=’WithBraces’])
Syntax
[] marks optional arguments
• format - The format, as the UUID will be formatted. ‘WithBraces’, ‘WithoutBraces’ or ‘Id128’.
Arguments
• uuid() → ‘{0bd2f60f-f157-4a6d-96af-d4ba4cb366a1}’
• uuid('WithoutBraces') → ‘0bd2f60f-f157-4a6d-96af-d4ba4cb366a1’
Examples
• uuid('Id128') → ‘0bd2f60ff1574a6d96afd4ba4cb366a1’
• ascii
• char
• concat
• format
• format_date
• format_number
• left
• length
• lower
• lpad
• regexp_match
• regexp_replace
• regexp_substr
• replace
• right
• rpad
• strpos
• substr
• title
• to_string
• trim
• upper
• wordwrap
Returns the unicode code associated with the first character of a string.
Syntax ascii(string)
• string - the string to convert to unicode code
Arguments
• ascii('Q') → 81
Examples
Syntax char(code)
• code - a unicode code number
Arguments
• char(81) → ‘Q’
Examples
Concatenates several strings to one. NULL values are converted to empty strings. Other values (like numbers) are
converted to strings.
You can also concatenate strings or field values using either || or + operators, with some special characteristics:
• The + operator also means sum up expression, so if you have an integer (field or numeric value) operand, this can
be error prone and you better use the others:
• 'My feature id is: ' + "gid" => triggers an error as gid returns an integer
• • When any of the arguments is a NULL value, either || or + will return a NULL value. To return the other arguments
regardless the NULL value, you may want to use the concat function:
Formats a date type or string into a custom string format. Uses Qt date/time format strings. See QDateTime::toString.
Expression Output
d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. ‘Mon’ to ‘Sun’)
Arguments dddd the long localized day name (e.g. ‘Monday’ to ‘Sunday’)
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. ‘Jan’ to ‘Dec’)
MMMM the long localized month name (e.g. ‘January’ to ‘December’)
yy the year as two digit number (00-99)
yyyy the year as four digit number
• These expressions may be used for the time part of the format string:
Expression Output
h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H the hour without a leading zero (0 to 23, even with AM/PM display)
HH the hour with a leading zero (00 to 23, even with AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without trailing zeroes (0 to 999)
zzz the milliseconds with trailing zeroes (000 to 999)
AP or A interpret as an AM/PM time. AP must be either ‘AM’ or ‘PM’.
ap or a Interpret as an AM/PM time. ap must be either ‘am’ or ‘pm’.
• language - language (lowercase, two- or three-letter, ISO 639 language code) used to format the date
into a custom string. By default the current QGIS user locale is used.
• format_date('2012-05-15','dd.MM.yyyy') → ‘15.05.2012’
• format_date('2012-05-15','d MMMM yyyy','fr') → ‘15 mai 2012’
• format_date('2012-05-15','dddd') → ‘Tuesday’, if the current locale is an English variant
Examples
• format_date('2012-05-15 13:54:20','dd.MM.yy') → ‘15.05.12’
• format_date('13:54:20','hh:mm AP') → ‘01:54 PM’
Returns a number formatted with the locale separator for thousands. By default the current QGIS user locale is used. Also
truncates the decimal places to the number of supplied places.
String variant
Syntax length(string)
• string - string to count length of
Arguments
• length('hello') →5
Examples
Geometry variant
Calculate the length of a geometry line object. Calculations are always planimetric in the Spatial Reference System (SRS)
of this geometry, and the units of the returned length will match the units for the SRS. This differs from the calculations
performed by the $length function, which will perform ellipsoidal calculations based on the project’s ellipsoid and
distance unit settings.
Syntax length(geometry)
• geometry - line geometry object
Arguments
Syntax lower(string)
• string - the string to convert to lower case
Arguments
Returns a string padded on the left to the specified width, using a fill character. If the target width is smaller than the
string’s length, the string is truncated.
Syntax lpad(string, width, fill)
• string - string to pad
• width - length of new string
Arguments
• fill - character to pad the remaining space with
Return the first matching position matching a regular expression within an unicode string, or 0 if the substring is not
found.
• regexp_match('QGIS ROCKS','\\sROCKS') →5
Examples • regexp_match('Budač','udač\\b') → 2
• regexp_substr('abc123','(\\d+)') → ‘123’
Examples
418. 13.2.24.14. replace
Returns a string with the supplied string, array, or map of strings replaced.
Returns a string with the supplied string or array of strings replaced by a string or an array of strings.
Map variant
Returns a string with the supplied map keys replaced by paired values. Longer map keys are evaluated first.
Returns a string padded on the right to the specified width, using a fill character. If the target width is smaller than the
string’s length, the string is truncated.
Return the first matching position of a substring within another string, or 0 if the substring is not found.
• strpos('HELLO WORLD','WORLD') → 7
Examples • strpos('HELLO WORLD','GOODBYE') → 0
Converts all words of a string to title case (all words lower case with leading capital letter).
Syntax title(string)
• string - the string to convert to title case
Arguments
Syntax to_string(number)
• number - Integer or real value. The number to convert to string.
Arguments
• to_string(123) → ‘123’
Examples
Removes all leading and trailing whitespace (spaces, tabs, etc) from a string.
Syntax trim(string)
• string - string to trim
Arguments
Syntax upper(string)
• string - the string to convert to upper case
Arguments
To use these variables in an expression, they should be preceded by the @ character (e.g, @row_number).
Variable Description
algorithm_id The unique ID of an algorithm
animation_end_time End of the animation’s overall temporal time range (as a datetime value)
animation_interval Duration of the animation’s overall temporal time range (as an interval value)
animation_start_time Start of the animation’s overall temporal time range (as a datetime value)
atlas_feature The current atlas feature (as feature object)
atlas_featureid The current atlas feature ID
atlas_featurenumber The current atlas feature number in the layout
atlas_filename The current atlas file name
atlas_geometry The current atlas feature geometry
atlas_layerid The current atlas coverage layer ID
atlas_layername The current atlas coverage layer name
atlas_pagename The current atlas page name
atlas_totalfeatures The total number of features in atlas
canvas_cursor_point The last cursor position on the canvas in the project’s geographical coordinates
cluster_color The color of symbols within a cluster, or NULL if symbols have mixed colors
cluster_size The number of symbols contained within a cluster
current_feature The feature currently being edited in the attribute form or table row
current_geometry The geometry of the feature currently being edited in the form or the table row
represents the feature currently being edited in the parent form. Only usable in an embedded
current_parent_feature
form context.
represents the geometry of the feature currently being edited in the parent form. Only usable in
current_parent_geometry
an embedded form context.
What the form is used for, like AddFeatureMode, SingleEditMode, MultiEditMode,
form_mode
SearchMode, AggregateSearchMode or IdentifyMode as string.
The current feature being evaluated. This can be used with the ‘attribute’ function to evaluate
feature NEW in 3.28
attribute values from the current feature.
frame_duration Temporal duration of each animation frame (as an interval value)
frame_number Current frame number during animation playback
frame_rate Number of frames per second during animation playback
fullextent_maxx Maximum x value from full canvas extent (including all layers)
fullextent_maxy Maximum y value from full canvas extent (including all layers)
fullextent_minx Minimum x value from full canvas extent (including all layers)
fullextent_miny Minimum y value from full canvas extent (including all layers)
geometry NEW in 3.28 The geometry of the current feature being evaluated
Variable Description
geometry_part_count The number of parts in rendered feature’s geometry
geometry_part_num The current geometry part number for feature being rendered
geometry_point_count The number of points in the rendered geometry’s part
geometry_point_num The current point number in the rendered geometry’s part
Current geometry ring number for feature being rendered (for polygon features only). The
geometry_ring_num
exterior ring has a value of 0.
grid_axis The current grid annotation axis (eg, ‘x’ for longitude, ‘y’ for latitude)
grid_number The current grid annotation value
id NEW in 3.28 The ID of the current feature being evaluated
item_id The layout item user ID (not necessarily unique)
item_uuid The layout item unique ID
layer The current layer
layer_crs The Coordinate Reference System Authority ID of the current layer
layer_id The ID of current layer
layer_ids The IDs of all the map layers in the current project as a list
layer_name The name of current layer
layers All the map layers in the current project as a list
layout_dpi The composition resolution (DPI)
layout_name The layout name
layout_numpages The number of pages in the layout
layout_page The page number of the current item in the layout
The active page height in the layout (in mm for standard paper sizes, or whatever unit was used
layout_pageheight
for custom paper size)
Array of Y coordinate of the top of each page. Allows to dynamically position items on pages
layout_pageoffsets
in a context where page sizes may change
The active page width in the layout (in mm for standard paper sizes, or whatever unit was used
layout_pagewidth
for custom paper size)
legend_column_count The number of columns in the legend
legend_filter_by_map Indicates if the content of the legend is filtered by the map
legend_filter_out_atlas Indicates if the atlas is filtered out of the legend
legend_split_layers Indicates if layers can be split in the legend
legend_title The title of the legend
legend_wrap_string The character(s) used to wrap the legend text
map_crs The Coordinate reference system of the current map
map_crs_acronym The acronym of the Coordinate reference system of the current map
map_crs_definition The full definition of the Coordinate reference system of the current map
map_crs_description The name of the Coordinate reference system of the current map
map_crs_ellipsoid The acronym of the ellipsoid of the Coordinate reference system of the current map
map_crs_proj4 The Proj4 definition of the Coordinate reference system of the current map
The descriptive name of the projection method used by the Coordinate reference system of the
map_crs_projection
map (e.g. ‘Albers Equal Area’)
map_crs_wkt The WKT definition of the Coordinate reference system of the current map
map_end_time The end of the map’s temporal time range (as a datetime value)
map_extent The geometry representing the current extent of the map
map_extent_center The point feature at the center of the map
Variable Description
map_extent_height The current height of the map
map_extent_width The current width of the map
The ID of current map destination. This will be ‘canvas’ for canvas renders, and the item ID for
map_id
layout map renders
map_interval The duration of the map’s temporal time range (as an interval value)
map_layer_ids The list of map layer IDs visible in the map
map_layers The list of map layers visible in the map
map_rotation The current rotation of the map
map_scale The current scale of the map
map_start_time The start of the map’s temporal time range (as a datetime value)
map_units The units of map measurements
Full path (including file name) of current model (or project path if model is embedded in a
model_path
project).
model_folder Folder containing current model (or project folder if model is embedded in a project).
model_name Name of current model
model_group Group for current model
Content of the notification message sent by the provider (available only for actions triggered by
notification_message
provider notifications).
Refers to the current feature in the parent layer, providing access to its attributes and geometry
parent
when filtering an aggregate function
project_abstract The project abstract, taken from project metadata
project_area_units The area unit for the current project, used when calculating areas of geometries
project_author The project author, taken from project metadata
project_basename The basename of current project’s filename (without path and extension)
project_creation_date The project creation date, taken from project metadata
project_crs The Coordinate reference system of the project
project_crs_arconym The acronym of the Coordinate reference system of the project
project_crs_definition The full definition of the Coordinate reference system of the project
project_crs_description The description of the Coordinate reference system of the project
project_crs_ellipsoid The ellipsoid of the Coordinate reference system of the project
project_crs_proj4 The Proj4 representation of the Coordinate reference system of the project
project_crs_wkt The WKT (well known text) representation of the coordinate reference system of the project
The distance unit for the current project, used when calculating lengths of geometries and
project_distance_units
distances
The name of the ellipsoid of the current project, used when calculating geodetic areas or
project_ellipsoid
lengths of geometries
project_filename The filename of the current project
project_folder The folder of the current project
project_home The home path of the current project
project_identifier The project identifier, taken from the project’s metadata
project_keywords The project keywords, taken from the project’s metadata
project_last_saved Date/time when project was last saved.
project_path The full path (including file name) of the current project
project_title The title of current project
project_units The units of the project’s CRS
qgis_locale The current language of QGIS
Variable Description
qgis_os_name The current Operating system name, eg ‘windows’, ‘linux’ or ‘osx’
qgis_platform The QGIS platform, eg ‘desktop’ or ‘server’
qgis_release_name The current QGIS release name
qgis_short_version The current QGIS version short string
qgis_version The current QGIS version string
qgis_version_no The current QGIS version number
row_number Stores the number of the current row
snapping_results Gives access to snapping results while digitizing a feature (only available in add feature)
scale_value The current scale bar distance value
Selected file path from file widget selector when uploading a file with an external storage
selected_file_path
system
symbol_angle The angle of the symbol used to render the feature (valid for marker symbols only)
symbol_color The color of the symbol used to render the feature
symbol_count The number of features represented by the symbol (in the layout legend)
symbol_id The Internal ID of the symbol (in the layout legend)
The label for the symbol (either a user defined label or the default autogenerated label - in the
symbol_label
layout legend)
symbol_layer_count Total number of symbol layers in the symbol
symbol_layer_index Current symbol layer index
symbol_marker_column Column number for marker (valid for point pattern fills only).
symbol_marker_row Row number for marker (valid for point pattern fills only).
user_account_name The current user’s operating system account name
user_full_name The current user’s operating system user name
value The current value
Exact vector tile zoom level of the map that is being rendered (derived from the current map
vector_tile_zoom scale). Normally in interval [0, 20]. Unlike @zoom_level, this variable is a floating point value
which can be used to interpolate values between two integer zoom levels.
Allows setting a variable for usage within an expression and avoid recalculating the same value
with_variable
repeatedly
Vector tile zoom level of the map that is being rendered (derived from the current map scale).
zoom_level
Normally in interval [0, 20].
Some examples:
• • Return, for each feature in the current layer, the number of overlapping airport features:
with_variable(
'first_snapped_point',
array_first( @snapping_results ),
attribute(
get_feature_by_id(
map_get( @first_snapped_point, 'layer' ),
map_get( @first_snapped_point, 'feature_id' )
),
'object_id'
)
)