13.2. A függvények listája

A QGIS-ben elérhető funkciók, operátorok és változók alább láthatóak, kategória szerint csoportosítva.

13.2.1. Aggregáló függvények

This group contains functions which aggregate values over layers and fields.

13.2.1.1. aggregate

Returns an aggregate value calculated using features from another layer.

Szintaxis

aggregate(layer, aggregate, expression, [filter], [concatenator=»»], [order_by])

[] marks optional arguments

Argumentumok

  • layer - a string, representing either a layer name or layer ID

  • aggregate - a string corresponding to the aggregate to calculate. Valid options are:

    • count

    • count_distinct

    • count_missing

    • min

    • max

    • sum

    • mean

    • median

    • stdev

    • stdevsample

    • range

    • minority

    • majority

    • q1: first quartile

    • q3: third quartile

    • iqr: inter quartile range

    • min_length: minimum string length

    • max_length: maximum string length

    • concatenate: join strings with a concatenator

    • concatenate_unique: join unique strings with a concatenator

    • collect: create an aggregated multipart geometry

    • array_agg: create an array of aggregated values

  • expression - sub expression or field name to aggregate

  • filter - optional filter expression to limit the features used for calculating the aggregate. Fields and geometry are from the features on the joined layer. The source feature can be accessed with the variable @parent.

  • concatenator - optional string to use to join values for «concatenate» and «concatenate_unique» aggregates

  • order_by - optional filter 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.

Példák

  • 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 „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

13.2.1.2. array_agg

Returns an array of aggregated values from a field or expression.

Szintaxis

array_agg(expression, [group_by], [filter], [order_by])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

  • order_by - optional expression to use to order features used to calculate aggregate. By default, the features will be returned in an unspecified order.

Példák

  • array_agg("name",group_by:="state") → list of name values, grouped by state field

13.2.1.3. collect

Returns the multipart geometry of aggregated geometries from an expression

Szintaxis

collect(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - geometry expression to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • collect( $geometry ) → multipart geometry of aggregated geometries

  • collect( centroid($geometry), group_by:="region", filter:= "use" = 'civilian' ) → aggregated centroids of the civilian features based on their region value

13.2.1.4. concatenate

Returns all aggregated strings from a field or expression joined by a delimiter.

Szintaxis

concatenate(expression, [group_by], [filter], [concatenator], [order_by])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

  • concatenator - optional string to use to join values. Empty by default.

  • order_by - optional expression to use to order features used to calculate aggregate. By default, the features will be returned in an unspecified order.

Példák

  • concatenate("town_name",group_by:="state",concatenator:=',') → comma separated list of town_names, grouped by state field

13.2.1.5. concatenate_unique

Returns all unique strings from a field or expression joined by a delimiter.

Szintaxis

concatenate_unique(expression, [group_by], [filter], [concatenator], [order_by])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

  • concatenator - optional string to use to join values. Empty by default.

  • order_by - optional expression to use to order features used to calculate aggregate. By default, the features will be returned in an unspecified order.

Példák

  • concatenate_unique("town_name",group_by:="state",concatenator:=',') → comma separated list of unique town_names, grouped by state field

13.2.1.6. count

Returns the count of matching features.

Szintaxis

count(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • count("stations",group_by:="state") → count of stations, grouped by state field

13.2.1.7. count_distinct

Returns the count of distinct values.

Szintaxis

count_distinct(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • count_distinct("stations",group_by:="state") → count of distinct stations values, grouped by state field

13.2.1.8. count_missing

Returns the count of missing (NULL) values.

Szintaxis

count_missing(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • count_missing("stations",group_by:="state") → count of missing (NULL) station values, grouped by state field

13.2.1.9. iqr

Returns the calculated inter quartile range from a field or expression.

Szintaxis

iqr(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • iqr("population",group_by:="state") → inter quartile range of population value, grouped by state field

13.2.1.10. majority

Returns the aggregate majority of values (most commonly occurring value) from a field or expression.

Szintaxis

majority(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • majority("class",group_by:="state") → most commonly occurring class value, grouped by state field

13.2.1.11. max_length

Returns the maximum length of strings from a field or expression.

Szintaxis

max_length(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • max_length("town_name",group_by:="state") → maximum length of town_name, grouped by state field

13.2.1.12. maximum

Returns the aggregate maximum value from a field or expression.

Szintaxis

maximum(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • maximum("population",group_by:="state") → maximum population value, grouped by state field

13.2.1.13. mean

Returns the aggregate mean value from a field or expression.

Szintaxis

mean(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • mean("population",group_by:="state") → mean population value, grouped by state field

13.2.1.14. median

Returns the aggregate median value from a field or expression.

Szintaxis

median(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • median("population",group_by:="state") → median population value, grouped by state field

13.2.1.15. min_length

Returns the minimum length of strings from a field or expression.

Szintaxis

min_length(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • min_length("town_name",group_by:="state") → minimum length of town_name, grouped by state field

13.2.1.16. minimum

Returns the aggregate minimum value from a field or expression.

Szintaxis

minimum(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • minimum("population",group_by:="state") → minimum population value, grouped by state field

13.2.1.17. minority

Returns the aggregate minority of values (least occurring value) from a field or expression.

Szintaxis

minority(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • minority("class",group_by:="state") → least occurring class value, grouped by state field

13.2.1.18. q1

Returns the calculated first quartile from a field or expression.

Szintaxis

q1(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • q1("population",group_by:="state") → first quartile of population value, grouped by state field

13.2.1.19. q3

Returns the calculated third quartile from a field or expression.

Szintaxis

q3(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • q3("population",group_by:="state") → third quartile of population value, grouped by state field

13.2.1.20. range

Returns the aggregate range of values (maximum - minimum) from a field or expression.

Szintaxis

range(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • range("population",group_by:="state") → range of population values, grouped by state field

13.2.1.21. relation_aggregate

Returns an aggregate value calculated using all matching child features from a layer relation.

Szintaxis

relation_aggregate(relation, aggregate, expression, [concatenator=»»], [order_by])

[] marks optional arguments

Argumentumok

  • relation - a string, representing a relation ID

  • aggregate - a string corresponding to the aggregate to calculate. Valid options are:

    • count

    • count_distinct

    • count_missing

    • min

    • max

    • sum

    • mean

    • median

    • stdev

    • stdevsample

    • range

    • minority

    • majority

    • q1: first quartile

    • q3: third quartile

    • iqr: inter quartile range

    • min_length: minimum string length

    • max_length: maximum string length

    • concatenate: join strings with a concatenator

    • concatenate_unique: join unique strings with a concatenator

    • collect: create an aggregated multipart geometry

    • 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.

Példák

  • relation_aggregate(relation:='my_relation',aggregate:='mean',expression:="passengers") → 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:=',') → 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

Further reading: Creating one or many to many relations

13.2.1.22. stdev

Returns the aggregate standard deviation value from a field or expression.

Szintaxis

stdev(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • stdev("population",group_by:="state") → standard deviation of population value, grouped by state field

13.2.1.23. sum

Returns the aggregate summed value from a field or expression.

Szintaxis

sum(expression, [group_by], [filter])

[] marks optional arguments

Argumentumok

  • expression - sub expression of field to aggregate

  • group_by - optional expression to use to group aggregate calculations

  • filter - optional expression to use to filter features used to calculate aggregate

Példák

  • sum("population",group_by:="state") → summed population value, grouped by state field

13.2.2. Array Functions

This group contains functions to create and manipulate arrays (also known as list data structures). The order of values within the array matters, unlike the «map» data structure, where the order of key-value pairs is irrelevant and values are identified by their keys.

13.2.2.1. array

Returns an array containing all the values passed as parameter.

Szintaxis

array(value1, value2, …)

Argumentumok

  • value - a value

Példák

  • array(2,10) → [ 2, 10 ]

  • array(2,10)[0] → 2

13.2.2.2. array_all

Returns TRUE if an array contains all the values of a given array.

Szintaxis

array_all(array_a, array_b)

Argumentumok

  • array_a - an array

  • array_b - the array of values to search

Példák

  • array_all(array(1,2,3),array(2,3)) → TRUE

  • array_all(array(1,2,3),array(1,2,4)) → FALSE

13.2.2.3. array_append

Returns an array with the given value added at the end.

Szintaxis

array_append(array, value)

Argumentumok

  • array - an array

  • value - the value to add

Példák

  • array_append(array(1,2,3),4) → [ 1, 2, 3, 4 ]

13.2.2.4. array_cat

Returns an array containing all the given arrays concatenated.

Szintaxis

array_cat(array1, array2, …)

Argumentumok

  • array - an array

Példák

  • array_cat(array(1,2),array(2,3)) → [ 1, 2, 2, 3 ]

13.2.2.5. array_contains

Returns TRUE if an array contains the given value.

Szintaxis

array_contains(array, value)

Argumentumok

  • array - an array

  • value - the value to search

Példák

  • array_contains(array(1,2,3),2) → TRUE

13.2.2.6. array_count

Counts the number of occurrences of a given value in an array.

Szintaxis

array_count(array, value)

Argumentumok

  • array - an array

  • value - the value to count

Példák

  • array_count(array('a', 'b', 'c', 'b'), 'b') → 2

13.2.2.7. array_distinct

Returns an array containing distinct values of the given array.

Szintaxis

array_distinct(array)

Argumentumok

  • array - an array

Példák

  • array_distinct(array(1,2,3,2,1)) → [ 1, 2, 3 ]

13.2.2.8. array_filter

Returns an array with only the items for which the expression evaluates to true.

Szintaxis

array_filter(array, expression, [limit=0])

[] marks optional arguments

Argumentumok

  • array - an array

  • expression - an expression to evaluate on each item. The variable @element will be replaced by the current value.

  • limit - maximum number of elements to be returned. Use 0 to return all values.

Példák

  • array_filter(array(1,2,3),@element < 3) → [ 1, 2 ]

  • array_filter(array(1,2,3),@element < 3, 1) → [ 1 ]

13.2.2.9. array_find

Returns the lowest index (0 for the first one) of a value within an array. Returns -1 if the value is not found.

Szintaxis

array_find(array, value)

Argumentumok

  • array - an array

  • value - the value to search

Példák

  • array_find(array('a', 'b', 'c'), 'b') → 1

  • array_find(array('a', 'b', 'c', 'b'), 'b') → 1

13.2.2.10. array_first

Returns the first value of an array.

Szintaxis

array_first(array)

Argumentumok

  • array - an array

Példák

  • array_first(array('a','b','c')) → «a»

13.2.2.11. array_foreach

Returns an array with the given expression evaluated on each item.

Szintaxis

array_foreach(array, expression)

Argumentumok

  • array - an array

  • expression - an expression to evaluate on each item. The variable @element will be replaced by the current value.

Példák

  • array_foreach(array('a','b','c'),upper(@element)) → [ «A», «B», «C» ]

  • array_foreach(array(1,2,3),@element + 10) → [ 11, 12, 13 ]

13.2.2.12. array_get

Returns the Nth value (0 for the first one) or the last -Nth value (-1 for the last one) of an array.

Szintaxis

array_get(array, pos)

Argumentumok

  • array - an array

  • pos - the index to get (0 based)

Példák

  • array_get(array('a','b','c'),1) → «b»

  • array_get(array('a','b','c'),-1) → «c»

Tipp

You can also use the index operator ([]) to get a value from an array.

13.2.2.13. array_insert

Returns an array with the given value added at the given position.

Szintaxis

array_insert(array, pos, value)

Argumentumok

  • array - an array

  • pos - the position where to add (0 based)

  • value - the value to add

Példák

  • array_insert(array(1,2,3),1,100) → [ 1, 100, 2, 3 ]

13.2.2.14. array_intersect

Returns TRUE if at least one element of array1 exists in array2.

Szintaxis

array_intersect(array1, array2)

Argumentumok

  • array1 - an array

  • array2 - another array

Példák

  • array_intersect(array(1,2,3,4),array(4,0,2,5)) → TRUE

13.2.2.15. array_last

Returns the last value of an array.

Szintaxis

array_last(array)

Argumentumok

  • array - an array

Példák

  • array_last(array('a','b','c')) → «c»

13.2.2.16. array_length

Returns the number of elements of an array.

Szintaxis

array_length(array)

Argumentumok

  • array - an array

Példák

  • array_length(array(1,2,3)) → 3

13.2.2.17. array_majority

Returns the most common values in an array.

Szintaxis

array_majority(array, [option=»all»])

[] marks optional arguments

Argumentumok

  • array - an array

  • option=»all» - a string specifying the return values handling. Valid options are:

    • all: Default, all most common values are returned in an array.

    • any: Returns one of the most common values.

    • median: Returns the median of the most common values. Non arithmetic values are ignored.

    • real_majority: Returns the value which occurs more than half the size of the array.

Példák

  • 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

  • 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

13.2.2.18. array_max

Returns the maximum value of an array.

Szintaxis

array_max(array)

Argumentumok

  • array - an array

Példák

  • array_max(array(0,42,4,2)) → 42

13.2.2.19. array_mean

Returns the mean of arithmetic values in an array. Non numeric values in the array are ignored.

Szintaxis

array_mean(array)

Argumentumok

  • array - an array

Példák

  • array_mean(array(0,1,7,66.6,135.4)) → 42

  • array_mean(array(0,84,'a','b','c')) → 42

13.2.2.20. array_median

Returns the median of arithmetic values in an array. Non arithmetic values in the array are ignored.

Szintaxis

array_median(array)

Argumentumok

  • array - an array

Példák

  • array_median(array(0,1,42,42,43)) → 42

  • array_median(array(0,1,2,42,'a','b')) → 1.5

13.2.2.21. array_min

Returns the minimum value of an array.

Szintaxis

array_min(array)

Argumentumok

  • array - an array

Példák

  • array_min(array(43,42,54)) → 42

13.2.2.22. array_minority

Returns the less common values in an array.

Szintaxis

array_minority(array, [option=»all»])

[] marks optional arguments

Argumentumok

  • array - an array

  • option=»all» - a string specifying the return values handling. Valid options are:

    • all: Default, all less common values are returned in an array.

    • any: Returns one of the less common values.

    • median: Returns the median of the less common values. Non arithmetic values are ignored.

    • real_minority: Returns values which occur less than half the size of the array.

Példák

  • 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

  • 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 ]

13.2.2.23. array_prepend

Returns an array with the given value added at the beginning.

Szintaxis

array_prepend(array, value)

Argumentumok

  • array - an array

  • value - the value to add

Példák

  • array_prepend(array(1,2,3),0) → [ 0, 1, 2, 3 ]

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.

Szintaxis

array_prioritize(array, array_prioritize)

Argumentumok

  • array - an array

  • array_prioritize - an array with values ordered by priority

Példák

  • array_prioritize(array(1, 8, 2, 5), array(5, 4, 2, 1, 3, 8)) → [ 5, 2, 1, 8 ]

  • array_prioritize(array(5, 4, 2, 1, 3, 8), array(1, 8, 6, 5)) → [ 1, 8, 5, 4, 2, 3 ]

13.2.2.25. array_remove_all

Returns an array with all the entries of the given value removed.

Szintaxis

array_remove_all(array, value)

Argumentumok

  • array - an array

  • value - the values to remove

Példák

  • array_remove_all(array('a','b','c','b'),'b') → [ «a», «c» ]

13.2.2.26. array_remove_at

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.

Szintaxis

array_remove_at(array, pos)

Argumentumok

  • array - an array

  • pos - the position to remove (0 based)

Példák

  • array_remove_at(array(1, 2, 3), 1) → [1, 3 ]

  • array_remove_at(array(1, 2, 3), -1) → [1, 2 ]

13.2.2.27. array_replace

Returns an array with the supplied value, array, or map of values replaced.

Value & array variant

Returns an array with the supplied value or array of values replaced by another value or an array of values.

Szintaxis

array_replace(array, before, after)

Argumentumok

  • array - the input array

  • before - the value or array of values to replace

  • after - the value or array of values to use as a replacement

Példák

  • array_replace(array('QGIS','SHOULD','ROCK'),'SHOULD','DOES') → [ «QGIS», «DOES», «ROCK» ]

  • array_replace(array(3,2,1),array(1,2,3),array(7,8,9)) → [ 9, 8, 7 ]

  • array_replace(array('Q','G','I','S'),array('Q','S'),'-') → [ «-», «G», «I», «-» ]

Map variant

Returns an array with the supplied map keys replaced by their paired values.

Szintaxis

array_replace(array, map)

Argumentumok

  • array - the input array

  • map - the map containing keys and values

Példák

  • array_replace(array('APP', 'SHOULD', 'ROCK'),map('APP','QGIS','SHOULD','DOES')) → [ «QGIS», «DOES», «ROCK» ]

13.2.2.28. array_reverse

Returns the given array with array values in reversed order.

Szintaxis

array_reverse(array)

Argumentumok

  • array - an array

Példák

  • array_reverse(array(2,4,0,10)) → [ 10, 0, 4, 2 ]

13.2.2.29. array_slice

Returns a portion of the array. The slice is defined by the start_pos and end_pos arguments.

Szintaxis

array_slice(array, start_pos, end_pos)

Argumentumok

  • array - an array

  • start_pos - the index of the start position of the slice (0 based). The start_pos index is included in the slice. If you use a negative start_pos, the index is counted from the end of the list (-1 based).

  • end_pos - the index of the end position of the slice (0 based). The end_pos index is included in the slice. If you use a negative end_pos, the index is counted from the end of the list (-1 based).

Példák

  • 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 ]

  • 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» ]

13.2.2.30. array_sort

Returns the provided array with its elements sorted.

Szintaxis

array_sort(array, [ascending=true])

[] marks optional arguments

Argumentumok

  • array - an array

  • ascending - set this parameter to false to sort the array in descending order

Példák

  • array_sort(array(3,2,1)) → [ 1, 2, 3 ]

13.2.2.31. array_sum

Returns the sum of arithmetic values in an array. Non numeric values in the array are ignored.

Szintaxis

array_sum(array)

Argumentumok

  • array - an array

Példák

  • array_sum(array(0,1,39.4,1.6,'a')) → 42.0

13.2.2.32. array_to_string

Concatenates array elements into a string separated by a delimiter and using optional string for empty values.

Szintaxis

array_to_string(array, [delimiter=»,»], [empty_value=»»])

[] marks optional arguments

Argumentumok

  • array - the input array

  • delimiter - the string delimiter used to separate concatenated array elements

  • empty_value - the optional string to use as replacement for empty (zero length) matches

Példák

  • array_to_string(array('1','2','3')) → «1,2,3»

  • array_to_string(array(1,2,3),'-') → «1-2-3»

  • array_to_string(array('1','','3'),',','0') → «1,0,3»

13.2.2.33. generate_series

Creates an array containing a sequence of numbers.

Szintaxis

generate_series(start, stop, [step=1])

[] marks optional arguments

Argumentumok

  • start - first value of the sequence

  • stop - value that ends the sequence once reached

  • step - value used as the increment between values

Példák

  • generate_series(1,5) → [ 1, 2, 3, 4, 5 ]

  • generate_series(5,1,-1) → [ 5, 4, 3, 2, 1 ]

13.2.2.34. geometries_to_array

Splits a geometry into simpler geometries in an array.

Szintaxis

geometries_to_array(geometry)

Argumentumok

  • geometry - the input geometry

Példák

  • geometries_to_array(geom_from_wkt('GeometryCollection (Polygon ((5 8, 4 1, 3 2, 5 8)),LineString (3 2, 4 2))')) → an array of a polygon and a line geometries

  • geom_to_wkt(geometries_to_array(geom_from_wkt('GeometryCollection (Polygon ((5 8, 4 1, 3 2, 5 8)),LineString (3 2, 4 2))'))[0]) → «Polygon ((5 8, 4 1, 3 2, 5 8))»

  • geometries_to_array(geom_from_wkt('MULTIPOLYGON(((5 5,0 0,0 10,5 5)),((5 5,10 10,10 0,5 5))')) → an array of two polygon geometries

13.2.2.35. regexp_matches

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.

Szintaxis

regexp_matches(string, regex, [empty_value=»»])

[] marks optional arguments

Argumentumok

  • string - the string to capture groups from against the regular expression

  • regex - the regular expression used to capture groups

  • empty_value - the optional string to use as replacement for empty (zero length) matches

Példák

  • regexp_matches('QGIS=>rocks','(.*)=>(.*)') → [ «QGIS», «rocks» ]

  • regexp_matches('key=>','(.*)=>(.*)','empty value') → [ «key», «empty value» ]

13.2.2.36. string_to_array

Splits string into an array using supplied delimiter and optional string for empty values.

Szintaxis

string_to_array(string, [delimiter=»,»], [empty_value=»»])

[] marks optional arguments

Argumentumok

  • string - the input string

  • delimiter - the string delimiter used to split the input string

  • empty_value - the optional string to use as replacement for empty (zero length) matches

Példák

  • string_to_array('1,2,3',',') → [ «1», «2», «3» ]

  • string_to_array('1,,3',',','0') → [ «1», «0», «3» ]

13.2.3. Color Functions

This group contains functions for manipulating colors.

13.2.3.1. color_cmyk

Returns a string representation of a color based on its cyan, magenta, yellow and black components

Szintaxis

color_cmyk(cyan, magenta, yellow, black)

Argumentumok

  • cyan - cyan component of the color, as a percentage integer value from 0 to 100

  • magenta - magenta component of the color, as a percentage integer value from 0 to 100

  • yellow - yellow component of the color, as a percentage integer value from 0 to 100

  • black - black component of the color, as a percentage integer value from 0 to 100

Példák

  • color_cmyk(100,50,0,10) → «0,115,230»

13.2.3.2. color_cmyka

Returns a string representation of a color based on its cyan, magenta, yellow, black and alpha (transparency) components

Szintaxis

color_cmyka(cyan, magenta, yellow, black, alpha)

Argumentumok

  • cyan - cyan component of the color, as a percentage integer value from 0 to 100

  • magenta - magenta component of the color, as a percentage integer value from 0 to 100

  • yellow - yellow component of the color, as a percentage integer value from 0 to 100

  • black - black component of the color, as a percentage integer value from 0 to 100

  • alpha - alpha component as an integer value from 0 (completely transparent) to 255 (opaque).

Példák

  • color_cmyka(100,50,0,10,200) → «0,115,230,200»

13.2.3.3. color_grayscale_average

Applies a grayscale filter and returns a string representation from a provided color.

Szintaxis

color_grayscale_average(color)

Argumentumok

  • color - a color string

Példák

  • color_grayscale_average('255,100,50') → «135,135,135,255»

13.2.3.4. color_hsl

Returns a string representation of a color based on its hue, saturation, and lightness attributes.

Szintaxis

color_hsl(hue, saturation, lightness)

Argumentumok

  • hue - hue of the color, as an integer value from 0 to 360

  • saturation - saturation percentage of the color as an integer value from 0 to 100

  • lightness - lightness percentage of the color as an integer value from 0 to 100

Példák

  • color_hsl(100,50,70) → «166,217,140»

13.2.3.5. color_hsla

Returns a string representation of a color based on its hue, saturation, lightness and alpha (transparency) attributes

Szintaxis

color_hsla(hue, saturation, lightness, alpha)

Argumentumok

  • hue - hue of the color, as an integer value from 0 to 360

  • saturation - saturation percentage of the color as an integer value from 0 to 100

  • lightness - lightness percentage of the color as an integer value from 0 to 100

  • alpha - alpha component as an integer value from 0 (completely transparent) to 255 (opaque).

Példák

  • color_hsla(100,50,70,200) → «166,217,140,200»

13.2.3.6. color_hsv

Returns a string representation of a color based on its hue, saturation, and value attributes.

Szintaxis

color_hsv(hue, saturation, value)

Argumentumok

  • hue - hue of the color, as an integer value from 0 to 360

  • saturation - saturation percentage of the color as an integer value from 0 to 100

  • value - value percentage of the color as an integer from 0 to 100

Példák

  • color_hsv(40,100,100) → «255,170,0»

13.2.3.7. color_hsva

Returns a string representation of a color based on its hue, saturation, value and alpha (transparency) attributes.

Szintaxis

color_hsva(hue, saturation, value, alpha)

Argumentumok

  • hue - hue of the color, as an integer value from 0 to 360

  • saturation - saturation percentage of the color as an integer value from 0 to 100

  • value - value percentage of the color as an integer from 0 to 100

  • alpha - alpha component as an integer value from 0 (completely transparent) to 255 (opaque)

Példák

  • color_hsva(40,100,100,200) → «255,170,0,200»

13.2.3.8. color_mix_rgb

Returns a string representing a color mixing the red, green, blue, and alpha values of two provided colors based on a given ratio.

Szintaxis

color_mix_rgb(color1, color2, ratio)

Argumentumok

  • color1 - a color string

  • color2 - a color string

  • ratio - a ratio

Példák

  • color_mix_rgb('0,0,0','255,255,255',0.5) → «127,127,127,255»

13.2.3.9. color_part

Returns a specific component from a color string, e.g., the red component or alpha component.

Szintaxis

color_part(color, component)

Argumentumok

  • color - a color string

  • component - a string corresponding to the color component to return. Valid options are:

    • red: RGB red component (0-255)

    • green: RGB green component (0-255)

    • blue: RGB blue component (0-255)

    • alpha: alpha (transparency) value (0-255)

    • hue: HSV hue (0-360)

    • saturation: HSV saturation (0-100)

    • value: HSV value (0-100)

    • hsl_hue: HSL hue (0-360)

    • hsl_saturation: HSL saturation (0-100)

    • lightness: HSL lightness (0-100)

    • cyan: CMYK cyan component (0-100)

    • magenta: CMYK magenta component (0-100)

    • yellow: CMYK yellow component (0-100)

    • black: CMYK black component (0-100)

Példák

  • color_part('200,10,30','green') → 10

13.2.3.10. color_rgb

Returns a string representation of a color based on its red, green, and blue components.

Szintaxis

color_rgb(red, green, blue)

Argumentumok

  • red - red component as an integer value from 0 to 255

  • green - green component as an integer value from 0 to 255

  • blue - blue component as an integer value from 0 to 255

Példák

  • color_rgb(255,127,0) → «255,127,0»

13.2.3.11. color_rgba

Returns a string representation of a color based on its red, green, blue, and alpha (transparency) components.

Szintaxis

color_rgba(red, green, blue, alpha)

Argumentumok

  • red - red component as an integer value from 0 to 255

  • green - green component as an integer value from 0 to 255

  • blue - blue component as an integer value from 0 to 255

  • alpha - alpha component as an integer value from 0 (completely transparent) to 255 (opaque).

Példák

  • color_rgba(255,127,0,200) → «255,127,0,200»

13.2.3.12. create_ramp

Returns a gradient ramp from a map of color strings and steps.

Szintaxis

create_ramp(map, [discrete=false])

[] marks optional arguments

Argumentumok

  • map - a map of color strings and steps

  • discrete - set this parameter to true to create a discrete color ramp

Példák

  • ramp_color(create_ramp(map(0,'0,0,0',1,'255,0,0')),1) → «255,0,0,255»

13.2.3.13. darker

Returns a darker (or lighter) color string

Szintaxis

darker(color, factor)

Argumentumok

  • color - a color string

  • factor - an integer corresponding to the darkening factor:

    • if the factor is greater than 100, this function returns a darker color (e.g., setting factor to 200 returns a color that is half the brightness);

    • if the factor is less than 100, the return color is lighter, but using the lighter() function for this purpose is recommended;

    • if the factor is 0 or negative, the return value is unspecified.

Példák

  • darker('200,10,30', 200) → «100,5,15,255»

Further reading: lighter

13.2.3.14. lighter

Returns a lighter (or darker) color string

Szintaxis

lighter(color, factor)

Argumentumok

  • color - a color string

  • factor - an integer corresponding to the lightening factor:

    • if the factor is greater than 100, this function returns a lighter color (e.g., setting factor to 150 returns a color that is 50% brighter);

    • if the factor is less than 100, the return color is darker, but using the darker() function for this purpose is recommended;

    • if the factor is 0 or negative, the return value is unspecified.

Példák

  • lighter('200,10,30', 200) → «255,158,168,255»

Further reading: darker

13.2.3.15. project_color

Returns a color from the project’s color scheme.

Szintaxis

project_color(name)

Argumentumok

  • name - a color name

Példák

  • project_color('Logo color') → «20,140,50»

Further reading: setting project colors

13.2.3.16. ramp_color

Returns a string representing a color from a color ramp.

Saved ramp variant

Returns a string representing a color from a saved ramp

Szintaxis

ramp_color(ramp_name, value)

Argumentumok

  • ramp_name - the name of the color ramp as a string, for example «Spectral»

  • value - the position on the ramp to select the color from as a real number between 0 and 1

Példák

  • ramp_color('Spectral',0.3) → «253,190,115,255»

Megjegyzés

The color ramps available vary between QGIS installations. This function may not give the expected results if you move your QGIS project between installations.

Expression-created ramp variant

Returns a string representing a color from an expression-created ramp

Szintaxis

ramp_color(ramp, value)

Argumentumok

  • ramp - the color ramp

  • value - the position on the ramp to select the color from as a real number between 0 and 1

Példák

  • ramp_color(create_ramp(map(0,'0,0,0',1,'255,0,0')),1) → «255,0,0,255»

Further reading: Színskála beállítása, A legördülő színskála gyors gomb

13.2.3.17. set_color_part

Sets a specific color component for a color string, e.g., the red component or alpha component.

Szintaxis

set_color_part(color, component, value)

Argumentumok

  • color - a color string

  • component - a string corresponding to the color component to set. Valid options are:

    • red: RGB red component (0-255)

    • green: RGB green component (0-255)

    • blue: RGB blue component (0-255)

    • alpha: alpha (transparency) value (0-255)

    • hue: HSV hue (0-360)

    • saturation: HSV saturation (0-100)

    • value: HSV value (0-100)

    • hsl_hue: HSL hue (0-360)

    • hsl_saturation: HSL saturation (0-100)

    • lightness: HSL lightness (0-100)

    • cyan: CMYK cyan component (0-100)

    • magenta: CMYK magenta component (0-100)

    • yellow: CMYK yellow component (0-100)

    • black: CMYK black component (0-100)

  • value - new value for color component, respecting the ranges listed above

Példák

  • set_color_part('200,10,30','green',50) → «200,50,30,255»

13.2.4. Conditional Functions

This group contains functions to handle conditional checks in expressions.

13.2.4.1. CASE

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

WHEN condition THEN result

[ …n ]

[ ELSE result ]

END

[ ] marks optional components

Argumentumok

  • WHEN condition - A condition expression to evaluate

  • THEN result - If condition evaluates to True then result is evaluated and returned.

  • ELSE result - If none of the above conditions evaluated to True then result is evaluated and returned.

Példák

  • 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 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

13.2.4.2. coalesce

Returns the first non-NULL value from the expression list.

This function can take any number of arguments.

Szintaxis

coalesce(expression1, expression2, …)

Argumentumok

  • expression - any valid expression or value, regardless of type.

Példák

  • coalesce(NULL, 2) → 2

  • coalesce(NULL, 2, 3) → 2

  • coalesce(7, NULL, 3*2) → 7

  • 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

13.2.4.3. if

Tests a condition and returns a different result depending on the conditional check.

Szintaxis

if(condition, result_when_true, result_when_false)

Argumentumok

  • condition - the condition which should be checked

  • result_when_true - the result which will be returned when the condition is true or another value that does not convert to false.

  • result_when_false - the result which will be returned when the condition is false or another value that converts to false like 0 or «». NULL will also be converted to false.

Példák

  • if( 1+1=2, 'Yes', 'No' ) → «Yes»

  • if( 1+1=3, 'Yes', 'No' ) → «No»

  • if( 5 > 3, 1, 0) → 1

  • if( '', 'It is true (not empty)', 'It is false (empty)' ) → «It is false (empty)»

  • if( ' ', 'It is true (not empty)', 'It is false (empty)' ) → «It is true (not empty)»

  • if( 0, 'One', 'Zero' ) → «Zero»

  • if( 10, 'One', 'Zero' ) → «One»

13.2.4.4. nullif

Returns a NULL value if value1 equals value2; otherwise it returns value1. This can be used to conditionally substitute values with NULL.

Szintaxis

nullif(value1, value2)

Argumentumok

  • value1 - The value that should either be used or substituted with NULL.

  • value2 - The control value that will trigger the NULL substitution.

Példák

  • nullif('(none)', '(none)') → NULL

  • nullif('text', '(none)') → «text»

  • nullif("name", '') → NULL, if name is an empty string (or already NULL), the name in any other case.

13.2.4.5. regexp_match

Return the first matching position matching a regular expression within an unicode string, or 0 if the substring is not found.

Szintaxis

regexp_match(input_string, regex)

Argumentumok

  • input_string - the string to test against the regular expression

  • regex - The regular expression to test against. Backslash characters must be double escaped (e.g., „\\s” to match a white space character or „\\b” to match a word boundary).

Példák

  • regexp_match('QGIS ROCKS','\\sROCKS') → 5

  • regexp_match('Budač','udač\\b') → 2

13.2.4.6. try

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.

Szintaxis

try(expression, [alternative])

[] marks optional arguments

Argumentumok

  • expression - the expression which should be run

  • alternative - the result which will be returned if the expression returns an error.

Példák

  • try( to_int( '1' ), 0 ) → 1

  • try( to_int( 'a' ), 0 ) → 0

  • try( to_date( 'invalid_date' ) ) → NULL

13.2.5. Conversions Functions

This group contains functions to convert one data type to another (e.g., string from/to integer, binary from/to string, string to date, …).

13.2.5.1. from_base64

Decodes a string in the Base64 encoding into a binary value.

Szintaxis

from_base64(string)

Argumentumok

  • string - the string to decode

Példák

  • from_base64('UUdJUw==') → «QGIS»

13.2.5.2. hash

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.

Szintaxis

hash(string, method)

Argumentumok

  • string - the string to hash

  • method - The hash method among «md4», «md5», «sha1», «sha224», «sha384», «sha512», «sha3_224», «sha3_256», «sha3_384», «sha3_512», «keccak_224», «keccak_256», «keccak_384», «keccak_512»

Példák

  • hash('QGIS', 'md4') → «c0fc71c241cdebb6e888cbac0e2b68eb»

  • hash('QGIS', 'md5') → «57470aaa9e22adaefac7f5f342f1c6da»

  • hash('QGIS', 'sha1') → «f87cfb2b74cdd5867db913237024e7001e62b114»

  • hash('QGIS', 'sha224') → «4093a619ada631c770f44bc643ead18fb393b93d6a6af1861fcfece0»

  • hash('QGIS', 'sha256') → «eb045cba7a797aaa06ac58830846e40c8e8c780bc0676d3393605fae50c05309»

  • hash('QGIS', 'sha384') → «91c1de038cc3d09fdd512e99f9dd9922efadc39ed21d3922e69a4305cc25506033aee388e554b78714c8734f9cd7e610»

  • hash('QGIS', 'sha512') → «c2c092f2ab743bf8edbeb6d028a745f30fc720408465ed369421f0a4e20fa5e27f0c90ad72d3f1d836eaa5d25cd39897d4cf77e19984668ef58da6e3159f18ac»

  • hash('QGIS', 'sha3_224') → «467f49a5039e7280d5d42fd433e80d203439e338eaabd701f0d6c17d»

  • hash('QGIS', 'sha3_256') → «540f7354b6b8a6e735f2845250f15f4f3ba4f666c55574d9e9354575de0e980f»

  • hash('QGIS', 'sha3_384') → «96052da1e77679e9a65f60d7ead961b287977823144786386eb43647b0901fd8516fa6f1b9d243fb3f28775e6dde6107»

  • hash('QGIS', 'sha3_512') → «900d079dc69761da113980253aa8ac0414a8bd6d09879a916228f8743707c4758051c98445d6b8945ec854ff90655005e02aceb0a2ffc6a0ebf818745d665349»

  • hash('QGIS', 'keccak_224') → «5b0ce6acef8b0a121d4ac4f3eaa8503c799ad4e26a3392d1fb201478»

  • hash('QGIS', 'keccak_256') → «991c520aa6815392de24087f61b2ae0fd56abbfeee4a8ca019c1011d327c577e»

  • hash('QGIS', 'keccak_384') → «c57a3aed9d856fa04e5eeee9b62b6e027cca81ba574116d3cc1f0d48a1ef9e5886ff463ea8d0fac772ee473bf92f810d»

13.2.5.3. md5

Creates a md5 hash from a string.

Szintaxis

md5(string)

Argumentumok

  • string - the string to hash

Példák

  • md5('QGIS') → «57470aaa9e22adaefac7f5f342f1c6da»

13.2.5.4. sha256

Creates a sha256 hash from a string.

Szintaxis

sha256(string)

Argumentumok

  • string - the string to hash

Példák

  • sha256('QGIS') → «eb045cba7a797aaa06ac58830846e40c8e8c780bc0676d3393605fae50c05309»

13.2.5.5. to_base64

Encodes a binary value into a string, using the Base64 encoding.

Szintaxis

to_base64(value)

Argumentumok

  • value - the binary value to encode

Példák

  • to_base64('QGIS') → «UUdJUw==»

13.2.5.6. to_date

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.

Szintaxis

to_date(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a date value

  • format - format used to convert the string into a date

  • 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.

Példák

  • 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 «June» for the sixth month, otherwise an error occurs

  • to_date('29 juin, 2019','d MMMM, yyyy','fr') → 2019-06-29

13.2.5.7. to_datetime

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.

Szintaxis

to_datetime(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a datetime value

  • format - format used to convert the string into a datetime

  • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the string into a datetime. By default the current QGIS user locale is used.

Példák

  • to_datetime('2012-05-04 12:50:00') → 2012-05-04T12:50:00

  • to_datetime('June 29, 2019 @ 12:34','MMMM d, yyyy @ HH:mm') → 2019-06-29T12:34, if the current locale uses the name «June» for the sixth month, otherwise an error occurs

  • to_datetime('29 juin, 2019 @ 12:34','d MMMM, yyyy @ HH:mm','fr') → 2019-06-29T12:34

13.2.5.8. to_decimal

Converts a degree, minute, second coordinate to its decimal equivalent.

Szintaxis

to_decimal(value)

Argumentumok

  • value - A degree, minute, second string.

Példák

  • to_decimal('6°21\'16.445') → 6.3545680555

13.2.5.9. to_dm

Converts a coordinate to degree, minute.

Szintaxis

to_dm(coordinate, axis, precision, [formatting=])

[] marks optional arguments

Argumentumok

  • coordinate - A latitude or longitude value.

  • axis - The axis of the coordinate. Either «x» or «y».

  • precision - Number of decimals.

  • formatting - Designates the formatting type. Acceptable values are NULL (default), «aligned» or «suffix».

Példák

  • to_dm(6.1545681, 'x', 3) → 6°9.274′

  • to_dm(6.1545681, 'y', 4, 'aligned') → 6°09.2741′N

  • to_dm(6.1545681, 'y', 4, 'suffix') → 6°9.2741′N

13.2.5.10. to_dms

Converts a coordinate to degree, minute, second.

Szintaxis

to_dms(coordinate, axis, precision, [formatting=])

[] marks optional arguments

Argumentumok

  • coordinate - A latitude or longitude value.

  • axis - The axis of the coordinate. Either «x» or «y».

  • precision - Number of decimals.

  • formatting - Designates the formatting type. Acceptable values are NULL (default), «aligned» or «suffix».

Példák

  • to_dms(6.1545681, 'x', 3) → 6°9′16.445″

  • to_dms(6.1545681, 'y', 4, 'aligned') → 6°09′16.4452″N

  • to_dms(6.1545681, 'y', 4, 'suffix') → 6°9′16.4452″N

13.2.5.11. to_int

Converts a string to integer number. Nothing is returned if a value cannot be converted to integer (e.g «123asd» is invalid).

Szintaxis

to_int(string)

Argumentumok

  • string - string to convert to integer number

Példák

  • to_int('123') → 123

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.

Szintaxis

to_interval(string)

Argumentumok

  • string - a string representing an interval. Allowable formats include {n} days {n} hours {n} months.

Példák

  • to_interval('1 day 2 hours') → interval: 1.08333 days

  • to_interval( '0.5 hours' ) → interval: 30 minutes

  • to_datetime('2012-05-05 12:00:00') - to_interval('1 day 2 hours') → 2012-05-04T10:00:00

13.2.5.13. to_real

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.

Szintaxis

to_real(string)

Argumentumok

  • string - string to convert to real number

Példák

  • to_real('123.45') → 123.45

13.2.5.14. to_string

Converts a number to string.

Szintaxis

to_string(number)

Argumentumok

  • number - Integer or real value. The number to convert to string.

Példák

  • to_string(123) → «123»

13.2.5.15. to_time

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.

Szintaxis

to_time(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a time value

  • format - format used to convert the string into a time

  • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the string into a time

Példák

  • to_time('12:30:01') → 12:30:01

  • to_time('12:34','HH:mm') → 12:34:00

  • to_time('12:34','HH:mm','fr') → 12:34:00

13.2.6. Custom Functions

This group contains functions created by the user. See Függvényszerkesztő for more details.

13.2.7. Date and Time Functions

This group contains functions for handling date and time data. This group shares several functions with the Conversions Functions (to_date, to_time, to_datetime, to_interval) and String Functions (format_date) groups.

Megjegyzés

Storing date, datetime and intervals on fields

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)

13.2.7.1. age

Returns the difference between two dates or datetimes.

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

Szintaxis

age(datetime1, datetime2)

Argumentumok

  • datetime1 - a string, date or datetime representing the later date

  • datetime2 - a string, date or datetime representing the earlier date

Példák

  • day(age('2012-05-12','2012-05-02')) → 10

  • hour(age('2012-05-12','2012-05-02')) → 240

13.2.7.2. datetime_from_epoch

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.

Szintaxis

datetime_from_epoch(int)

Argumentumok

  • int - number (milliseconds)

Példák

  • datetime_from_epoch(1483225200000) → 2017-01-01T00:00:00

13.2.7.3. day

Extracts the day from a date, or the number of days from an interval.

Date variant

Extracts the day from a date or datetime.

Szintaxis

day(date)

Argumentumok

  • date - a date or datetime value

Példák

  • day('2012-05-12') → 12

Interval variant

Calculates the length in days of an interval.

Szintaxis

day(interval)

Argumentumok

  • interval - interval value to return number of days from

Példák

  • day(to_interval('3 days')) → 3

  • day(to_interval('3 weeks 2 days')) → 23

  • day(age('2012-01-01','2010-01-01')) → 730

13.2.7.4. day_of_week

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.

Szintaxis

day_of_week(date)

Argumentumok

  • date - date or datetime value

Példák

  • day_of_week(to_date('2015-09-21')) → 1

13.2.7.5. epoch

Returns the interval in milliseconds between the unix epoch and a given date value.

Szintaxis

epoch(date)

Argumentumok

  • date - a date or datetime value

Példák

  • epoch(to_date('2017-01-01')) → 1483203600000

13.2.7.6. format_date

Formats a date type or string into a custom string format. Uses Qt date/time format strings. See QDateTime::toString.

Szintaxis

format_date(datetime, format, [language])

[] marks optional arguments

Argumentumok

  • datetime - date, time or datetime value

  • format - String template used to format the string.

    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»)

    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.

Példák

  • 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

  • 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»

13.2.7.7. hour

Extracts the hour part from a datetime or time, or the number of hours from an interval.

Time variant

Extracts the hour part from a time or datetime.

Szintaxis

hour(datetime)

Argumentumok

  • datetime - a time or datetime value

Példák

  • hour( to_datetime('2012-07-22 13:24:57') ) → 13

Interval variant

Calculates the length in hours of an interval.

Szintaxis

hour(interval)

Argumentumok

  • interval - interval value to return number of hours from

Példák

  • hour(to_interval('3 hours')) → 3

  • hour(age('2012-07-22T13:00:00','2012-07-22T10:00:00')) → 3

  • hour(age('2012-01-01','2010-01-01')) → 17520

13.2.7.8. make_date

Creates a date value from year, month and day numbers.

Szintaxis

make_date(year, month, day)

Argumentumok

  • year - Year number. Years 1 to 99 are interpreted as is. Year 0 is invalid.

  • month - Month number, where 1=January

  • day - Day number, beginning with 1 for the first day in the month

Példák

  • make_date(2020,5,4) → date value 2020-05-04

13.2.7.9. make_datetime

Creates a datetime value from year, month, day, hour, minute and second numbers.

Szintaxis

make_datetime(year, month, day, hour, minute, second)

Argumentumok

  • year - Year number. Years 1 to 99 are interpreted as is. Year 0 is invalid.

  • month - Month number, where 1=January

  • day - Day number, beginning with 1 for the first day in the month

  • hour - Hour number

  • minute - Minutes

  • second - Seconds (fractional values include milliseconds)

Példák

  • make_datetime(2020,5,4,13,45,30.5) → datetime value 2020-05-04 13:45:30.500

13.2.7.10. make_interval

Creates an interval value from year, month, weeks, days, hours, minute and seconds values.

Szintaxis

make_interval([years=0], [months=0], [weeks=0], [days=0], [hours=0], [minutes=0], [seconds=0])

[] marks optional arguments

Argumentumok

  • years - Number of years (assumes a 365.25 day year length).

  • months - Number of months (assumes a 30 day month length)

  • weeks - Number of weeks

  • days - Number of days

  • hours - Number of hours

  • minutes - Number of minutes

  • seconds - Number of seconds

Példák

  • make_interval(hours:=3) → interval: 3 hours

  • make_interval(days:=2, hours:=3) → interval: 2.125 days

  • make_interval(minutes:=0.5, seconds:=5) → interval: 35 seconds

13.2.7.11. make_time

Creates a time value from hour, minute and second numbers.

Szintaxis

make_time(hour, minute, second)

Argumentumok

  • hour - Hour number

  • minute - Minutes

  • second - Seconds (fractional values include milliseconds)

Példák

  • make_time(13,45,30.5) → time value 13:45:30.500

13.2.7.12. minute

Extracts the minutes part from a datetime or time, or the number of minutes from an interval.

Time variant

Extracts the minutes part from a time or datetime.

Szintaxis

minute(datetime)

Argumentumok

  • datetime - a time or datetime value

Példák

  • minute( to_datetime('2012-07-22 13:24:57') ) → 24

Interval variant

Calculates the length in minutes of an interval.

Szintaxis

minute(interval)

Argumentumok

  • interval - interval value to return number of minutes from

Példák

  • minute(to_interval('3 minutes')) → 3

  • minute(age('2012-07-22T00:20:00','2012-07-22T00:00:00')) → 20

  • minute(age('2012-01-01','2010-01-01')) → 1051200

13.2.7.13. month

Extracts the month part from a date, or the number of months from an interval.

Date variant

Extracts the month part from a date or datetime.

Szintaxis

month(date)

Argumentumok

  • date - a date or datetime value

Példák

  • month('2012-05-12') → 05

Interval variant

Calculates the length in months of an interval.

Szintaxis

month(interval)

Argumentumok

  • interval - interval value to return number of months from

Példák

  • month(to_interval('3 months')) → 3

  • month(age('2012-01-01','2010-01-01')) → 4.03333

13.2.7.14. now

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.

Szintaxis

now()

Példák

  • now() → 2012-07-22T13:24:57

13.2.7.15. second

Extracts the seconds part from a datetime or time, or the number of seconds from an interval.

Time variant

Extracts the seconds part from a time or datetime.

Szintaxis

second(datetime)

Argumentumok

  • datetime - a time or datetime value

Példák

  • second( to_datetime('2012-07-22 13:24:57') ) → 57

Interval variant

Calculates the length in seconds of an interval.

Szintaxis

second(interval)

Argumentumok

  • interval - interval value to return number of seconds from

Példák

  • second(to_interval('3 minutes')) → 180

  • second(age('2012-07-22T00:20:00','2012-07-22T00:00:00')) → 1200

  • second(age('2012-01-01','2010-01-01')) → 63072000

13.2.7.16. to_date

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.

Szintaxis

to_date(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a date value

  • format - format used to convert the string into a date

  • 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.

Példák

  • 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 «June» for the sixth month, otherwise an error occurs

  • to_date('29 juin, 2019','d MMMM, yyyy','fr') → 2019-06-29

13.2.7.17. to_datetime

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.

Szintaxis

to_datetime(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a datetime value

  • format - format used to convert the string into a datetime

  • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the string into a datetime. By default the current QGIS user locale is used.

Példák

  • to_datetime('2012-05-04 12:50:00') → 2012-05-04T12:50:00

  • to_datetime('June 29, 2019 @ 12:34','MMMM d, yyyy @ HH:mm') → 2019-06-29T12:34, if the current locale uses the name «June» for the sixth month, otherwise an error occurs

  • to_datetime('29 juin, 2019 @ 12:34','d MMMM, yyyy @ HH:mm','fr') → 2019-06-29T12:34

13.2.7.18. to_interval

Converts a string to an interval type. Can be used to take days, hours, month, etc of a date.

Szintaxis

to_interval(string)

Argumentumok

  • string - a string representing an interval. Allowable formats include {n} days {n} hours {n} months.

Példák

  • to_interval('1 day 2 hours') → interval: 1.08333 days

  • to_interval( '0.5 hours' ) → interval: 30 minutes

  • to_datetime('2012-05-05 12:00:00') - to_interval('1 day 2 hours') → 2012-05-04T10:00:00

13.2.7.19. to_time

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.

Szintaxis

to_time(string, [format], [language])

[] marks optional arguments

Argumentumok

  • string - string representing a time value

  • format - format used to convert the string into a time

  • language - language (lowercase, two- or three-letter, ISO 639 language code) used to convert the string into a time

Példák

  • to_time('12:30:01') → 12:30:01

  • to_time('12:34','HH:mm') → 12:34:00

  • to_time('12:34','HH:mm','fr') → 12:34:00

13.2.7.20. week

Extracts the week number from a date, or the number of weeks from an interval.

Date variant

Extracts the week number from a date or datetime.

Szintaxis

week(date)

Argumentumok

  • date - a date or datetime value

Példák

  • week('2012-05-12') → 19

Interval variant

Calculates the length in weeks of an interval.

Szintaxis

week(interval)

Argumentumok

  • interval - interval value to return number of months from

Példák

  • week(to_interval('3 weeks')) → 3

  • week(age('2012-01-01','2010-01-01')) → 104.285

13.2.7.21. year

Extracts the year part from a date, or the number of years from an interval.

Date variant

Extracts the year part from a date or datetime.

Szintaxis

year(date)

Argumentumok

  • date - a date or datetime value

Példák

  • year('2012-05-12') → 2012

Interval variant

Calculates the length in years of an interval.

Szintaxis

year(interval)

Argumentumok

  • interval - interval value to return number of years from

Példák

  • year(to_interval('3 years')) → 3

  • 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.

  • Get the number of days until QGIS 3.0 release:

    to_date('2017-09-29') - to_date(now())
    -- Returns <interval: 203 days>
    
  • The same with time:

    to_datetime('2017-09-29 12:00:00') - now()
    -- Returns <interval: 202.49 days>
    
  • Get the datetime of 100 days from now:

    now() + to_interval('100 days')
    -- Returns <datetime: 2017-06-18 01:00:00>
    

13.2.8. Fields and Values

Contains a list of fields from the active layer, and special values. Fields list includes the ones stored in the dataset, virtual and auxiliary ones as well as from joins.

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.

13.2.8.1. NULL

Equates to a NULL value.

Szintaxis

NULL

Példák

  • NULL → a NULL value

Megjegyzés

To test for NULL use an IS NULL or IS NOT NULL expression.

13.2.9. Files and Paths Functions

This group contains functions which manipulate file and path names.

13.2.9.1. base_file_name

Returns the base name of the file without the directory or file suffix.

Szintaxis

base_file_name(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • base_file_name('/home/qgis/data/country_boundaries.shp') → «country_boundaries»

13.2.9.2. exif

Retrieves exif tag values from an image file.

Szintaxis

exif(path, [tag])

[] marks optional arguments

Argumentumok

  • 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.

  • tag - The tag to return. If empty, a map with all exif tag values will be returned.

Példák

  • exif('/my/photo.jpg','Exif.Image.Orientation') → 0

13.2.9.3. file_exists

Returns TRUE if a file path exists.

Szintaxis

file_exists(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • file_exists('/home/qgis/data/country_boundaries.shp') → TRUE

13.2.9.4. file_name

Returns the name of a file (including the file extension), excluding the directory.

Szintaxis

file_name(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • file_name('/home/qgis/data/country_boundaries.shp') → «country_boundaries.shp»

13.2.9.5. file_path

Returns the directory component of a file path. This does not include the file name.

Szintaxis

file_path(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • file_path('/home/qgis/data/country_boundaries.shp') → «/home/qgis/data»

13.2.9.6. file_size

Returns the size (in bytes) of a file.

Szintaxis

file_size(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • file_size('/home/qgis/data/country_boundaries.geojson') → 5674

13.2.9.7. file_suffix

Returns the file suffix (extension) from a file path.

Szintaxis

file_suffix(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • file_suffix('/home/qgis/data/country_boundaries.shp') → «shp»

13.2.9.8. is_directory

Returns TRUE if a path corresponds to a directory.

Szintaxis

is_directory(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • is_directory('/home/qgis/data/country_boundaries.shp') → FALSE

  • is_directory('/home/qgis/data/') → TRUE

13.2.9.9. is_file

Returns TRUE if a path corresponds to a file.

Szintaxis

is_file(path)

Argumentumok

  • path - a file path or a map layer value. If a map layer value is specified then the file source of the layer will be used.

Példák

  • is_file('/home/qgis/data/country_boundaries.shp') → TRUE

  • is_file('/home/qgis/data/') → FALSE

13.2.10. Form Functions

This group contains functions that operate exclusively under the attribute form context. For example, in field’s widgets settings.

13.2.10.1. current_parent_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.

Szintaxis

current_parent_value(field_name)

Argumentumok

  • field_name - a field name in the current parent form

Példák

  • current_parent_value( 'FIELD_NAME' ) → The current value of a field «FIELD_NAME» in the parent form.

13.2.10.2. current_value

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.

Szintaxis

current_value(field_name)

Argumentumok

  • field_name - a field name in the current form or table row

Példák

  • current_value( 'FIELD_NAME' ) → The current value of field «FIELD_NAME».

13.2.11. Fuzzy Matching Functions

This group contains functions for fuzzy comparisons between values.

13.2.11.1. hamming_distance

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.

Szintaxis

hamming_distance(string1, string2)

Argumentumok

  • string1 - a string

  • string2 - a string

Példák

  • hamming_distance('abc','xec') → 2

  • hamming_distance('abc','ABc') → 2

  • hamming_distance(upper('abc'),upper('ABC')) → 0

  • hamming_distance('abc','abcd') → NULL

13.2.11.2. levenshtein

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.

Szintaxis

levenshtein(string1, string2)

Argumentumok

  • string1 - a string

  • string2 - a string

Példák

  • levenshtein('kittens','mitten') → 2

  • levenshtein('Kitten','kitten') → 1

  • levenshtein(upper('Kitten'),upper('kitten')) → 0

13.2.11.3. longest_common_substring

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.

Szintaxis

longest_common_substring(string1, string2)

Argumentumok

  • string1 - a string

  • string2 - a string

Példák

  • longest_common_substring('ABABC','BABCA') → «BABC»

  • longest_common_substring('abcDeF','abcdef') → «abc»

  • longest_common_substring(upper('abcDeF'),upper('abcdex')) → «ABCDE»

13.2.11.4. soundex

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.

Szintaxis

soundex(string)

Argumentumok

  • string - a string

Példák

  • soundex('robert') → «R163»

  • soundex('rupert') → «R163»

  • soundex('rubin') → «R150»

13.2.12. General Functions

This group contains general assorted functions.

13.2.12.1. env

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.

Szintaxis

env(name)

Argumentumok

  • name - The name of the environment variable which should be retrieved.

Példák

  • env( 'LANG' ) → «en_US.UTF-8»

  • env( 'MY_OWN_PREFIX_VAR' ) → «Z:»

  • env( 'I_DO_NOT_EXIST' ) → NULL

13.2.12.2. eval

Evaluates an expression which is passed in a string. Useful to expand dynamic parameters passed as context variables or fields.

Szintaxis

eval(expression)

Argumentumok

  • expression - an expression string

Példák

  • eval('\'nice\'') → «nice»

  • eval(@expression_var) → [whatever the result of evaluating @expression_var might be…]

13.2.12.3. eval_template

Evaluates a template which is passed in a string. Useful to expand dynamic parameters passed as context variables or fields.

Szintaxis

eval_template(template)

Argumentumok

  • template - a template string

Példák

  • eval_template('QGIS [% upper(\'rocks\') %]') → QGIS ROCKS

13.2.12.4. is_layer_visible

Returns TRUE if a specified layer is visible.

Szintaxis

is_layer_visible(layer)

Argumentumok

  • layer - a string, representing either a layer name or layer ID

Példák

  • is_layer_visible('baseraster') → TRUE

13.2.12.5. mime_type

Returns the mime type of the binary data.

Szintaxis

mime_type(bytes)

Argumentumok

  • bytes - the binary data

Példák

  • mime_type('<html><body></body></html>') → text/html

  • mime_type(from_base64('R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAIAOw==')) → image/gif

13.2.12.6. var

Returns the value stored within a specified variable.

Szintaxis

var(name)

Argumentumok

  • name - a variable name

Példák

  • var('qgis_version') → «2.12»

Further reading: List of default variables

13.2.12.7. with_variable

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.

Szintaxis

with_variable(name, value, expression)

Argumentumok

  • name - the name of the variable to set

  • value - the value to set

  • expression - the expression for which the variable will be available

Példák

  • with_variable('my_sum', 1 + 2 + 3, @my_sum * 2 + @my_sum * 5) → 42

13.2.13. Geometry Functions

This group contains functions that operate on geometry objects (e.g. buffer, transform, $area).

13.2.13.1. affine_transform

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.

Szintaxis

affine_transform(geometry, delta_x, delta_y, rotation_z, scale_x, scale_y, [delta_z=0], [delta_m=0], [scale_z=1], [scale_m=1])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • delta_x - x-axis translation

  • delta_y - y-axis translation

  • rotation_z - rotation around z-axis in degrees counter-clockwise

  • scale_x - x-axis scale factor

  • scale_y - y-axis scale factor

  • delta_z - z-axis translation

  • delta_m - m-axis translation

  • scale_z - z-axis scale factor

  • scale_m - m-axis scale factor

Példák

  • 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, -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)»

13.2.13.2. angle_at_vertex

Returns the bisector angle (average angle) to the geometry for a specified vertex on a linestring geometry. Angles are in degrees clockwise from north.

Szintaxis

angle_at_vertex(geometry, vertex)

Argumentumok

  • geometry - a linestring geometry

  • vertex - vertex index, starting from 0; if the value is negative, the selected vertex index will be its total count minus the absolute value

Példák

  • angle_at_vertex(geometry:=geom_from_wkt('LineString(0 0, 10 0, 10 10)'),vertex:=1) → 45.0

13.2.13.3. apply_dash_pattern

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.

Szintaxis

apply_dash_pattern(geometry, pattern, [start_rule=no_rule], [end_rule=no_rule], [adjustment=both], [pattern_offset=0])

[] marks optional arguments

Argumentumok

  • geometry - a geometry (accepts (multi)linestrings or (multi)polygons).

  • pattern - dash pattern, as an array of numbers representing dash and gap lengths. Must contain an even number of elements.

  • start_rule - optional rule for constraining the start of the pattern. Valid values are «no_rule», «full_dash», «half_dash», «full_gap», «half_gap».

  • end_rule - optional rule for constraining the end of the pattern. Valid values are «no_rule», «full_dash», «half_dash», «full_gap», «half_gap».

  • adjustment - optional rule for specifying which part of patterns are adjusted to fit the desired pattern rules. Valid values are «both», «dash», «gap».

  • pattern_offset - Optional distance specifying a specific distance along the pattern to commence at.

Példák

  • geom_to_wkt(apply_dash_pattern(geom_from_wkt('LINESTRING(1 1, 10 1)'), array(3, 1))) → MultiLineString ((1 1, 4 1),(5 1, 8 1),(9 1, 10 1, 10 1))

  • geom_to_wkt(apply_dash_pattern(geom_from_wkt('LINESTRING(1 1, 10 1)'), array(3, 1), start_rule:='half_dash')) → MultiLineString ((1 1, 2.5 1),(3.5 1, 6.5 1),(7.5 1, 10 1, 10 1))

13.2.13.4. $area

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.

Szintaxis

$area

Példák

  • $area → 42

13.2.13.5. area

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.

Szintaxis

area(geometry)

Argumentumok

  • geometry - polygon geometry object

Példák

  • area(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))')) → 8.0

13.2.13.6. azimuth

Returns the north-based azimuth as the angle in radians measured clockwise from the vertical on point_a to point_b.

Szintaxis

azimuth(point_a, point_b)

Argumentumok

  • point_a - point geometry

  • point_b - point geometry

Példák

  • degrees( azimuth( make_point(25, 45), make_point(75, 100) ) ) → 42.273689

  • degrees( azimuth( make_point(75, 100), make_point(25,45) ) ) → 222.273689

13.2.13.7. boundary

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.

Szintaxis

boundary(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • 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)»

  • geom_to_wkt(boundary(geom_from_wkt('LineString(1 1,0 0,-1 1)'))) → «MultiPoint ((1 1),(-1 1))»

Further reading: Boundary algorithm

13.2.13.8. bounds

Returns a geometry which represents the bounding box of an input geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

bounds(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • bounds($geometry) → bounding box of the current feature’s geometry

  • geom_to_wkt(bounds(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))'))) → «Polygon ((-1 0, 1 0, 1 1, -1 1, -1 0))»

../../../_images/bounding_box.png

13.4. ábra Black lines represent the bounding boxes of each polygon feature

Further reading: Bounding boxes algorithm

13.2.13.9. bounds_height

Returns the height of the bounding box of a geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

bounds_height(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • bounds_height($geometry) → height of bounding box of the current feature’s geometry

  • bounds_height(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))')) → 1

13.2.13.10. bounds_width

Returns the width of the bounding box of a geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

bounds_width(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • bounds_width($geometry) → width of bounding box of the current feature’s geometry

  • bounds_width(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))')) → 2

13.2.13.11. buffer

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.

Szintaxis

buffer(geometry, distance, [segments=8], [cap=»round»], [join=»round»], [miter_limit=2])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • distance - buffer distance in layer units

  • segments - number of segments to use to represent a quarter circle when a round join style is used. A larger number results in a smoother buffer with more nodes.

  • cap - end cap style for buffer. Valid values are «round», «flat» or «square»

  • join - join style for buffer. Valid values are «round», «bevel» or «miter».

  • miter_limit - miter distance limit, for use when the join style is set to «miter»

Példák

  • buffer($geometry, 10.5) → polygon of the current feature’s geometry buffered by 10.5 units

../../../_images/buffer1.png

13.5. ábra Buffer (in yellow) of points, line, polygon with positive buffer, and polygon with negative buffer

Further reading: Buffer algorithm

13.2.13.12. buffer_by_m

Creates a buffer along a line geometry where the buffer diameter varies according to the m-values at the line vertices.

Szintaxis

buffer_by_m(geometry, [segments=8])

[] marks optional arguments

Argumentumok

  • geometry - input geometry. Must be a (multi)line geometry with m values.

  • segments - number of segments to approximate quarter-circle curves in the buffer.

Példák

  • 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 linestring geometry.

../../../_images/variable_buffer_m.png

13.6. ábra Buffering line features using the m value on the vertices

Further reading: Variable width buffer (by M value) algorithm

13.2.13.13. centroid

Returns the geometric center of a geometry.

Szintaxis

centroid(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • centroid($geometry) → a point geometry

Further reading: Centroids algorithm

13.2.13.14. close_line

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.

Szintaxis

close_line(geometry)

Argumentumok

  • geometry - a line string geometry

Példák

  • geom_to_wkt(close_line(geom_from_wkt('LINESTRING(0 0, 1 0, 1 1)'))) → «LineString (0 0, 1 0, 1 1, 0 0)»

  • geom_to_wkt(close_line(geom_from_wkt('LINESTRING(0 0, 1 0, 1 1, 0 0)'))) → «LineString (0 0, 1 0, 1 1, 0 0)»

13.2.13.15. closest_point

Returns the point on geometry1 that is closest to geometry2.

Szintaxis

closest_point(geometry1, geometry2)

Argumentumok

  • geometry1 - geometry to find closest point on

  • geometry2 - geometry to find closest point to

Példák

  • geom_to_wkt(closest_point(geom_from_wkt('LINESTRING (20 80, 98 190, 110 180, 50 75 )'),geom_from_wkt('POINT(100 100)'))) → «Point(73.0769 115.384)»

13.2.13.16. collect_geometries

Collects a set of geometries into a multi-part geometry object.

List of arguments variant

Geometry parts are specified as separate arguments to the function.

Szintaxis

collect_geometries(geometry1, geometry2, …)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkt(collect_geometries(make_point(1,2), make_point(3,4), make_point(5,6))) → «MultiPoint ((1 2),(3 4),(5 6))»

Array variant

Geometry parts are specified as an array of geometry parts.

Szintaxis

collect_geometries(array)

Argumentumok

  • array - array of geometry objects

Példák

  • geom_to_wkt(collect_geometries(array(make_point(1,2), make_point(3,4), make_point(5,6)))) → «MultiPoint ((1 2),(3 4),(5 6))»

Further reading: Collect geometries algorithm

13.2.13.17. combine

Returns the combination of two geometries.

Szintaxis

combine(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • geom_to_wkt( combine( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 2 1)' ) ) ) → «MULTILINESTRING((4 4, 2 1), (3 3, 4 4), (4 4, 5 5))»

  • geom_to_wkt( combine( geom_from_wkt( 'LINESTRING(3 3, 4 4)' ), geom_from_wkt( 'LINESTRING(3 3, 6 6, 2 1)' ) ) ) → «LINESTRING(3 3, 4 4, 6 6, 2 1)»

13.2.13.18. concave_hull

Returns a possibly concave polygon that contains all the points in the geometry

Szintaxis

concave_hull(geometry, target_percent, [allow_holes=False])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • target_percent - the percentage of area of the convex hull the solution tries to approach. A target_percent of 1 gives the same result as the convex hull. A target_percent between 0 and 0.99 produces a result that should have a smaller area than the convex hull.

  • allow_holes - optional argument specifying whether to allow holes within the output geometry. Defaults to FALSE, set to TRUE to avoid including holes in the output geometry.

Példák

  • geom_to_wkt(concave_hull(geom_from_wkt('MULTILINESTRING((106 164,30 112,74 70,82 112,130 94,130 62,122 40,156 32,162 76,172 88),(132 178,134 148,128 136,96 128,132 108,150 130,170 142,174 110,156 96,158 90,158 88),(22 64,66 28,94 38,94 68,114 76,112 30,132 10,168 18,178 34,186 52,184 74,190 100,190 122,182 148,178 170,176 184,156 164,146 178,132 186,92 182,56 158,36 150,62 150,76 128,88 118))'), 0.99)) → «Polygon ((30 112, 36 150, 92 182, 132 186, 176 184, 190 122, 190 100, 186 52, 178 34, 168 18, 132 10, 112 30, 66 28, 22 64, 30 112))»

Further reading: convex_hull

13.2.13.19. contains

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.

Szintaxis

contains(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • contains( geom_from_wkt( 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' ), geom_from_wkt( 'POINT(0.5 0.5 )' ) ) → TRUE

  • contains( geom_from_wkt( 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → FALSE

Further reading: overlay_contains

13.2.13.20. convex_hull

Returns the convex hull of a geometry. It represents the minimum convex geometry that encloses all geometries within the set.

Szintaxis

convex_hull(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkt( convex_hull( geom_from_wkt( 'LINESTRING(3 3, 4 4, 4 10)' ) ) ) → «POLYGON((3 3, 4 10, 4 4, 3 3))»

Further reading: concave_hull, Convex hull algorithm

13.2.13.21. crosses

Tests whether a geometry crosses another. Returns TRUE if the supplied geometries have some, but not all, interior points in common.

Szintaxis

crosses(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • crosses( geom_from_wkt( 'LINESTRING(3 5, 4 4, 5 3)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • crosses( geom_from_wkt( 'POINT(4 5)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → FALSE

Further reading: overlay_crosses

13.2.13.22. densify_by_count

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.

Szintaxis

densify_by_count(geometry, vertices)

Argumentumok

  • geometry - a geometry (accepts (multi)linestrings or (multi)polygons).

  • vertices - number of vertices to add (per segment)

Példák

  • geom_to_wkt(densify_by_count(geom_from_wkt('LINESTRING(1 1, 10 1)'), 3)) → LineString (1 1, 3.25 1, 5.5 1, 7.75 1, 10 1)

Further reading: Densify by count algorithm

13.2.13.23. densify_by_distance

Takes a polygon or line layer geometry and generates a new one in which the geometries are densified by adding additional vertices on edges that have a maximum distance of the specified interval distance.

Szintaxis

densify_by_distance(geometry, distance)

Argumentumok

  • geometry - a geometry (accepts (multi)linestrings or (multi)polygons).

  • distance - maximum interval distance between vertices in output geometry

Példák

  • geom_to_wkt(densify_by_distance(geom_from_wkt('LINESTRING(1 1, 10 1)'), 4)) → LineString (1 1, 4 1, 7 1, 10 1)

Further reading: Densify by interval algorithm

13.2.13.24. difference

Returns a geometry that represents that part of geometry1 that does not intersect with geometry2.

Szintaxis

difference(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • geom_to_wkt( difference( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4)' ) ) ) → «LINESTRING(4 4, 5 5)»

Further reading: Difference algorithm

13.2.13.25. disjoint

Tests whether geometries do not spatially intersect. Returns TRUE if the geometries do not share any space together.

Szintaxis

disjoint(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • disjoint( geom_from_wkt( 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0 ))' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • disjoint( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'POINT(4 4)' )) → FALSE

Further reading: overlay_disjoint

13.2.13.26. distance

Returns the minimum distance (based on spatial reference) between two geometries in projected units.

Szintaxis

distance(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • distance( geom_from_wkt( 'POINT(4 4)' ), geom_from_wkt( 'POINT(4 8)' ) ) → 4

13.2.13.27. distance_to_vertex

Returns the distance along the geometry to a specified vertex.

Szintaxis

distance_to_vertex(geometry, vertex)

Argumentumok

  • geometry - a linestring geometry

  • vertex - vertex index, starting from 0; if the value is negative, the selected vertex index will be its total count minus the absolute value

Példák

  • distance_to_vertex(geometry:=geom_from_wkt('LineString(0 0, 10 0, 10 10)'),vertex:=1) → 10.0

13.2.13.28. end_point

Returns the last node from a geometry.

Szintaxis

end_point(geometry)

Argumentumok

  • geometry - geometry object

Példák

  • geom_to_wkt(end_point(geom_from_wkt('LINESTRING(4 0, 4 2, 0 2)'))) → «Point (0 2)»

Further reading: Extract specific vertices algorithm

13.2.13.29. exif_geotag

Creates a point geometry from the exif geotags of an image file.

Szintaxis

exif_geotag(path)

Argumentumok

  • 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.

Példák

  • geom_to_wkt(exif_geotag('/my/photo.jpg')) → «Point (2 4)»

13.2.13.30. extend

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.

Szintaxis

extend(geometry, start_distance, end_distance)

Argumentumok

  • geometry - a (multi)linestring geometry

  • start_distance - distance to extend the start of the line

  • end_distance - distance to extend the end of the line.

Példák

  • geom_to_wkt(extend(geom_from_wkt('LineString(0 0, 1 0, 1 1)'),1,2)) → «LineString (-1 0, 1 0, 1 3)»

  • geom_to_wkt(extend(geom_from_wkt('MultiLineString((0 0, 1 0, 1 1), (2 2, 0 2, 0 5))'),1,2)) → «MultiLineString ((-1 0, 1 0, 1 3),(3 2, 0 2, 0 7))»

Further reading: Extend lines algorithm

13.2.13.31. exterior_ring

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.

Szintaxis

exterior_ring(geometry)

Argumentumok

  • geometry - a polygon geometry

Példák

  • geom_to_wkt(exterior_ring(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1),( 0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2, 0.1, 0.1 0.1))'))) → «LineString (-1 -1, 4 0, 4 2, 0 2, -1 -1)»

13.2.13.32. extrude

Returns an extruded version of the input (Multi-)Curve or (Multi-)Linestring geometry with an extension specified by x and y.

Szintaxis

extrude(geometry, x, y)

Argumentumok

  • geometry - a curve or linestring geometry

  • x - x extension, numeric value

  • y - y extension, numeric value

Példák

  • geom_to_wkt(extrude(geom_from_wkt('LineString(1 2, 3 2, 4 3)'), 1, 2)) → «Polygon ((1 2, 3 2, 4 3, 5 5, 4 4, 2 4, 1 2))»

  • geom_to_wkt(extrude(geom_from_wkt('MultiLineString((1 2, 3 2), (4 3, 8 3))'), 1, 2)) → «MultiPolygon (((1 2, 3 2, 4 4, 2 4, 1 2)),((4 3, 8 3, 9 5, 5 5, 4 3)))»

13.2.13.33. flip_coordinates

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.

Szintaxis

flip_coordinates(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkt(flip_coordinates(make_point(1, 2))) → «Point (2 1)»

  • geom_to_wkt(flip_coordinates(geom_from_wkt('LineString(0 2, 1 0, 1 6)'))) → «LineString (2 0, 0 1, 6 1)»

Further reading: Swap X and Y coordinates algorithm

13.2.13.34. force_polygon_ccw

Forces a geometry to respect the convention where exterior rings are counter-clockwise, interior rings are clockwise.

Szintaxis

force_polygon_ccw(geometry)

Argumentumok

  • geometry - a geometry. Any non-polygon geometries are returned unchanged.

Példák

  • geom_to_wkt(force_polygon_ccw(geometry:=geom_from_wkt('Polygon ((-1 -1, 0 2, 4 2, 4 0, -1 -1))'))) → «Polygon ((-1 -1, 4 0, 4 2, 0 2, -1 -1))»

Further reading: force_polygon_cw, force_rhr

13.2.13.35. force_polygon_cw

Forces a geometry to respect the convention where exterior rings are clockwise, interior rings are counter-clockwise.

Szintaxis

force_polygon_cw(geometry)

Argumentumok

  • geometry - a geometry. Any non-polygon geometries are returned unchanged.

Példák

  • geom_to_wkt(force_polygon_cw(geometry:=geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))) → «Polygon ((-1 -1, 0 2, 4 2, 4 0, -1 -1))»

Further reading: force_polygon_ccw, force_rhr

13.2.13.36. force_rhr

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.

Szintaxis

force_rhr(geometry)

Argumentumok

  • geometry - a geometry. Any non-polygon geometries are returned unchanged.

Példák

  • geom_to_wkt(force_rhr(geometry:=geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))) → «Polygon ((-1 -1, 0 2, 4 2, 4 0, -1 -1))»

Further reading: Force right-hand-rule algorithm, force_polygon_ccw, force_polygon_cw

13.2.13.37. geom_from_gml

Returns a geometry from a GML representation of geometry.

Szintaxis

geom_from_gml(gml)

Argumentumok

  • gml - GML representation of a geometry as a string

Példák

  • geom_from_gml('<gml:LineString srsName="EPSG:4326"><gml:coordinates>4,4 5,5 6,6</gml:coordinates></gml:LineString>') → a line geometry object

13.2.13.38. geom_from_wkb

Returns a geometry created from a Well-Known Binary (WKB) representation.

Szintaxis

geom_from_wkb(binary)

Argumentumok

  • binary - Well-Known Binary (WKB) representation of a geometry (as a binary blob)

Példák

  • geom_from_wkb( geom_to_wkb( make_point(4,5) ) ) → a point geometry object

13.2.13.39. geom_from_wkt

Returns a geometry created from a Well-Known Text (WKT) representation.

Szintaxis

geom_from_wkt(text)

Argumentumok

  • text - Well-Known Text (WKT) representation of a geometry

Példák

  • geom_from_wkt( 'POINT(4 5)' ) → a geometry object

13.2.13.40. geom_to_wkb

Returns the Well-Known Binary (WKB) representation of a geometry

Szintaxis

geom_to_wkb(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkb( $geometry ) → binary blob containing a geometry object

13.2.13.41. geom_to_wkt

Returns the Well-Known Text (WKT) representation of the geometry without SRID metadata.

Szintaxis

geom_to_wkt(geometry, [precision=8])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • precision - numeric precision

Példák

  • geom_to_wkt( make_point(6, 50) ) → «POINT(6 50)»

  • geom_to_wkt(centroid(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))'))) → «POINT(0 0.66666667)»

  • geom_to_wkt(centroid(geom_from_wkt('Polygon((1 1, 0 0, -1 1, 1 1))')), 2) → «POINT(0 0.67)»

13.2.13.42. $geometry

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.

Szintaxis

$geometry

Példák

  • geom_to_wkt( $geometry ) → «POINT(6 50)»

13.2.13.43. geometry

Returns a feature’s geometry.

Szintaxis

geometry(feature)

Argumentumok

  • feature - a feature object

Példák

  • `` 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)»

  • 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

13.2.13.44. geometry_n

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.

Szintaxis

geometry_n(geometry, index)

Argumentumok

  • geometry - geometry collection

  • index - index of geometry to return, where 1 is the first geometry in the collection

Példák

  • geom_to_wkt(geometry_n(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))'),3)) → «Point (1 0)»

13.2.13.45. geometry_type

Returns a string value describing the type of a geometry (Point, Line or Polygon)

Szintaxis

geometry_type(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geometry_type( geom_from_wkt( 'LINESTRING(2 5, 3 6, 4 8)') ) → «Line»

  • geometry_type( geom_from_wkt( 'MULTILINESTRING((2 5, 3 6, 4 8), (1 1, 0 0))') ) → «Line»

  • geometry_type( geom_from_wkt( 'POINT(2 5)') ) → «Point»

  • geometry_type( geom_from_wkt( 'POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))') ) → «Polygon»

13.2.13.46. hausdorff_distance

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.

Szintaxis

hausdorff_distance(geometry1, geometry2, [densify_fraction])

[] marks optional arguments

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

  • densify_fraction - densify fraction amount

Példák

  • hausdorff_distance( geometry1:= geom_from_wkt('LINESTRING (0 0, 2 1)'),geometry2:=geom_from_wkt('LINESTRING (0 0, 2 0)')) → 2

  • hausdorff_distance( geom_from_wkt('LINESTRING (130 0, 0 0, 0 150)'),geom_from_wkt('LINESTRING (10 10, 10 150, 130 10)')) → 14.142135623

  • hausdorff_distance( geom_from_wkt('LINESTRING (130 0, 0 0, 0 150)'),geom_from_wkt('LINESTRING (10 10, 10 150, 130 10)'),0.5) → 70.0

13.2.13.47. inclination

Returns the inclination measured from the zenith (0) to the nadir (180) on point_a to point_b.

Szintaxis

inclination(point_a, point_b)

Argumentumok

  • point_a - point geometry

  • point_b - point geometry

Példák

  • inclination( make_point( 5, 10, 0 ), make_point( 5, 10, 5 ) ) → 0.0

  • inclination( make_point( 5, 10, 0 ), make_point( 5, 10, 0 ) ) → 90.0

  • inclination( make_point( 5, 10, 0 ), make_point( 50, 100, 0 ) ) → 90.0

  • inclination( make_point( 5, 10, 0 ), make_point( 5, 10, -5 ) ) → 180.0

13.2.13.48. interior_ring_n

Returns a specific interior ring from a polygon geometry, or NULL if the geometry is not a polygon.

Szintaxis

interior_ring_n(geometry, index)

Argumentumok

  • geometry - polygon geometry

  • index - index of interior to return, where 1 is the first interior ring

Példák

  • 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 -1))'),1)) → «LineString (-0.1 -0.1, 0.4 0, 0.4 0.2, 0 0.2, -0.1 -0.1))»

13.2.13.49. intersection

Returns a geometry that represents the shared portion of two geometries.

Szintaxis

intersection(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • geom_to_wkt( intersection( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4)' ) ) ) → «LINESTRING(3 3, 4 4)»

  • geom_to_wkt( intersection( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'MULTIPOINT(3.5 3.5, 4 5)' ) ) ) → «POINT(3.5 3.5)»

Further reading: Intersection algorithm

13.2.13.50. intersects

Tests whether a geometry intersects another. Returns TRUE if the geometries spatially intersect (share any portion of space) and false if they do not.

Szintaxis

intersects(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • intersects( geom_from_wkt( 'POINT(4 4)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • intersects( geom_from_wkt( 'POINT(4 5)' ), geom_from_wkt( 'POINT(5 5)' ) ) → FALSE

Further reading: overlay_intersects

13.2.13.51. intersects_bbox

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.

Szintaxis

intersects_bbox(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • intersects_bbox( geom_from_wkt( 'POINT(4 5)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • intersects_bbox( geom_from_wkt( 'POINT(6 5)' ), geom_from_wkt( 'POLYGON((3 3, 4 4, 5 5, 3 3))' ) ) → FALSE

13.2.13.52. is_closed

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.

Szintaxis

is_closed(geometry)

Argumentumok

  • geometry - a line string geometry

Példák

  • is_closed(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')) → FALSE

  • is_closed(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2, 0 0)')) → TRUE

13.2.13.53. is_empty

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.

Szintaxis

is_empty(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • is_empty(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')) → FALSE

  • is_empty(geom_from_wkt('LINESTRING EMPTY')) → TRUE

  • is_empty(geom_from_wkt('POINT(7 4)')) → FALSE

  • is_empty(geom_from_wkt('POINT EMPTY')) → TRUE

Further reading: is_empty_or_null

13.2.13.54. is_empty_or_null

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)»

Szintaxis

is_empty_or_null(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • is_empty_or_null(NULL) → TRUE

  • is_empty_or_null(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')) → FALSE

  • 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

Further reading: is_empty, NULL

13.2.13.55. is_multipart

Returns TRUE if the geometry is of Multi type.

Szintaxis

is_multipart(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • is_multipart(geom_from_wkt('MULTIPOINT ((0 0),(1 1),(2 2))')) → TRUE

  • is_multipart(geom_from_wkt('POINT (0 0)')) → FALSE

13.2.13.56. is_valid

Returns TRUE if a geometry is valid; if it is well-formed in 2D according to the OGC rules.

Szintaxis

is_valid(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • is_valid(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2, 0 0)')) → TRUE

  • is_valid(geom_from_wkt('LINESTRING(0 0)')) → FALSE

Further reading: make_valid, Check validity algorithm

13.2.13.57. $length

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.

Szintaxis

$length

Példák

  • $length → 42.4711

13.2.13.58. length

Returns the number of characters in a string or the length of a geometry linestring.

String variant

Returns the number of characters in a string.

Szintaxis

length(string)

Argumentumok

  • string - string to count length of

Példák

  • length('hello') → 5

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.

Szintaxis

length(geometry)

Argumentumok

  • geometry - line geometry object

Példák

  • length(geom_from_wkt('LINESTRING(0 0, 4 0)')) → 4.0

Further reading: straight_distance_2d

13.2.13.59. length3D

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.

Szintaxis

length3D(geometry)

Argumentumok

  • geometry - line geometry object

Példák

  • length3D(geom_from_wkt('LINESTRINGZ(0 0 0, 3 0 4)')) → 5.0

13.2.13.60. line_interpolate_angle

Returns the angle parallel to the geometry at a specified distance along a linestring geometry. Angles are in degrees clockwise from north.

Szintaxis

line_interpolate_angle(geometry, distance)

Argumentumok

  • geometry - a linestring geometry

  • distance - distance along line to interpolate angle at

Példák

  • line_interpolate_angle(geometry:=geom_from_wkt('LineString(0 0, 10 0)'),distance:=5) → 90.0

13.2.13.61. line_interpolate_point

Returns the point interpolated by a specified distance along a linestring geometry.

Szintaxis

line_interpolate_point(geometry, distance)

Argumentumok

  • geometry - a linestring geometry

  • distance - distance along line to interpolate

Példák

  • 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 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

Further reading: Interpolate point on line algorithm

13.2.13.62. line_locate_point

Returns the distance along a linestring corresponding to the closest position the linestring comes to a specified point geometry.

Szintaxis

line_locate_point(geometry, point)

Argumentumok

  • geometry - a linestring geometry

  • point - point geometry to locate closest position on linestring to

Példák

  • line_locate_point(geometry:=geom_from_wkt('LineString(0 0, 10 0)'),point:=geom_from_wkt('Point(5 0)')) → 5.0

13.2.13.63. line_merge

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.

Szintaxis

line_merge(geometry)

Argumentumok

  • geometry - a LineString/MultiLineString geometry

Példák

  • geom_to_wkt(line_merge(geom_from_wkt('MULTILINESTRING((0 0, 1 1),(1 1, 2 2))'))) → «LineString(0 0,1 1,2 2)»

  • geom_to_wkt(line_merge(geom_from_wkt('MULTILINESTRING((0 0, 1 1),(11 1, 21 2))'))) → «MultiLineString((0 0, 1 1),(11 1, 21 2)»

13.2.13.64. line_substring

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.

Szintaxis

line_substring(geometry, start_distance, end_distance)

Argumentumok

  • geometry - a linestring or curve geometry

  • start_distance - distance to start of substring

  • end_distance - distance to end of substring

Példák

  • geom_to_wkt(line_substring(geometry:=geom_from_wkt('LineString(0 0, 10 0)'),start_distance:=2,end_distance:=6)) → «LineString (2 0,6 0)»

Further reading: Line substring algorithm

13.2.13.65. m

Returns the m (measure) value of a point geometry.

Szintaxis

m(geometry)

Argumentumok

  • geometry - a point geometry

Példák

  • m( geom_from_wkt( 'POINTM(2 5 4)' ) ) → 4

13.2.13.66. m_max

Returns the maximum m (measure) value of a geometry.

Szintaxis

m_max(geometry)

Argumentumok

  • geometry - a geometry containing m values

Példák

  • m_max( make_point_m( 0,0,1 ) ) → 1

  • m_max(make_line( make_point_m( 0,0,1 ), make_point_m( -1,-1,2 ), make_point_m( -2,-2,0 ) ) ) → 2

13.2.13.67. m_min

Returns the minimum m (measure) value of a geometry.

Szintaxis

m_min(geometry)

Argumentumok

  • geometry - a geometry containing m values

Példák

  • m_min( make_point_m( 0,0,1 ) ) → 1

  • m_min(make_line( make_point_m( 0,0,1 ), make_point_m( -1,-1,2 ), make_point_m( -2,-2,0 ) ) ) → 0

13.2.13.68. main_angle

Returns the angle of the long axis (clockwise, in degrees from North) of the oriented minimal bounding rectangle, which completely covers the geometry.

Szintaxis

main_angle(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • main_angle(geom_from_wkt('Polygon ((321577 129614, 321581 129618, 321585 129615, 321581 129610, 321577 129614))')) → 38.66

13.2.13.69. make_circle

Creates a circular polygon.

Szintaxis

make_circle(center, radius, [segments=36])

[] marks optional arguments

Argumentumok

  • center - center point of the circle

  • radius - radius of the circle

  • segments - optional argument for polygon segmentation. By default this value is 36

Példák

  • geom_to_wkt(make_circle(make_point(10,10), 5, 4)) → «Polygon ((10 15, 15 10, 10 5, 5 10, 10 15))»

  • geom_to_wkt(make_circle(make_point(10,10,5), 5, 4)) → «PolygonZ ((10 15 5, 15 10 5, 10 5 5, 5 10 5, 10 15 5))»

  • geom_to_wkt(make_circle(make_point(10,10,5,30), 5, 4)) → «PolygonZM ((10 15 5 30, 15 10 5 30, 10 5 5 30, 5 10 5 30, 10 15 5 30))»

13.2.13.70. make_ellipse

Creates an elliptical polygon.

Szintaxis

make_ellipse(center, semi_major_axis, semi_minor_axis, azimuth, [segments=36])

[] marks optional arguments

Argumentumok

  • center - center point of the ellipse

  • semi_major_axis - semi-major axis of the ellipse

  • semi_minor_axis - semi-minor axis of the ellipse

  • azimuth - orientation of the ellipse

  • segments - optional argument for polygon segmentation. By default this value is 36

Példák

  • geom_to_wkt(make_ellipse(make_point(10,10), 5, 2, 90, 4)) → «Polygon ((15 10, 10 8, 5 10, 10 12, 15 10))»

  • geom_to_wkt(make_ellipse(make_point(10,10,5), 5, 2, 90, 4)) → «PolygonZ ((15 10 5, 10 8 5, 5 10 5, 10 12 5, 15 10 5))»

  • geom_to_wkt(make_ellipse(make_point(10,10,5,30), 5, 2, 90, 4)) → «PolygonZM ((15 10 5 30, 10 8 5 30, 5 10 5 30, 10 12 5 30, 15 10 5 30))»

13.2.13.71. make_line

Creates a line geometry from a series of point geometries.

List of arguments variant

Line vertices are specified as separate arguments to the function.

Szintaxis

make_line(point1, point2, …)

Argumentumok

  • point - a point geometry (or array of points)

Példák

  • geom_to_wkt(make_line(make_point(2,4),make_point(3,5))) → «LineString (2 4, 3 5)»

  • geom_to_wkt(make_line(make_point(2,4),make_point(3,5),make_point(9,7))) → «LineString (2 4, 3 5, 9 7)»

Array variant

Line vertices are specified as an array of points.

Szintaxis

make_line(array)

Argumentumok

  • array - array of points

Példák

  • geom_to_wkt(make_line(array(make_point(2,4),make_point(3,5),make_point(9,7)))) → «LineString (2 4, 3 5, 9 7)»

13.2.13.72. make_point

Creates a point geometry from an x and y (and optional z and m) value.

Szintaxis

make_point(x, y, [z], [m])

[] marks optional arguments

Argumentumok

  • x - x coordinate of point

  • y - y coordinate of point

  • z - optional z coordinate of point

  • m - optional m value of point

Példák

  • geom_to_wkt(make_point(2,4)) → «Point (2 4)»

  • geom_to_wkt(make_point(2,4,6)) → «PointZ (2 4 6)»

  • geom_to_wkt(make_point(2,4,6,8)) → «PointZM (2 4 6 8)»

13.2.13.73. make_point_m

Creates a point geometry from an x, y coordinate and m value.

Szintaxis

make_point_m(x, y, m)

Argumentumok

  • x - x coordinate of point

  • y - y coordinate of point

  • m - m value of point

Példák

  • geom_to_wkt(make_point_m(2,4,6)) → «PointM (2 4 6)»

13.2.13.74. make_polygon

Creates a polygon geometry from an outer ring and optional series of inner ring geometries.

Szintaxis

make_polygon(outerRing, [innerRing1], [innerRing2], …)

[] marks optional arguments

Argumentumok

  • outerRing - closed line geometry for polygon’s outer ring

  • innerRing - optional closed line geometry for inner ring

Példák

  • 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 )'),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))»

13.2.13.75. make_rectangle_3points

Creates a rectangle from 3 points.

Szintaxis

make_rectangle_3points(point1, point2, point3, [option=0])

[] marks optional arguments

Argumentumok

  • point1 - First point.

  • point2 - Second point.

  • point3 - Third point.

  • option - An optional argument to construct the rectangle. By default this value is 0. Value can be 0 (distance) or 1 (projected). Option distance: Second distance is equal to the distance between 2nd and 3rd point. Option projected: Second distance is equal to the distance of the perpendicular projection of the 3rd point on the segment or its extension.

Példák

  • geom_to_wkt(make_rectangle_3points(make_point(0, 0), make_point(0,5), make_point(5, 5), 0)) → «Polygon ((0 0, 0 5, 5 5, 5 0, 0 0))»

  • geom_to_wkt(make_rectangle_3points(make_point(0, 0), make_point(0,5), make_point(5, 3), 1)) → «Polygon ((0 0, 0 5, 5 5, 5 0, 0 0))»

13.2.13.76. make_regular_polygon

Creates a regular polygon.

Szintaxis

make_regular_polygon(center, radius, number_sides, [circle=0])

[] marks optional arguments

Argumentumok

  • center - center of the regular polygon

  • radius - second point. The first if the regular polygon is inscribed. The midpoint of the first side if the regular polygon is circumscribed.

  • number_sides - Number of sides/edges of the regular polygon

  • circle - Optional argument to construct the regular polygon. By default this value is 0. Value can be 0 (inscribed) or 1 (circumscribed)

Példák

  • geom_to_wkt(make_regular_polygon(make_point(0,0), make_point(0,5), 5)) → «Polygon ((0 5, 4.76 1.55, 2.94 -4.05, -2.94 -4.05, -4.76 1.55, 0 5))»

  • geom_to_wkt(make_regular_polygon(make_point(0,0), project(make_point(0,0), 4.0451, radians(36)), 5)) → «Polygon ((0 5, 4.76 1.55, 2.94 -4.05, -2.94 -4.05, -4.76 1.55, 0 5))»

13.2.13.77. make_square

Creates a square from a diagonal.

Szintaxis

make_square(point1, point2)

Argumentumok

  • point1 - First point of the diagonal

  • point2 - Last point of the diagonal

Példák

  • geom_to_wkt(make_square( make_point(0,0), make_point(5,5))) → «Polygon ((0 0, -0 5, 5 5, 5 0, 0 0))»

  • geom_to_wkt(make_square( make_point(5,0), make_point(5,5))) → «Polygon ((5 0, 2.5 2.5, 5 5, 7.5 2.5, 5 0))»

13.2.13.78. make_triangle

Creates a triangle polygon.

Szintaxis

make_triangle(point1, point2, point3)

Argumentumok

  • point1 - first point of the triangle

  • point2 - second point of the triangle

  • point3 - third point of the triangle

Példák

  • geom_to_wkt(make_triangle(make_point(0,0), make_point(5,5), make_point(0,10))) → «Triangle ((0 0, 5 5, 0 10, 0 0))»

  • geom_to_wkt(boundary(make_triangle(make_point(0,0), make_point(5,5), make_point(0,10)))) → «LineString (0 0, 5 5, 0 10, 0 0)»

13.2.13.79. make_valid

Returns a valid geometry or an empty geometry if the geometry could not be made valid.

Szintaxis

make_valid(geometry, [method=structure], [keep_collapsed=false])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • method - repair algorithm. May be either «structure» or «linework». The «linework» option combines all rings into a set of noded lines and then extracts valid polygons from that linework. The «structure» method first makes all rings valid and then merges shells and subtracts holes from shells to generate valid result. Assumes that holes and shells are correctly categorized.

  • keep_collapsed - if set to true, then components that have collapsed into a lower dimensionality will be kept. For example, a ring collapsing to a line, or a line collapsing to a point.

Példák

  • 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))»

  • 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

Further reading: is_valid, Fix geometries algorithm

13.2.13.80. minimal_circle

Returns the minimal enclosing circle of a geometry. It represents the minimum circle that encloses all geometries within the set.

Szintaxis

minimal_circle(geometry, [segments=36])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • segments - optional argument for polygon segmentation. By default this value is 36

Példák

  • geom_to_wkt( minimal_circle( geom_from_wkt( 'LINESTRING(0 5, 0 -5, 2 1)' ), 4 ) ) → «Polygon ((0 5, 5 -0, -0 -5, -5 0, 0 5))»

  • geom_to_wkt( minimal_circle( geom_from_wkt( 'MULTIPOINT(1 2, 3 4, 3 2)' ), 4 ) ) → «Polygon ((3 4, 3 2, 1 2, 1 4, 3 4))»

Further reading: Minimum enclosing circles algorithm

13.2.13.81. nodes_to_points

Returns a multipoint geometry consisting of every node in the input geometry.

Szintaxis

nodes_to_points(geometry, [ignore_closing_nodes=false])

[] marks optional arguments

Argumentumok

  • geometry - geometry object

  • ignore_closing_nodes - optional argument specifying whether to include duplicate nodes which close lines or polygons rings. Defaults to false, set to true to avoid including these duplicate nodes in the output collection.

Példák

  • geom_to_wkt(nodes_to_points(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))) → «MultiPoint ((0 0),(1 1),(2 2))»

  • 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))»

Further reading: Extract vertices algorithm

13.2.13.82. num_geometries

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.

Szintaxis

num_geometries(geometry)

Argumentumok

  • geometry - geometry collection or multi-part geometry

Példák

  • num_geometries(geom_from_wkt('GEOMETRYCOLLECTION(POINT(0 1), POINT(0 0), POINT(1 0), POINT(1 1))')) → 4

  • num_geometries(geom_from_wkt('MULTIPOINT((0 1), (0 0), (1 0))')) → 3

13.2.13.83. num_interior_rings

Returns the number of interior rings in a polygon or geometry collection, or NULL if the input geometry is not a polygon or collection.

Szintaxis

num_interior_rings(geometry)

Argumentumok

  • geometry - input geometry

Példák

  • num_interior_rings(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

13.2.13.84. num_points

Returns the number of vertices in a geometry.

Szintaxis

num_points(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • num_points($geometry) → number of vertices in the current feature’s geometry

13.2.13.85. num_rings

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.

Szintaxis

num_rings(geometry)

Argumentumok

  • geometry - input geometry

Példák

  • num_rings(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))')) → 2

13.2.13.86. offset_curve

Returns a geometry formed by offsetting a linestring geometry to the side. Distances are in the Spatial Reference System of this geometry.

Szintaxis

offset_curve(geometry, distance, [segments=8], [join=1], [miter_limit=2.0])

[] marks optional arguments

Argumentumok

  • geometry - a (multi)linestring geometry

  • distance - offset distance. Positive values will be buffered to the left of lines, negative values to the right

  • segments - number of segments to use to represent a quarter circle when a round join style is used. A larger number results in a smoother line with more nodes.

  • join - join style for corners, where 1 = round, 2 = miter and 3 = bevel

  • miter_limit - limit on the miter ratio used for very sharp corners (when using miter joins only)

Példák

  • offset_curve($geometry, 10.5) → line offset to the left by 10.5 units

  • offset_curve($geometry, -10.5) → line offset to the right by 10.5 units

  • offset_curve($geometry, 10.5, segments:=16, join:=1) → line offset to the left by 10.5 units, using more segments to result in a smoother curve

  • offset_curve($geometry, 10.5, join:=3) → line offset to the left by 10.5 units, using a beveled join

Further reading: Offset lines algorithm

13.2.13.87. order_parts

Orders the parts of a MultiGeometry by a given criteria

Szintaxis

order_parts(geometry, orderby, [ascending=true])

[] marks optional arguments

Argumentumok

  • geometry - a multi-type geometry

  • orderby - an expression string defining the order criteria

  • ascending - boolean, True for ascending, False for descending

Példák

  • 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)))»

  • geom_to_wkt(order_parts(geom_from_wkt('LineString(1 2, 3 2, 4 3)'), '1', True)) → «LineString(1 2, 3 2, 4 3)»

13.2.13.88. oriented_bbox

Returns a geometry which represents the minimal oriented bounding box of an input geometry.

Szintaxis

oriented_bbox(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkt( oriented_bbox( geom_from_wkt( 'MULTIPOINT(1 2, 3 4, 3 2)' ) ) ) → «Polygon ((3 2, 3 4, 1 4, 1 2, 3 2))»

Further reading: Oriented minimum bounding box algorithm

13.2.13.89. overlaps

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.

Szintaxis

overlaps(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • overlaps( geom_from_wkt( 'LINESTRING(3 5, 4 4, 5 5, 5 3)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • overlaps( geom_from_wkt( 'LINESTRING(0 0, 1 1)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → FALSE

13.2.13.90. overlay_contains

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.

Szintaxis

overlay_contains(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_contains('regions') → TRUE if the current feature spatially contains a region

  • overlay_contains('regions', filter:= population > 10000) → TRUE if the current feature spatially contains a region with a population greater than 10000

  • overlay_contains('regions', name) → an array of names, for the regions contained in the current feature

  • array_to_string(overlay_contains('regions', name)) → a string as a comma separated list of names, for the regions contained in the current feature

  • array_sort(overlay_contains(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions contained in the current feature and with a population greater than 10000

  • overlay_contains(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions contained in the current feature

Further reading: contains, array manipulation, Select by location algorithm

13.2.13.91. overlay_crosses

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.

Szintaxis

overlay_crosses(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_crosses('regions') → TRUE if the current feature spatially crosses a region

  • overlay_crosses('regions', filter:= population > 10000) → TRUE if the current feature spatially crosses a region with a population greater than 10000

  • overlay_crosses('regions', name) → an array of names, for the regions crossed by the current feature

  • array_to_string(overlay_crosses('regions', name)) → a string as a comma separated list of names, for the regions crossed by the current feature

  • array_sort(overlay_crosses(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions crossed by the current feature and with a population greater than 10000

  • overlay_crosses(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions crossed by the current feature

Further reading: crosses, array manipulation, Select by location algorithm

13.2.13.92. overlay_disjoint

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.

Szintaxis

overlay_disjoint(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • 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 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

Further reading: disjoint, array manipulation, Select by location algorithm

13.2.13.93. overlay_equals

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.

Szintaxis

overlay_equals(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_equals('regions') → TRUE if the current feature is spatially equal to a region

  • overlay_equals('regions', filter:= population > 10000) → TRUE if the current feature is spatially equal to a region with a population greater than 10000

  • overlay_equals('regions', name) → an array of names, for the regions spatially equal to the current feature

  • array_to_string(overlay_equals('regions', name)) → a string as a comma separated list of names, for the regions spatially equal to the current feature

  • array_sort(overlay_equals(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions spatially equal to the current feature and with a population greater than 10000

  • overlay_equals(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions spatially equal to the current feature

Further reading: array manipulation, Select by location algorithm

13.2.13.94. overlay_intersects

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.

Szintaxis

overlay_intersects(layer, [expression], [filter], [limit], [cache=false], [min_overlap], [min_inscribed_circle_radius], [return_details], [sort_by_intersection_size])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

  • min_overlap - defines an optional exclusion filter:

    • for polygons, a minimum area in current feature squared units for the intersection. If the intersection results in multiple polygons the intersection will be returned if at least one of the polygons has an area greater or equal to the value

    • for lines, a minimum length in current feature units. If the intersection results in multiple lines the intersection will be returned if at least one of the lines has a length greater or equal to the value.

  • min_inscribed_circle_radius - defines an optional exclusion filter (for polygons only): minimum radius in current feature units for the maximum inscribed circle of the intersection. If the intersection results in multiple polygons the intersection will be returned if at least one of the polygons has a radius for the maximum inscribed circle greater or equal to the value.

    Read more on the underlying GEOS predicate, as described in PostGIS ST_MaximumInscribedCircle function.

    This argument requires GEOS >= 3.9.

  • 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.

Példák

  • overlay_intersects('regions') → TRUE if the current feature spatially intersects a region

  • overlay_intersects('regions', filter:= population > 10000) → TRUE if the current feature spatially intersects a region with a population greater than 10000

  • overlay_intersects('regions', name) → an array of names, for the regions intersected by the current feature

  • array_to_string(overlay_intersects('regions', name)) → a string as a comma separated list of names, for the regions intersected by the current feature

  • array_sort(overlay_intersects(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions intersected by the current feature and with a population greater than 10000

  • overlay_intersects(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions intersected by the current feature

  • overlay_intersects(layer:='regions', min_overlap:=0.54) → TRUE if the current feature spatially intersects a region and the intersection area (of at least one of the parts in case of multipolygons) is greater or equal to 0.54

  • overlay_intersects(layer:='regions', min_inscribed_circle_radius:=0.54) → TRUE if the current feature spatially intersects a region and the intersection area maximum inscribed circle’s radius (of at least one of the parts in case of multipart) is greater or equal to 0.54

  • overlay_intersects(layer:='regions', expression:= geom_to_wkt($geometry), return_details:=true) → an array of maps containing «id», «result», «overlap» and «radius»

  • overlay_intersects(layer:='regions', expression:= geom_to_wkt($geometry), sort_by_intersection_size:='des') → an array of geometries (in WKT) ordered by the overlap value in descending order

Further reading: intersects, array manipulation, Select by location algorithm

13.2.13.95. overlay_nearest

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.

Szintaxis

overlay_nearest(layer, [expression], [filter], [limit=1], [max_distance], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the target layer

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features in the target layer will be used.

  • limit - an optional integer to limit the number of matching features. If not set, only the nearest feature will be returned. If set to -1, returns all the matching features.

  • max_distance - an optional distance to limit the search of matching features. If not set, all the features in the target layer will be used.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_nearest('airports') → TRUE if the „airports” layer has at least one feature

  • overlay_nearest('airports', max_distance:= 5000) → TRUE if there is an airport within a distance of 5000 map units from the current feature

  • overlay_nearest('airports', name) → the name of the closest airport to the current feature, as an array

  • array_to_string(overlay_nearest('airports', name)) → the name of the closest airport to the current feature, as a string

  • overlay_nearest(layer:='airports', expression:= name, max_distance:= 5000) → the name of the closest airport within a distance of 5000 map units from the current feature, as an array

  • overlay_nearest(layer:='airports', expression:="name", filter:= "Use"='Civilian', limit:=3) → an array of names, for up to the three closest civilian airports ordered by distance

  • overlay_nearest(layer:='airports', expression:="name", limit:= -1, max_distance:= 5000) → an array of names, for all the airports within a distance of 5000 map units from the current feature, ordered by distance

Further reading: array manipulation, Join attributes by nearest algorithm

13.2.13.96. overlay_touches

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.

Szintaxis

overlay_touches(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_touches('regions') → TRUE if the current feature spatially touches a region

  • overlay_touches('regions', filter:= population > 10000) → TRUE if the current feature spatially touches a region with a population greater than 10000

  • overlay_touches('regions', name) → an array of names, for the regions touched by the current feature

  • string_to_array(overlay_touches('regions', name)) → a string as a comma separated list of names, for the regions touched by the current feature

  • array_sort(overlay_touches(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions touched by the current feature and with a population greater than 10000

  • overlay_touches(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions touched by the current feature

Further reading: touches, array manipulation, Select by location algorithm

13.2.13.97. overlay_within

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.

Szintaxis

overlay_within(layer, [expression], [filter], [limit], [cache=false])

[] marks optional arguments

Argumentumok

  • layer - the layer whose overlay is checked

  • expression - an optional expression to evaluate on the features from the target layer. If not set, the function will just return a boolean indicating whether there is at least one match.

  • filter - an optional expression to filter the target features to check. If not set, all the features will be checked.

  • limit - an optional integer to limit the number of matching features. If not set, all the matching features will be returned.

  • cache - set this to true to build a local spatial index (most of the time, this is unwanted, unless you are working with a particularly slow data provider)

Példák

  • overlay_within('regions') → TRUE if the current feature is spatially within a region

  • overlay_within('regions', filter:= population > 10000) → TRUE if the current feature is spatially within a region with a population greater than 10000

  • overlay_within('regions', name) → an array of names, for the regions containing the current feature

  • array_to_string(overlay_within('regions', name)) → a string as a comma separated list of names, for the regions containing the current feature

  • array_sort(overlay_within(layer:='regions', expression:="name", filter:= population > 10000)) → an ordered array of names, for the regions containing the current feature and with a population greater than 10000

  • overlay_within(layer:='regions', expression:= geom_to_wkt($geometry), limit:=2) → an array of geometries (in WKT), for up to two regions containing the current feature

Further reading: within, array manipulation, Select by location algorithm

13.2.13.98. $perimeter

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.

Szintaxis

$perimeter

Példák

  • $perimeter → 42

13.2.13.99. perimeter

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.

Szintaxis

perimeter(geometry)

Argumentumok

  • geometry - polygon geometry object

Példák

  • perimeter(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))')) → 12.0

13.2.13.100. point_n

Returns a specific node from a geometry.

Szintaxis

point_n(geometry, index)

Argumentumok

  • geometry - geometry object

  • index - index of node to return, where 1 is the first node; if the value is negative, the selected vertex index will be its total count minus the absolute value

Példák

  • geom_to_wkt(point_n(geom_from_wkt('POLYGON((0 0, 4 0, 4 2, 0 2, 0 0))'),2)) → «Point (4 0)»

Further reading: Extract specific vertices algorithm

13.2.13.101. point_on_surface

Returns a point guaranteed to lie on the surface of a geometry.

Szintaxis

point_on_surface(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • point_on_surface($geometry) → a point geometry

Further reading: Point on Surface algorithm

13.2.13.102. pole_of_inaccessibility

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.

Szintaxis

pole_of_inaccessibility(geometry, tolerance)

Argumentumok

  • geometry - a geometry

  • tolerance - maximum distance between the returned point and the true pole location

Példák

  • geom_to_wkt(pole_of_inaccessibility( geom_from_wkt('POLYGON((0 1, 0 9, 3 10, 3 3, 10 3, 10 1, 0 1))'), 0.1)) → «Point(1.546875 2.546875)»

Further reading: Pole of inaccessibility algorithm

13.2.13.103. project

Returns a point projected from a start point using a distance, a bearing (azimuth) and an elevation in radians.

Szintaxis

project(point, distance, azimuth, [elevation])

[] marks optional arguments

Argumentumok

  • point - start point

  • distance - distance to project

  • azimuth - azimuth in radians clockwise, where 0 corresponds to north

  • elevation - angle of inclination in radians

Példák

  • geom_to_wkt(project(make_point(1, 2), 3, radians(270))) → «Point(-2, 2)»

Further reading: Project points (Cartesian) algorithm

13.2.13.104. relate

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.

Szintaxis

relate(geometry, geometry)

Argumentumok

  • geometry - a geometry

  • geometry - a geometry

Példák

  • relate( geom_from_wkt( 'LINESTRING(40 40,120 120)' ), geom_from_wkt( 'LINESTRING(40 40,60 120)' ) ) → «FF1F00102»

Pattern match variant

Tests whether the DE-9IM relationship between two geometries matches a specified pattern.

Szintaxis

relate(geometry, geometry, pattern)

Argumentumok

  • geometry - a geometry

  • geometry - a geometry

  • pattern - DE-9IM pattern to match

Példák

  • relate( geom_from_wkt( 'LINESTRING(40 40,120 120)' ), geom_from_wkt( 'LINESTRING(40 40,60 120)' ), '**1F001**' ) → TRUE

13.2.13.105. reverse

Reverses the direction of a line string by reversing the order of its vertices.

Szintaxis

reverse(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • geom_to_wkt(reverse(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))) → «LINESTRING(2 2, 1 1, 0 0)»

Further reading: Reverse line direction algorithm

13.2.13.106. rotate

Returns a rotated version of a geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

rotate(geometry, rotation, [center=NULL], [per_part=false])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • rotation - clockwise rotation in degrees

  • center - rotation center point. If not specified, the center of the geometry’s bounding box is used.

  • per_part - apply rotation per part. If true, then rotation will apply around the center of each part’s bounding box when the input geometry is multipart and an explicit rotation center point is not specified.

Példák

  • rotate($geometry, 45, make_point(4, 5)) → geometry rotated 45 degrees clockwise around the (4, 5) point

  • rotate($geometry, 45) → geometry rotated 45 degrees clockwise around the center of its bounding box

../../../_images/rotate.gif

13.7. ábra Rotating features

13.2.13.107. roundness

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.

Szintaxis

roundness(geometry)

Argumentumok

  • geometry - a polygon

Példák

  • round(roundness(geom_from_wkt('POLYGON(( 0 0, 0 1, 1 1, 1 0, 0 0))')), 3) → 0.785

  • round(roundness(geom_from_wkt('POLYGON(( 0 0, 0 0.1, 1 0.1, 1 0, 0 0))')), 3) → 0.260

Further reading: Roundness algorithm

13.2.13.108. scale

Returns a scaled version of a geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

scale(geometry, x_scale, y_scale, [center])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • x_scale - x-axis scaling factor

  • y_scale - y-axis scaling factor

  • center - scaling center point. If not specified, the center of the geometry’s bounding box is used.

Példák

  • scale($geometry, 2, 0.5, make_point(4, 5)) → geometry scaled twice horizontally and halved vertically, around the (4, 5) point

  • scale($geometry, 2, 0.5) → geometry twice horizontally and halved vertically, around the center of its bounding box

13.2.13.109. segments_to_lines

Returns a multi line geometry consisting of a line for every segment in the input geometry.

Szintaxis

segments_to_lines(geometry)

Argumentumok

  • geometry - geometry object

Példák

  • geom_to_wkt(segments_to_lines(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))) → «MultiLineString ((0 0, 1 1),(1 1, 2 2))»

Further reading: Explode lines algorithm

13.2.13.110. shared_paths

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.

Szintaxis

shared_paths(geometry1, geometry2)

Argumentumok

  • geometry1 - a LineString/MultiLineString geometry

  • geometry2 - a LineString/MultiLineString geometry

Példák

  • geom_to_wkt(shared_paths(geom_from_wkt('MULTILINESTRING((26 125,26 200,126 200,126 125,26 125),(51 150,101 150,76 175,51 150)))'),geom_from_wkt('LINESTRING(151 100,126 156.25,126 125,90 161, 76 175)'))) → «GeometryCollection (MultiLineString ((126 156.25, 126 125),(101 150, 90 161),(90 161, 76 175)),MultiLineString EMPTY)»

  • geom_to_wkt(shared_paths(geom_from_wkt('LINESTRING(76 175,90 161,126 125,126 156.25,151 100)'),geom_from_wkt('MULTILINESTRING((26 125,26 200,126 200,126 125,26 125),(51 150,101 150,76 175,51 150))'))) → «GeometryCollection (MultiLineString EMPTY,MultiLineString ((76 175, 90 161),(90 161, 101 150),(126 125, 126 156.25)))»

13.2.13.111. shortest_line

Returns the shortest line joining geometry1 to geometry2. The resultant line will start at geometry1 and end at geometry2.

Szintaxis

shortest_line(geometry1, geometry2)

Argumentumok

  • geometry1 - geometry to find shortest line from

  • geometry2 - geometry to find shortest line to

Példák

  • geom_to_wkt(shortest_line(geom_from_wkt('LINESTRING (20 80, 98 190, 110 180, 50 75 )'),geom_from_wkt('POINT(100 100)'))) → «LineString(73.0769 115.384, 100 100)»

13.2.13.112. simplify

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.

Szintaxis

simplify(geometry, tolerance)

Argumentumok

  • geometry - a geometry

  • tolerance - maximum deviation from straight segments for points to be removed

Példák

  • geom_to_wkt(simplify(geometry:=geom_from_wkt('LineString(0 0, 5 0.1, 10 0)'),tolerance:=5)) → «LineString(0 0, 10 0)»

Further reading: Simplify algorithm

13.2.13.113. simplify_vw

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.

Szintaxis

simplify_vw(geometry, tolerance)

Argumentumok

  • geometry - a geometry

  • tolerance - a measure of the maximum area created by a node for the node to be removed

Példák

  • geom_to_wkt(simplify_vw(geometry:=geom_from_wkt('LineString(0 0, 5 0, 5.01 10, 5.02 0, 10 0)'),tolerance:=5)) → «LineString(0 0, 10 0)»

Further reading: Simplify algorithm

13.2.13.114. single_sided_buffer

Returns a geometry formed by buffering out just one side of a linestring geometry. Distances are in the Spatial Reference System of this geometry.

Szintaxis

single_sided_buffer(geometry, distance, [segments=8], [join=1], [miter_limit=2.0])

[] marks optional arguments

Argumentumok

  • geometry - a (multi)linestring geometry

  • distance - buffer distance. Positive values will be buffered to the left of lines, negative values to the right

  • segments - number of segments to use to represent a quarter circle when a round join style is used. A larger number results in a smoother buffer with more nodes.

  • join - join style for corners, where 1 = round, 2 = miter and 3 = bevel

  • miter_limit - limit on the miter ratio used for very sharp corners (when using miter joins only)

Példák

  • single_sided_buffer($geometry, 10.5) → line buffered to the left by 10.5 units

  • single_sided_buffer($geometry, -10.5) → line buffered to the right by 10.5 units

  • single_sided_buffer($geometry, 10.5, segments:=16, join:=1) → line buffered to the left by 10.5 units, using more segments to result in a smoother buffer

  • single_sided_buffer($geometry, 10.5, join:=3) → line buffered to the left by 10.5 units, using a beveled join

Further reading: Single sided buffer algorithm

13.2.13.115. sinuosity

Returns the sinuosity of a curve, which is the ratio of the curve length to the straight (2D) distance between its endpoints.

Szintaxis

sinuosity(geometry)

Argumentumok

  • geometry - Input curve (circularstring, linestring)

Példák

  • round(sinuosity(geom_from_wkt('LINESTRING(2 0, 2 2, 3 2, 3 3)')), 3) → 1.265

  • sinuosity(geom_from_wkt('LINESTRING( 3 1, 5 1)')) → 1.0

13.2.13.116. smooth

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.

Szintaxis

smooth(geometry, [iterations=1], [offset=0.25], [min_length=-1], [max_angle=180])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • iterations - number of smoothing iterations to apply. Larger numbers result in smoother but more complex geometries.

  • offset - value between 0 and 0.5 which controls how tightly the smoothed geometry follow the original geometry. Smaller values result in a tighter smoothing, larger values result in looser smoothing.

  • min_length - minimum length of segments to apply smoothing to. This parameter can be used to avoid placing excessive additional nodes in shorter segments of the geometry.

  • max_angle - maximum angle at node for smoothing to be applied (0-180). By lowering the maximum angle intentionally sharp corners in the geometry can be preserved. For instance, a value of 80 degrees will retain right angles in the geometry.

Példák

  • geom_to_wkt(smooth(geometry:=geom_from_wkt('LineString(0 0, 5 0, 5 5)'),iterations:=1,offset:=0.2,min_length:=-1,max_angle:=180)) → «LineString (0 0, 4 0, 5 1, 5 5)»

Further reading: Smooth algorithm

13.2.13.117. square_wave

Constructs square/rectangular waves along the boundary of a geometry.

Szintaxis

square_wave(geometry, wavelength, amplitude, [strict=False])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • wavelength - wavelength of square waveform

  • amplitude - amplitude of square waveform

  • strict - By default the wavelength argument is treated as a „maximum wavelength”, where the actual wavelength will be dynamically adjusted so that an exact number of square waves are created along the boundaries of the geometry. If the strict argument is set to true then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.

Példák

  • square_wave(geom_from_wkt('LineString(0 0, 10 0)'), 3, 1) → Square waves with wavelength 3 and amplitude 1 along the linestring

13.2.13.118. square_wave_randomized

Constructs randomized square/rectangular waves along the boundary of a geometry.

Szintaxis

square_wave_randomized(geometry, min_wavelength, max_wavelength, min_amplitude, max_amplitude, [seed=0])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • min_wavelength - minimum wavelength of waves

  • max_wavelength - maximum wavelength of waves

  • min_amplitude - minimum amplitude of waves

  • max_amplitude - maximum amplitude of waves

  • seed - specifies a random seed for generating waves. If the seed is 0, then a completely random set of waves will be generated.

Példák

  • square_wave_randomized(geom_from_wkt('LineString(0 0, 10 0)'), 2, 3, 0.1, 0.2) → Randomly sized square waves with wavelengths between 2 and 3 and amplitudes between 0.1 and 0.2 along the linestring

13.2.13.119. start_point

Returns the first node from a geometry.

Szintaxis

start_point(geometry)

Argumentumok

  • geometry - geometry object

Példák

  • geom_to_wkt(start_point(geom_from_wkt('LINESTRING(4 0, 4 2, 0 2)'))) → «Point (4 0)»

Further reading: Extract specific vertices algorithm

13.2.13.120. straight_distance_2d

Returns the direct/euclidean distance between the first and last vertex of a geometry. The geometry must be a curve (circularstring, linestring).

Szintaxis

straight_distance_2d(geometry)

Argumentumok

  • geometry - The geometry.

Példák

  • straight_distance_2d(geom_from_wkt('LINESTRING(1 0, 1 1)')) → 1

  • round(straight_distance_2d(geom_from_wkt('LINESTRING(1 4, 3 5, 5 0)')), 3) → 5.657

Further reading: length

13.2.13.121. sym_difference

Returns a geometry that represents the portions of two geometries that do not intersect.

Szintaxis

sym_difference(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • geom_to_wkt( sym_difference( geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ), geom_from_wkt( 'LINESTRING(3 3, 8 8)' ) ) ) → «LINESTRING(5 5, 8 8)»

Further reading: Symmetrical difference algorithm

13.2.13.122. tapered_buffer

Creates a buffer along a line geometry where the buffer diameter varies evenly over the length of the line.

Szintaxis

tapered_buffer(geometry, start_width, end_width, [segments=8])

[] marks optional arguments

Argumentumok

  • geometry - input geometry. Must be a (multi)line geometry.

  • start_width - width of buffer at start of line,

  • end_width - width of buffer at end of line.

  • segments - number of segments to approximate quarter-circle curves in the buffer.

Példák

  • tapered_buffer(geometry:=geom_from_wkt('LINESTRING(1 2, 4 2)'),start_width:=1,end_width:=2,segments:=8) → A tapered buffer starting with a diameter of 1 and ending with a diameter of 2 along the linestring geometry.

../../../_images/tapered_buffer.png

13.8. ábra Tapered buffer on line features

Further reading: Tapered buffers algorithm

13.2.13.123. touches

Tests whether a geometry touches another. Returns TRUE if the geometries have at least one point in common, but their interiors do not intersect.

Szintaxis

touches(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • touches( geom_from_wkt( 'LINESTRING(5 3, 4 4)' ), geom_from_wkt( 'LINESTRING(3 3, 4 4, 5 5)' ) ) → TRUE

  • touches( geom_from_wkt( 'POINT(4 4)' ), geom_from_wkt( 'POINT(5 5)' ) ) → FALSE

Further reading: overlay_touches

13.2.13.124. transform

Returns the geometry transformed from a source CRS to a destination CRS.

Szintaxis

transform(geometry, source_auth_id, dest_auth_id)

Argumentumok

  • geometry - a geometry

  • source_auth_id - the source auth CRS ID

  • dest_auth_id - the destination auth CRS ID

Példák

  • geom_to_wkt( transform( make_point(488995.53240249, 7104473.38600835), 'EPSG:2154', 'EPSG:4326' ) ) → «POINT(0 51)»

Further reading: Reproject layer algorithm

13.2.13.125. translate

Returns a translated version of a geometry. Calculations are in the Spatial Reference System of this geometry.

Szintaxis

translate(geometry, dx, dy)

Argumentumok

  • geometry - a geometry

  • dx - delta x

  • dy - delta y

Példák

  • translate($geometry, 5, 10) → a geometry of the same type like the original one

../../../_images/translate_geometry.png

13.9. ábra Translating features

Further reading: Translate algorithm

13.2.13.126. triangular_wave

Constructs triangular waves along the boundary of a geometry.

Szintaxis

triangular_wave(geometry, wavelength, amplitude, [strict=False])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • wavelength - wavelength of triangular waveform

  • amplitude - amplitude of triangular waveform

  • strict - By default the wavelength argument is treated as a „maximum wavelength”, where the actual wavelength will be dynamically adjusted so that an exact number of triangular waves are created along the boundaries of the geometry. If the strict argument is set to true then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.

Példák

  • triangular_wave(geom_from_wkt('LineString(0 0, 10 0)'), 3, 1) → Triangular waves with wavelength 3 and amplitude 1 along the linestring

13.2.13.127. triangular_wave_randomized

Constructs randomized triangular waves along the boundary of a geometry.

Szintaxis

triangular_wave_randomized(geometry, min_wavelength, max_wavelength, min_amplitude, max_amplitude, [seed=0])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • min_wavelength - minimum wavelength of waves

  • max_wavelength - maximum wavelength of waves

  • min_amplitude - minimum amplitude of waves

  • max_amplitude - maximum amplitude of waves

  • seed - specifies a random seed for generating waves. If the seed is 0, then a completely random set of waves will be generated.

Példák

  • triangular_wave_randomized(geom_from_wkt('LineString(0 0, 10 0)'), 2, 3, 0.1, 0.2) → Randomly sized triangular waves with wavelengths between 2 and 3 and amplitudes between 0.1 and 0.2 along the linestring

13.2.13.128. union

Returns a geometry that represents the point set union of the geometries.

Szintaxis

union(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • geom_to_wkt( union( make_point(4, 4), make_point(5, 5) ) ) → «MULTIPOINT(4 4, 5 5)»

13.2.13.129. wave

Constructs rounded (sine-like) waves along the boundary of a geometry.

Szintaxis

wave(geometry, wavelength, amplitude, [strict=False])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • wavelength - wavelength of sine-like waveform

  • amplitude - amplitude of sine-like waveform

  • strict - By default the wavelength argument is treated as a „maximum wavelength”, where the actual wavelength will be dynamically adjusted so that an exact number of waves are created along the boundaries of the geometry. If the strict argument is set to true then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.

Példák

  • wave(geom_from_wkt('LineString(0 0, 10 0)'), 3, 1) → Sine-like waves with wavelength 3 and amplitude 1 along the linestring

13.2.13.130. wave_randomized

Constructs randomized curved (sine-like) waves along the boundary of a geometry.

Szintaxis

wave_randomized(geometry, min_wavelength, max_wavelength, min_amplitude, max_amplitude, [seed=0])

[] marks optional arguments

Argumentumok

  • geometry - a geometry

  • min_wavelength - minimum wavelength of waves

  • max_wavelength - maximum wavelength of waves

  • min_amplitude - minimum amplitude of waves

  • max_amplitude - maximum amplitude of waves

  • seed - specifies a random seed for generating waves. If the seed is 0, then a completely random set of waves will be generated.

Példák

  • wave_randomized(geom_from_wkt('LineString(0 0, 10 0)'), 2, 3, 0.1, 0.2) → Randomly sized curved waves with wavelengths between 2 and 3 and amplitudes between 0.1 and 0.2 along the linestring

13.2.13.131. wedge_buffer

Returns a wedge shaped buffer originating from a point geometry.

Szintaxis

wedge_buffer(center, azimuth, width, outer_radius, [inner_radius=0.0])

[] marks optional arguments

Argumentumok

  • center - center point (origin) of buffer. Must be a point geometry.

  • azimuth - angle (in degrees) for the middle of the wedge to point.

  • width - buffer width (in degrees). Note that the wedge will extend to half of the angular width either side of the azimuth direction.

  • outer_radius - outer radius for buffers

  • inner_radius - optional inner radius for buffers

Példák

  • wedge_buffer(center:=geom_from_wkt('POINT(1 2)'),azimuth:=90,width:=180,outer_radius:=1) → A wedge shaped buffer centered on the point (1,2), facing to the East, with a width of 180 degrees and outer radius of 1.

Further reading: Create wedge buffers algorithm

13.2.13.132. within

Tests whether a geometry is within another. Returns TRUE if the geometry1 is completely within geometry2.

Szintaxis

within(geometry1, geometry2)

Argumentumok

  • geometry1 - a geometry

  • geometry2 - a geometry

Példák

  • within( geom_from_wkt( 'POINT( 0.5 0.5)' ), geom_from_wkt( 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' ) ) → TRUE

  • within( geom_from_wkt( 'POINT( 5 5 )' ), geom_from_wkt( 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0 ))' ) ) → FALSE

Further reading: overlay_within

13.2.13.133. $x

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.

Szintaxis

$x

Példák

  • $x → 42

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.

Szintaxis

x(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • x( geom_from_wkt( 'POINT(2 5)' ) ) → 2

  • x( $geometry ) → x coordinate of the current feature’s centroid

13.2.13.135. $x_at

Retrieves a x coordinate of the current feature’s geometry.

Szintaxis

$x_at(i)

Argumentumok

  • i - index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)

Példák

  • $x_at(1) → 5

13.2.13.136. x_max

Returns the maximum x coordinate of a geometry. Calculations are in the spatial reference system of this geometry.

Szintaxis

x_max(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • x_max( geom_from_wkt( 'LINESTRING(2 5, 3 6, 4 8)') ) → 4

13.2.13.137. x_min

Returns the minimum x coordinate of a geometry. Calculations are in the spatial reference system of this geometry.

Szintaxis

x_min(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • x_min( geom_from_wkt( 'LINESTRING(2 5, 3 6, 4 8)') ) → 2

13.2.13.138. $y

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.

Szintaxis

$y

Példák

  • $y → 42

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.

Szintaxis

y(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • y( geom_from_wkt( 'POINT(2 5)' ) ) → 5

  • y( $geometry ) → y coordinate of the current feature’s centroid

13.2.13.140. $y_at

Retrieves a y coordinate of the current feature’s geometry.

Szintaxis

$y_at(i)

Argumentumok

  • i - index of point of a line (indices start at 0; negative values apply from the last index, starting at -1)

Példák

  • $y_at(1) → 2

13.2.13.141. y_max

Returns the maximum y coordinate of a geometry. Calculations are in the spatial reference system of this geometry.

Szintaxis

y_max(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • y_max( geom_from_wkt( 'LINESTRING(2 5, 3 6, 4 8)') ) → 8

13.2.13.142. y_min

Returns the minimum y coordinate of a geometry. Calculations are in the spatial reference system of this geometry.

Szintaxis

y_min(geometry)

Argumentumok

  • geometry - a geometry

Példák

  • y_min( geom_from_wkt( 'LINESTRING(2 5, 3 6, 4 8)') ) → 5

13.2.13.143. $z

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.

Szintaxis

$z

Példák

  • $z → 123

13.2.13.144. z

Returns the z coordinate of a point geometry, or NULL if the geometry has no z value.

Szintaxis

z(geometry)

Argumentumok

  • geometry - a point geometry

Példák

  • z( geom_from_wkt( 'POINTZ(2 5 7)' ) ) → 7

13.2.13.145. z_max

Returns the maximum z coordinate of a geometry, or NULL if the geometry has no z value.

Szintaxis

z_max(geometry)

Argumentumok

  • geometry - a geometry with z coordinate

Példák

  • z_max( geom_from_wkt( 'POINT ( 0 0 1 )' ) ) → 1

  • z_max( geom_from_wkt( 'MULTIPOINT ( 0 0 1 , 1 1 3 )' ) ) → 3

  • z_max( make_line( make_point( 0,0,0 ), make_point( -1,-1,-2 ) ) ) → 0

  • z_max( geom_from_wkt( 'LINESTRING( 0 0 0, 1 0 2, 1 1 -1 )' ) ) → 2

  • z_max( geom_from_wkt( 'POINT ( 0 0 )' ) ) → NULL

13.2.13.146. z_min

Returns the minimum z coordinate of a geometry, or NULL if the geometry has no z value.

Szintaxis

z_min(geometry)

Argumentumok

  • geometry - a geometry with z coordinate

Példák

  • z_min( geom_from_wkt( 'POINT ( 0 0 1 )' ) ) → 1

  • z_min( geom_from_wkt( 'MULTIPOINT ( 0 0 1 , 1 1 3 )' ) ) → 1

  • z_min( make_line( make_point( 0,0,0 ), make_point( -1,-1,-2 ) ) ) → -2

  • z_min( geom_from_wkt( 'LINESTRING( 0 0 0, 1 0 2, 1 1 -1 )' ) ) → -1

  • z_min( geom_from_wkt( 'POINT ( 0 0 )' ) ) → NULL

13.2.14. Layout Functions

This group contains functions to manipulate print layout items properties.

13.2.14.1. item_variables

Returns a map of variables from a layout item inside this print layout.

Szintaxis

item_variables(id)

Argumentumok

  • id - layout item ID

Példák

  • map_get( item_variables('Map 0'), 'map_scale') → scale of the item «Map 0» in the current print layout

Further reading: List of default variables

13.2.14.2. map_credits

Returns a list of credit (usage rights) strings for the layers shown in a layout map item.

Szintaxis

map_credits(id, [include_layer_names=false], [layer_name_separator=»: «])

[] marks optional arguments

Argumentumok

  • id - map item ID

  • include_layer_names - Set to true to include layer names before their credit strings

  • layer_name_separator - String to insert between layer names and their credit strings, if include_layer_names is true

Példák

  • array_to_string( map_credits( 'Main Map' ) ) → comma separated list of layer credits for 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.

13.2.15. Map Layers

This group contains a list of the available layers in the current project and, for each layer, their fields (stored in the dataset, virtual or auxiliary ones as well as from joins). The fields can be interacted the same way as mentioned in Fields and Values, except that a double-click will add the name as a string (single quoted) to the expression instead of as a field reference given that they do not belong to the active layer. This offers a convenient way to write expressions referring to different layers, such as when performing aggregates, attribute or spatial queries.

It also provides some convenient functions to manipulate layers.

13.2.15.1. decode_uri

Takes a layer and decodes the uri of the underlying data provider. It depends on the dataprovider, which data is available.

Szintaxis

decode_uri(layer, [part])

[] marks optional arguments

Argumentumok

  • layer - The layer for which the uri should be decoded.

  • part - The part of the uri to return. If unspecified, a map with all uri parts will be returned.

Példák

  • decode_uri(@layer) → {«layerId»: «0», «layerName»: «», «path»: «/home/qgis/shapefile.shp»}

  • decode_uri(@layer) → {«layerId»: NULL, «layerName»: «layer», «path»: «/home/qgis/geopackage.gpkg»}

  • decode_uri(@layer, 'path') → «C:\my_data\qgis\shape.shp»

13.2.15.2. layer_property

Returns a matching layer property or metadata value.

Szintaxis

layer_property(layer, property)

Argumentumok

  • layer - a string, representing either a layer name or layer ID

  • property - a string corresponding to the property to return. Valid options are:

    • name: layer name

    • id: layer ID

    • title: metadata title string

    • abstract: metadata abstract string

    • keywords: metadata keywords

    • data_url: metadata URL

    • attribution: metadata attribution string

    • attribution_url: metadata attribution URL

    • source: layer source

    • min_scale: minimum display scale for layer

    • max_scale: maximum display scale for layer

    • is_editable: if layer is in edit mode

    • crs: layer CRS

    • crs_definition: layer CRS full definition

    • crs_description: layer CRS description

    • extent: layer extent (as a geometry object)

    • distance_units: layer distance units

    • type: layer type, e.g., Vector or Raster

    • storage_type: storage format (vector layers only)

    • geometry_type: geometry type, e.g., Point (vector layers only)

    • feature_count: approximate feature count for layer (vector layers only)

    • path: File path to the layer data source. Only available for file based layers.

Példák

  • layer_property('streets','title') → «Basemap Streets»

  • layer_property('airports','feature_count') → 120

  • layer_property('landsat','crs') → «EPSG:4326»

Further reading: vector, raster and mesh layer properties

13.2.16. Maps Functions

This group contains functions to create or manipulate keys and values of map data structures (also known as dictionary objects, key-value pairs, or associative arrays). Unlike the list data structure where values order matters, the order of the key-value pairs in the map object is not relevant and values are identified by their keys.

13.2.16.1. from_json

Loads a JSON formatted string.

Szintaxis

from_json(string)

Argumentumok

  • string - JSON string

Példák

  • from_json('{"qgis":"rocks"}') → { «qgis»: «rocks» }

  • from_json('[1,2,3]') → [1,2,3]

13.2.16.2. hstore_to_map

Creates a map from a hstore-formatted string.

Szintaxis

hstore_to_map(string)

Argumentumok

  • string - the input string

Példák

  • hstore_to_map('qgis=>rocks') → { «qgis»: «rocks» }

13.2.16.3. map

Returns a map containing all the keys and values passed as pair of parameters.

Szintaxis

map(key1, value1, key2, value2, …)

Argumentumok

  • key - a key (string)

  • value - a value

Példák

  • map('1','one','2', 'two') → { «1»: «one», «2»: «two» }

  • map('1','one','2', 'two')['1'] → «one»

13.2.16.4. map_akeys

Returns all the keys of a map as an array.

Szintaxis

map_akeys(map)

Argumentumok

  • map - a map

Példák

  • map_akeys(map('1','one','2','two')) → [ «1», «2» ]

13.2.16.5. map_avals

Returns all the values of a map as an array.

Szintaxis

map_avals(map)

Argumentumok

  • map - a map

Példák

  • map_avals(map('1','one','2','two')) → [ «one», «two» ]

13.2.16.6. map_concat

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.

Szintaxis

map_concat(map1, map2, …)

Argumentumok

  • map - a map

Példák

  • map_concat(map('1','one', '2','overridden'),map('2','two', '3','three')) → { «1»: «one», «2»: «two», «3»: «three» }

13.2.16.7. map_delete

Returns a map with the given key and its corresponding value deleted.

Szintaxis

map_delete(map, key)

Argumentumok

  • map - a map

  • key - the key to delete

Példák

  • map_delete(map('1','one','2','two'),'2') → { «1»: «one» }

13.2.16.8. map_exist

Returns TRUE if the given key exists in the map.

Szintaxis

map_exist(map, key)

Argumentumok

  • map - a map

  • key - the key to lookup

Példák

  • map_exist(map('1','one','2','two'),'3') → FALSE

13.2.16.9. map_get

Returns the value of a map, given its key. Returns NULL if the key does not exist.

Szintaxis

map_get(map, key)

Argumentumok

  • map - a map

  • key - the key to lookup

Példák

  • 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 the current print layout

Tipp

You can also use the index operator ([]) to get a value from a map.

13.2.16.10. map_insert

Returns a map with an added key/value. If the key already exists, its value is overridden.

Szintaxis

map_insert(map, key, value)

Argumentumok

  • map - a map

  • key - the key to add

  • value - the value to add

Példák

  • map_insert(map('1','one'),'3','three') → { «1»: «one», «3»: «three» }

  • map_insert(map('1','one','2','overridden'),'2','two') → { «1»: «one», «2»: «two» }

13.2.16.11. map_prefix_keys

Returns a map with all keys prefixed by a given string.

Szintaxis

map_prefix_keys(map, prefix)

Argumentumok

  • map - a map

  • prefix - a string

Példák

  • map_prefix_keys(map('1','one','2','two'), 'prefix-') → { «prefix-1»: «one», «prefix-2»: «two» }

13.2.16.12. map_to_hstore

Merge map elements into a hstore-formatted string.

Szintaxis

map_to_hstore(map)

Argumentumok

  • map - the input map

Példák

  • map_to_hstore(map('qgis','rocks')) → «„qgis”=>”rocks”»

13.2.16.13. to_json

Create a JSON formatted string from a map, array or other value.

Szintaxis

to_json(value)

Argumentumok

  • value - The input value

Példák

  • to_json(map('qgis','rocks')) → {„qgis”:”rocks”}

  • to_json(array(1,2,3)) → [1,2,3]

13.2.16.14. url_encode

Returns an URL encoded string from a map. Transforms all characters in their properly-encoded form producing a fully-compliant query string.

Note that the plus sign «+» is not converted.

Szintaxis

url_encode(map)

Argumentumok

  • map - a map.

Példák

  • url_encode(map('a&+b', 'a and plus b', 'a=b', 'a equals b')) → «a%26+b=a%20and%20plus%20b&a%3Db=a%20equals%20b»

13.2.17. Mathematical Functions

This group contains math functions (e.g., square root, sin and cos).

13.2.17.1. abs

Returns the absolute value of a number.

Szintaxis

abs(value)

Argumentumok

  • value - a number

Példák

  • abs(-2) → 2

13.2.17.2. acos

Returns the inverse cosine of a value in radians.

Szintaxis

acos(value)

Argumentumok

  • value - cosine of an angle in radians

Példák

  • acos(0.5) → 1.0471975511966

13.2.17.3. asin

Returns the inverse sine of a value in radians.

Szintaxis

asin(value)

Argumentumok

  • value - sine of an angle in radians

Példák

  • asin(1.0) → 1.5707963267949

13.2.17.4. atan

Returns the inverse tangent of a value in radians.

Szintaxis

atan(value)

Argumentumok

  • value - tan of an angle in radians

Példák

  • atan(0.5) → 0.463647609000806

13.2.17.5. atan2

Returns the inverse tangent of dy/dx by using the signs of the two arguments to determine the quadrant of the result.

Szintaxis

atan2(dy, dx)

Argumentumok

  • dy - y coordinate difference

  • dx - x coordinate difference

Példák

  • atan2(1.0, 1.732) → 0.523611477769969

13.2.17.6. ceil

Rounds a number upwards.

Szintaxis

ceil(value)

Argumentumok

  • value - a number

Példák

  • ceil(4.9) → 5

  • ceil(-4.9) → -4

13.2.17.7. clamp

Restricts an input value to a specified range.

Szintaxis

clamp(minimum, input, maximum)

Argumentumok

  • minimum - the smallest value input is allowed to take.

  • input - a value which will be restricted to the range specified by minimum and maximum

  • maximum - the largest value input is allowed to take

Példák

  • clamp(1,5,10) → 5

    input is between 1 and 10 so is returned unchanged

  • clamp(1,0,10) → 1

    input is less than minimum value of 1, so function returns 1

  • clamp(1,11,10) → 10

    input is greater than maximum value of 10, so function returns 10

13.2.17.8. cos

Returns cosine of an angle.

Szintaxis

cos(angle)

Argumentumok

  • angle - angle in radians

Példák

  • cos(1.571) → 0.000796326710733263

13.2.17.9. degrees

Converts from radians to degrees.

Szintaxis

degrees(radians)

Argumentumok

  • radians - numeric value

Példák

  • degrees(3.14159) → 180

  • degrees(1) → 57.2958

13.2.17.10. exp

Returns exponential of an value.

Szintaxis

exp(value)

Argumentumok

  • value - number to return exponent of

Példák

  • exp(1.0) → 2.71828182845905

13.2.17.11. floor

Rounds a number downwards.

Szintaxis

floor(value)

Argumentumok

  • value - a number

Példák

  • floor(4.9) → 4

  • floor(-4.9) → -5

13.2.17.12. ln

Returns the natural logarithm of a value.

Szintaxis

ln(value)

Argumentumok

  • value - numeric value

Példák

  • ln(1) → 0

  • ln(2.7182818284590452354) → 1

13.2.17.13. log

Returns the value of the logarithm of the passed value and base.

Szintaxis

log(base, value)

Argumentumok

  • base - any positive number

  • value - any positive number

Példák

  • log(2, 32) → 5

  • log(0.5, 32) → -5

13.2.17.14. log10

Returns the value of the base 10 logarithm of the passed expression.

Szintaxis

log10(value)

Argumentumok

  • value - any positive number

Példák

  • log10(1) → 0

  • log10(100) → 2

13.2.17.15. max

Returns the largest value in a set of values.

Szintaxis

max(value1, value2, …)

Argumentumok

  • value - a number

Példák

  • max(2,10.2,5.5) → 10.2

  • max(20.5,NULL,6.2) → 20.5

13.2.17.16. min

Returns the smallest value in a set of values.

Szintaxis

min(value1, value2, …)

Argumentumok

  • value - a number

Példák

  • min(20.5,10,6.2) → 6.2

  • min(2,-10.3,NULL) → -10.3

13.2.17.17. pi

Returns value of pi for calculations.

Szintaxis

pi()

Példák

  • pi() → 3.14159265358979

13.2.17.18. radians

Converts from degrees to radians.

Szintaxis

radians(degrees)

Argumentumok

  • degrees - numeric value

Példák

  • radians(180) → 3.14159

  • radians(57.2958) → 1

13.2.17.19. rand

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.

Szintaxis

rand(min, max, [seed=NULL])

[] marks optional arguments

Argumentumok

  • min - an integer representing the smallest possible random number desired

  • max - an integer representing the largest possible random number desired

  • seed - any value to use as seed

Példák

  • rand(1, 10) → 8

13.2.17.20. randf

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.

Szintaxis

randf([min=0.0], [max=1.0], [seed=NULL])

[] marks optional arguments

Argumentumok

  • min - an float representing the smallest possible random number desired

  • max - an float representing the largest possible random number desired

  • seed - any value to use as seed

Példák

  • randf(1, 10) → 4.59258286403147

13.2.17.21. round

Rounds a number to number of decimal places.

Szintaxis

round(value, [places=0])

[] marks optional arguments

Argumentumok

  • value - decimal number to be rounded

  • places - Optional integer representing number of places to round decimals to. Can be negative.

Példák

  • round(1234.567, 2) → 1234.57

  • round(1234.567) → 1235

  • round(1234.567, -1) → 1230

13.2.17.22. scale_exp

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.

Szintaxis

scale_exp(value, domain_min, domain_max, range_min, range_max, exponent)

Argumentumok

  • value - A value in the input domain. The function will return a corresponding scaled value in the output range.

  • domain_min - Specifies the minimum value in the input domain, the smallest value the input value should take.

  • domain_max - Specifies the maximum value in the input domain, the largest value the input value should take.

  • range_min - Specifies the minimum value in the output range, the smallest value which should be output by the function.

  • range_max - Specifies the maximum value in the output range, the largest value which should be output by the function.

  • exponent - A positive value (greater than 0), which dictates the way input values are mapped to the output range. Large exponents will cause the output values to «ease in», starting slowly before accelerating as the input values approach the domain maximum. Smaller exponents (less than 1) will cause output values to «ease out», where the mapping starts quickly but slows as it approaches the domain maximum.

Példák

  • scale_exp(5,0,10,0,100,2) → 25

    easing in, using an exponent of 2

  • scale_exp(3,0,10,0,100,0.5) → 54.772

    easing out, using an exponent of 0.5

13.2.17.23. scale_linear

Transforms a given value from an input domain to an output range using linear interpolation.

Szintaxis

scale_linear(value, domain_min, domain_max, range_min, range_max)

Argumentumok

  • value - A value in the input domain. The function will return a corresponding scaled value in the output range.

  • domain_min - Specifies the minimum value in the input domain, the smallest value the input value should take.

  • domain_max - Specifies the maximum value in the input domain, the largest value the input value should take.

  • range_min - Specifies the minimum value in the output range, the smallest value which should be output by the function.

  • range_max - Specifies the maximum value in the output range, the largest value which should be output by the function.

Példák

  • scale_linear(5,0,10,0,100) → 50

  • scale_linear(0.2,0,1,0,360) → 72

    scaling a value between 0 and 1 to an angle between 0 and 360

  • scale_linear(1500,1000,10000,9,20) → 9.6111111

    scaling a population which varies between 1000 and 10000 to a font size between 9 and 20

13.2.17.24. sin

Returns the sine of an angle.

Szintaxis

sin(angle)

Argumentumok

  • angle - angle in radians

Példák

  • sin(1.571) → 0.999999682931835

13.2.17.25. sqrt

Returns square root of a value.

Szintaxis

sqrt(value)

Argumentumok

  • value - a number

Példák

  • sqrt(9) → 3

13.2.17.26. tan

Returns the tangent of an angle.

Szintaxis

tan(angle)

Argumentumok

  • angle - angle in radians

Példák

  • tan(1.0) → 1.5574077246549

13.2.18. Meshes Functions

This group contains functions which calculate or return mesh related values.

13.2.18.1. $face_area

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.

Szintaxis

$face_area

Példák

  • $face_area → 42

13.2.18.2. $face_index

Returns the index of the current mesh face.

Szintaxis

$face_index

Példák

  • $face_index → 4581

13.2.18.3. $vertex_as_point

Returns the current vertex as a point geometry.

Szintaxis

$vertex_as_point

Példák

  • geom_to_wkt( $vertex_as_point ) → «POINT(800 1500 41)»

13.2.18.4. $vertex_index

Returns the index of the current mesh vertex.

Szintaxis

$vertex_index

Példák

  • $vertex_index → 9874

13.2.18.5. $vertex_x

Returns the X coordinate of the current mesh vertex.

Szintaxis

$vertex_x

Példák

  • $vertex_x → 42.12

13.2.18.6. $vertex_y

Returns the Y coordinate of the current mesh vertex.

Szintaxis

$vertex_y

Példák

  • $vertex_y → 12.24

13.2.18.7. $vertex_z

Returns the Z value of the current mesh vertex.

Szintaxis

$vertex_z

Példák

  • $vertex_z → 42

13.2.19. Operators

This group contains operators (e.g., +, -, *). Note that for most of the mathematical functions below, if one of the inputs is NULL then the result is NULL.

13.2.19.1. %

Remainder of division. Takes the sign of the dividend.

Szintaxis

a % b

Argumentumok

  • a - value

  • b - value

Példák

  • 9 % 2 → 1

  • 9 % -2 → 1

  • -9 % 2 → -1

  • 5 % NULL → NULL

13.2.19.2. *

Multiplication of two values

Szintaxis

a * b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 * 4 → 20

  • 5 * NULL → NULL

13.2.19.3. +

Addition of two values. If one of the values is NULL the result will be NULL.

Szintaxis

a + b

Argumentumok

  • a - value

  • b - value

Példák

  • 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

Further reading: concat, ||

13.2.19.4. -

Subtraction of two values. If one of the values is NULL the result will be NULL.

Szintaxis

a - b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 - 4 → 1

  • 5 - NULL → NULL

  • to_datetime('2012-05-05 12:00:00') - to_interval('1 day 2 hours') → 2012-05-04T10:00:00

13.2.19.5. /

Division of two values

Szintaxis

a / b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 / 4 → 1.25

  • 5 / NULL → NULL

13.2.19.6. <

Compares two values and evaluates to 1 if the left value is less than the right value.

Szintaxis

a < b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 < 4 → FALSE

  • 5 < 5 → FALSE

  • 4 < 5 → TRUE

13.2.19.7. <=

Compares two values and evaluates to 1 if the left value is less or equal than the right value.

Szintaxis

a <= b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 <= 4 → FALSE

  • 5 <= 5 → TRUE

  • 4 <= 5 → TRUE

13.2.19.8. <>

Compares two values and evaluates to 1 if they are not equal.

Szintaxis

a <> b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 <> 4 → TRUE

  • 4 <> 4 → FALSE

  • 5 <> NULL → NULL

  • NULL <> NULL → NULL

13.2.19.9. =

Compares two values and evaluates to 1 if they are equal.

Szintaxis

a = b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 = 4 → FALSE

  • 4 = 4 → TRUE

  • 5 = NULL → NULL

  • NULL = NULL → NULL

13.2.19.10. >

Compares two values and evaluates to 1 if the left value is greater than the right value.

Szintaxis

a > b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 > 4 → TRUE

  • 5 > 5 → FALSE

  • 4 > 5 → FALSE

13.2.19.11. >=

Compares two values and evaluates to 1 if the left value is greater or equal than the right value.

Szintaxis

a >= b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 >= 4 → TRUE

  • 5 >= 5 → TRUE

  • 4 >= 5 → FALSE

13.2.19.12. AND

Returns TRUE when conditions a and b are true.

Szintaxis

a AND b

Argumentumok

  • a - condition

  • b - condition

Példák

  • TRUE AND TRUE → TRUE

  • TRUE AND FALSE → FALSE

  • 4 = 2+2 AND 1 = 1 → TRUE

  • 4 = 2+2 AND 1 = 2 → FALSE

13.2.19.13. BETWEEN

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.

Szintaxis

value BETWEEN lower_bound AND higher_bound

Argumentumok

  • value - the value to compare with a range. It can be a string, a number or a date.

  • lower_bound AND higher_bound - range bounds

Példák

  • 'B' BETWEEN 'A' AND 'C' → TRUE

  • 2 BETWEEN 1 AND 3 → TRUE

  • 2 BETWEEN 2 AND 3 → TRUE

  • 'B' BETWEEN 'a' AND 'c' → FALSE

  • lower('B') BETWEEN 'a' AND 'b' → TRUE

Megjegyzés

value BETWEEN lower_bound AND higher_bound is the same as „value >= lower_bound AND value <= higher_bound”.

Further reading: NOT BETWEEN

13.2.19.14. ILIKE

Returns TRUE if the first parameter matches case-insensitive the supplied pattern. LIKE can be used instead of ILIKE to make the match case-sensitive. Works with numbers also.

Szintaxis

string/number ILIKE pattern

Argumentumok

  • string/number - string to search

  • pattern - pattern to find, you can use «%» as a wildcard, «_» as a single char and «\\» to escape these special characters.

Példák

  • 'A' ILIKE 'A' → TRUE

  • 'A' ILIKE 'a' → TRUE

  • 'A' ILIKE 'B' → FALSE

  • 'ABC' ILIKE 'b' → FALSE

  • 'ABC' ILIKE 'B' → FALSE

  • 'ABC' ILIKE '_b_' → TRUE

  • 'ABC' ILIKE '_B_' → TRUE

  • 'ABCD' ILIKE '_b_' → FALSE

  • 'ABCD' ILIKE '_B_' → FALSE

  • 'ABCD' ILIKE '_b%' → TRUE

  • 'ABCD' ILIKE '_B%' → TRUE

  • 'ABCD' ILIKE '%b%' → TRUE

  • 'ABCD' ILIKE '%B%' → TRUE

  • 'ABCD%' ILIKE 'abcd\\%' → TRUE

  • 'ABCD' ILIKE '%B\\%' → FALSE

13.2.19.15. IN

Returns TRUE if value is found within a list of values.

Szintaxis

a IN b

Argumentumok

  • a - value

  • b - list of values

Példák

  • 'A' IN ('A','B') → TRUE

  • 'A' IN ('C','B') → FALSE

13.2.19.16. IS

Returns TRUE if a is the same as b.

Szintaxis

a IS b

Argumentumok

  • a - any value

  • b - any value

Példák

  • 'A' IS 'A' → TRUE

  • 'A' IS 'a' → FALSE

  • 4 IS 4 → TRUE

  • 4 IS 2+2 → TRUE

  • 4 IS 2 → FALSE

  • $geometry IS NULL → 0, if your geometry is not NULL

13.2.19.17. IS NOT

Returns TRUE if a is not the same as b.

Szintaxis

a IS NOT b

Argumentumok

  • a - value

  • b - value

Példák

  • 'a' IS NOT 'b' → TRUE

  • 'a' IS NOT 'a' → FALSE

  • 4 IS NOT 2+2 → FALSE

13.2.19.18. LIKE

Returns TRUE if the first parameter matches the supplied pattern. Works with numbers also.

Szintaxis

string/number LIKE pattern

Argumentumok

  • string/number - value

  • pattern - pattern to compare value with, you can use «%» as a wildcard, «_» as a single char and «\\» to escape these special characters.

Példák

  • 'A' LIKE 'A' → TRUE

  • 'A' LIKE 'a' → FALSE

  • 'A' LIKE 'B' → FALSE

  • 'ABC' LIKE 'B' → FALSE

  • 'ABC' LIKE '_B_' → TRUE

  • 'ABCD' LIKE '_B_' → FALSE

  • 'ABCD' LIKE '_B%' → TRUE

  • 'ABCD' LIKE '%B%' → TRUE

  • '1%' LIKE '1\\%' → TRUE

  • '1_' LIKE '1\\%' → FALSE

13.2.19.19. NOT

Negates a condition.

Szintaxis

NOT a

Argumentumok

  • a - condition

Példák

  • NOT 1 → FALSE

  • NOT 0 → TRUE

13.2.19.20. NOT BETWEEN

Returns TRUE if value is not within the specified range. The range is considered inclusive of the bounds.

Szintaxis

value NOT BETWEEN lower_bound AND higher_bound

Argumentumok

  • value - the value to compare with a range. It can be a string, a number or a date.

  • lower_bound AND higher_bound - range bounds

Példák

  • 'B' NOT BETWEEN 'A' AND 'C' → FALSE

  • 1.0 NOT BETWEEN 1.1 AND 1.2 → TRUE

  • 2 NOT BETWEEN 2 AND 3 → FALSE

  • 'B' NOT BETWEEN 'a' AND 'c' → TRUE

  • lower('B') NOT BETWEEN 'a' AND 'b' → FALSE

Megjegyzés

value NOT BETWEEN lower_bound AND higher_bound is the same as „value < lower_bound OR value > higher_bound”.

Further reading: BETWEEN

13.2.19.21. OR

Returns TRUE when condition a or b is true.

Szintaxis

a OR b

Argumentumok

  • a - condition

  • b - condition

Példák

  • 4 = 2+2 OR 1 = 1 → TRUE

  • 4 = 2+2 OR 1 = 2 → TRUE

  • 4 = 2   OR 1 = 2 → FALSE

13.2.19.22. []

Index operator. Returns an element from an array or map value.

Szintaxis

[index]

Argumentumok

  • index - array index or map key value

Példák

  • array(1,2,3)[0] → 1

  • array(1,2,3)[2] → 3

  • array(1,2,3)[-1] → 3

  • map('a',1,'b',2)['a'] → 1

  • map('a',1,'b',2)['b'] → 2

Further reading: array_get, map_get

13.2.19.23. ^

Power of two values.

Szintaxis

a ^ b

Argumentumok

  • a - value

  • b - value

Példák

  • 5 ^ 4 → 625

  • 5 ^ NULL → NULL

13.2.19.24. ||

Joins two values together into a string.

If one of the values is NULL the result will be NULL. See the CONCAT function for a different behavior.

Szintaxis

a || b

Argumentumok

  • a - value

  • b - value

Példák

  • 'Here' || ' and ' || 'there' → «Here and there»

  • 'Nothing' || NULL → NULL

  • 'Dia: ' || "Diameter" → «Dia: 25»

  • 1 || 2 → «12»

Further reading: concat, +

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).

Szintaxis

string ~ regex

Argumentumok

  • string - A string value

  • regex - A regular expression. Slashes must be escaped, eg \\d.

Példák

  • 'hello' ~ 'll' → TRUE

  • 'hello' ~ '^ll' → FALSE

  • 'hello' ~ 'llo$' → TRUE

  • 'abc123' ~ '\\d+' → TRUE

Further reading: regexp_match

13.2.20. Processing Functions

This group contains functions that operate on processing algorithms.

13.2.20.1. parameter

Returns the value of a processing algorithm input parameter.

Szintaxis

parameter(name)

Argumentumok

  • name - name of the corresponding input parameter

Példák

  • parameter('BUFFER_SIZE') → 5.6

13.2.21. Rasters Functions

This group contains functions to operate on raster layer.

13.2.21.1. raster_statistic

Returns statistics from a raster layer.

Szintaxis

raster_statistic(layer, band, property)

Argumentumok

  • layer - a string, representing either a raster layer name or layer ID

  • band - integer representing the band number from the raster layer, starting at 1

  • property - a string corresponding to the property to return. Valid options are:

    • min: minimum value

    • max: maximum value

    • avg: average (mean) value

    • stdev: standard deviation of values

    • range: range of values (max - min)

    • sum: sum of all values from raster

Példák

  • raster_statistic('lc',1,'avg') → Average value from band 1 from «lc» raster layer

  • raster_statistic('ac2010',3,'min') → Minimum value from band 3 from «ac2010» raster layer

13.2.21.2. raster_value

Returns the raster value found at the provided point.

Szintaxis

raster_value(layer, band, point)

Argumentumok

  • layer - the name or id of a raster layer

  • band - the band number to sample the value from.

  • point - point geometry (for multipart geometries having more than one part, a NULL value will be returned)

Példák

  • raster_value('dem', 1, make_point(1,1)) → 25

13.2.22. Record and Attributes Functions

This group contains functions that operate on record identifiers.

13.2.22.1. attribute

Returns an attribute from a feature.

Variant 1

Returns the value of an attribute from the current feature.

Szintaxis

attribute(attribute_name)

Argumentumok

  • attribute_name - name of attribute to be returned

Példák

  • attribute( 'name' ) → value stored in «name» attribute for the current feature

Variant 2

Allows the target feature and attribute name to be specified.

Szintaxis

attribute(feature, attribute_name)

Argumentumok

  • feature - a feature

  • attribute_name - name of attribute to be returned

Példák

  • attribute( @atlas_feature, 'name' ) → value stored in «name» attribute for the current atlas feature

13.2.22.2. attributes

Returns a map containing all attributes from a feature, with field names as map keys.

Variant 1

Returns a map of all attributes from the current feature.

Szintaxis

attributes()

Példák

  • attributes()['name'] → value stored in «name» attribute for the current feature

Variant 2

Allows the target feature to be specified.

Szintaxis

attributes(feature)

Argumentumok

  • feature - a feature

Példák

  • attributes( @atlas_feature )['name'] → value stored in «name» attribute for the current atlas feature

Further reading: Maps Functions

13.2.22.3. $currentfeature

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.

Szintaxis

$currentfeature

Példák

  • attribute( $currentfeature, 'name' ) → value stored in «name» attribute for the current feature

13.2.22.4. display_expression

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.

Szintaxis

display_expression()

Példák

  • display_expression() → The display expression of the current feature in the current layer.

One «feature» parameter

If called with a «feature» parameter only, the function will evaluate the specified feature from the current layer.

Szintaxis

display_expression(feature)

Argumentumok

  • feature - The feature which should be evaluated.

Példák

  • display_expression(@atlas_feature) → The display expression of the current atlas feature.

Layer and feature parameters

If the function is called with both a layer and a feature, it will evaluate the specified feature from the specified layer.

Szintaxis

display_expression(layer, feature, [evaluate=true])

[] marks optional arguments

Argumentumok

  • layer - The layer (or its ID or name)

  • feature - The feature which should be evaluated.

  • 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).

Példák

  • display_expression( 'streets', get_feature_by_id('streets', 1)) → The display expression of the feature with the ID 1 on the layer «streets».

  • display_expression('a_layer_id', $currentfeature, 'False') → The display expression of the given feature not evaluated.

13.2.22.5. get_feature

Returns the first feature of a layer matching a given attribute value.

Single value variant

Along with the layer ID, a single column and value are specified.

Szintaxis

get_feature(layer, attribute, value)

Argumentumok

  • layer - layer name or ID

  • attribute - attribute name to use for the match

  • value - attribute value to match

Példák

  • get_feature('streets','name','main st') → first feature found in „streets” layer with „main st” value in the „name” field

Map variant

Along with the layer ID, a map containing the columns (key) and their respective value to be used.

Szintaxis

get_feature(layer, attribute)

Argumentumok

  • layer - layer name or ID

  • attribute - Map containing the column and value pairs to use

Példák

  • get_feature('streets',map('name','main st','lane_num','4')) → first feature found in „streets” layer with „main st” value in the „name” field and „4” value in the „lane_num” field

13.2.22.6. get_feature_by_id

Returns the feature with an id on a layer.

Szintaxis

get_feature_by_id(layer, feature_id)

Argumentumok

  • layer - layer, layer name or layer id

  • feature_id - the id of the feature which should be returned

Példák

  • get_feature_by_id('streets', 1) → the feature with the id 1 on the layer „streets”

Further reading: $id

13.2.22.7. $id

Returns the feature id of the current row. WARNING: This function is deprecated. It is recommended to use the replacement @id variable instead.

Szintaxis

$id

Példák

  • $id → 42

13.2.22.8. is_selected

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.

Szintaxis

is_selected()

Példák

  • is_selected() → TRUE if the current feature in the current layer is selected.

One «feature» parameter

If called with a «feature» parameter only, the function returns TRUE if the specified feature from the current layer is selected.

Szintaxis

is_selected(feature)

Argumentumok

  • feature - The feature which should be checked for selection.

Példák

  • is_selected(@atlas_feature) → TRUE if the current atlas feature is selected.

  • is_selected(get_feature('streets', 'name', 'Main St.')) → TRUE if the unique named „Main St.” feature on the active „streets” layer is selected.

  • is_selected(get_feature_by_id('streets', 1)) → TRUE if the feature with the id 1 on the active „streets” layer is selected.

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.

Szintaxis

is_selected(layer, feature)

Argumentumok

  • layer - The layer (its ID or name) on which the selection will be checked.

  • feature - The feature which should be checked for selection.

Példák

  • is_selected( 'streets', get_feature('streets', 'name', "street_name")) → TRUE if the current building’s street is selected (assuming the building layer has a field named «street_name» and the «streets» layer has a field called «name» with unique values).

  • is_selected( 'streets', get_feature_by_id('streets', 1)) → TRUE if the feature with the id 1 on the „streets” layer is selected.

13.2.22.9. maptip

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.

Szintaxis

maptip()

Példák

  • maptip() → The maptip of the current feature in the current layer.

One «feature» parameter

If called with a «feature» parameter only, the function will evaluate the specified feature from the current layer.

Szintaxis

maptip(feature)

Argumentumok

  • feature - The feature which should be evaluated.

Példák

  • maptip(@atlas_feature) → The maptip of the current atlas feature.

Layer and feature parameters

If the function is called with both a layer and a feature, it will evaluate the specified feature from the specified layer.

Szintaxis

maptip(layer, feature, [evaluate=true])

[] marks optional arguments

Argumentumok

  • layer - The layer (or its ID or name)

  • feature - The feature which should be evaluated.

  • 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_template» function).

Példák

  • maptip('streets', get_feature_by_id('streets', 1)) → The maptip of the feature with the ID 1 on the layer «streets».

  • maptip('a_layer_id', $currentfeature, 'False') → The maptip of the given feature not evaluated.

13.2.22.10. num_selected

Returns the number of selected features on a given layer. By default works on the layer on which the expression is evaluated.

Szintaxis

num_selected([layer=current layer])

[] marks optional arguments

Argumentumok

  • layer - The layer (or its id or name) on which the selection will be checked.

Példák

  • num_selected() → The number of selected features on the current layer.

  • num_selected('streets') → The number of selected features on the layer streets

13.2.22.11. represent_attributes

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.

Szintaxis

represent_attributes()

Példák

  • represent_attributes() → The representation of the attributes for the current feature.

One «feature» parameter

If called with a «feature» parameter only, the function will return the representation of the attributes of the specified feature from the current layer.

Szintaxis

represent_attributes(feature)

Argumentumok

  • feature - The feature which should be evaluated.

Példák

  • represent_attributes(@atlas_feature) → The representation of the attributes for the specified feature from the current layer.

Layer and feature parameters

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.

Szintaxis

represent_attributes(layer, feature)

Argumentumok

  • layer - The layer (or its ID or name).

  • feature - The feature which should be evaluated.

Példák

  • represent_attributes('atlas_layer', @atlas_feature) → The representation of the attributes for the specified feature from the specified layer.

Further reading: represent_value

13.2.22.12. represent_value

Returns the configured representation value for a field value. It depends on the configured widget type. Often, this is useful for «Value Map» widgets.

Szintaxis

represent_value(value, [fieldName])

[] marks optional arguments

Argumentumok

  • value - The value which should be resolved. Most likely a field.

  • fieldName - The field name for which the widget configuration should be loaded.

Példák

  • represent_value("field_with_value_map") → Description for value

  • represent_value('static value', 'field_name') → Description for static value

Further reading: widget types, represent_attributes

13.2.22.13. sqlite_fetch_and_increment

Manage autoincrementing values in sqlite databases.

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.

Szintaxis

sqlite_fetch_and_increment(database, table, id_field, filter_attribute, filter_value, [default_values])

[] marks optional arguments

Argumentumok

  • database - Path to the sqlite file or geopackage layer

  • table - Name of the table that manages the sequences

  • id_field - Name of the field that contains the current value

  • filter_attribute - Name the field that contains a unique identifier for this sequence. Must have a UNIQUE index.

  • filter_value - Name of the sequence to use.

  • default_values - Map with default values for additional columns on the table. The values need to be fully quoted. Functions are allowed.

Példák

  • sqlite_fetch_and_increment(@layer, 'sequence_table', 'last_unique_id', 'sequence_id', 'global', map('last_change', 'date(''now'')', 'user', '''' || @user_account_name || '''')) → 0

  • sqlite_fetch_and_increment(layer_property(@layer, 'path'), 'sequence_table', 'last_unique_id', 'sequence_id', 'global', map('last_change', 'date(''now'')', 'user', '''' || @user_account_name || '''')) → 0

Further reading: Data Sources Properties, Creating one or many to many relations

13.2.22.14. uuid

Generates a Universally Unique Identifier (UUID) for each row using the Qt QUuid::createUuid method.

Szintaxis

uuid([format=»WithBraces»])

[] marks optional arguments

Argumentumok

  • format - The format, as the UUID will be formatted. «WithBraces», «WithoutBraces» or «Id128».

Példák

  • uuid() → «{0bd2f60f-f157-4a6d-96af-d4ba4cb366a1}»

  • uuid('WithoutBraces') → «0bd2f60f-f157-4a6d-96af-d4ba4cb366a1»

  • uuid('Id128') → «0bd2f60ff1574a6d96afd4ba4cb366a1»

13.2.23. Relations

This group contains the list of the relations available in the current project, with their description. It provides a quick access to the relation ID for writing an expression (with e.g. the relation_aggregate function) or customizing a form.

13.2.24. String Functions

This group contains functions that operate on strings (e.g., that replace, convert to upper case).

13.2.24.1. ascii

Returns the unicode code associated with the first character of a string.

Szintaxis

ascii(string)

Argumentumok

  • string - the string to convert to unicode code

Példák

  • ascii('Q') → 81

13.2.24.2. char

Returns the character associated with a unicode code.

Szintaxis

char(code)

Argumentumok

  • code - a unicode code number

Példák

  • char(81) → «Q»

13.2.24.3. concat

Concatenates several strings to one. NULL values are converted to empty strings. Other values (like numbers) are converted to strings.

Szintaxis

concat(string1, string2, …)

Argumentumok

  • string - a string value

Példák

  • concat('sun', 'set') → «sunset»

  • concat('a','b','c','d','e') → «abcde»

  • concat('Anno ', 1984) → «Anno 1984»

  • concat('The Wall', NULL) → «The Wall»

About fields concatenation

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:

    'My feature id is: ' + NULL ==> NULL
    'My feature id is: ' || NULL => NULL
    concat('My feature id is: ', NULL) => 'My feature id is: '
    

further reading: ||, +

13.2.24.4. format

Format a string using supplied arguments.

Szintaxis

format(string, arg1, arg2, …)

Argumentumok

  • string - A string with placeholders %1, %2, etc., for the arguments. Placeholders can be repeated. The lowest numbered placeholder is replaced by arg1, the next by arg2, etc.

  • arg - any type. Any number of arguments.

Példák

  • format('This %1 a %2','is', 'test') → «This is a test»

  • format('This is %2','a bit unexpected but 2 is lowest number in string','normal') → «This is a bit unexpected but 2 is lowest number in string»

13.2.24.5. format_date

Formats a date type or string into a custom string format. Uses Qt date/time format strings. See QDateTime::toString.

Szintaxis

format_date(datetime, format, [language])

[] marks optional arguments

Argumentumok

  • datetime - date, time or datetime value

  • format - String template used to format the string.

    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»)

    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.

Példák

  • 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

  • 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»

13.2.24.6. format_number

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.

Szintaxis

format_number(number, [places=0], [language], [omit_group_separators=false], [trim_trailing_zeroes=false])

[] marks optional arguments

Argumentumok

  • number - number to be formatted

  • places - integer representing the number of decimal places to truncate the string to.

  • language - language (lowercase, two- or three-letter, ISO 639 language code) used to format the number into a string. By default the current QGIS user locale is used.

  • omit_group_separators - if set to true then group separators will not be included in the string

  • trim_trailing_zeroes - if set to true then trailing zeros following the decimal point will be trimmed from the string

Példák

  • format_number(10000000.332,2) → «10,000,000.33» if e.g. the current locale is an English variant

  • format_number(10000000.332,2,'fr') → «10 000 000,33»

13.2.24.7. left

Returns a substring that contains the n leftmost characters of the string.

Szintaxis

left(string, length)

Argumentumok

  • string - a string

  • length - integer. The number of characters from the left of the string to return.

Példák

  • left('Hello World',5) → «Hello»

13.2.24.8. length

Returns the number of characters in a string or the length of a geometry linestring.

String variant

Returns the number of characters in a string.

Szintaxis

length(string)

Argumentumok

  • string - string to count length of

Példák

  • length('hello') → 5

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.

Szintaxis

length(geometry)

Argumentumok

  • geometry - line geometry object

Példák

  • length(geom_from_wkt('LINESTRING(0 0, 4 0)')) → 4.0

13.2.24.9. lower

Converts a string to lower case letters.

Szintaxis

lower(string)

Argumentumok

  • string - the string to convert to lower case

Példák

  • lower('HELLO World') → «hello world»

13.2.24.10. lpad

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.

Szintaxis

lpad(string, width, fill)

Argumentumok

  • string - string to pad

  • width - length of new string

  • fill - character to pad the remaining space with

Példák

  • lpad('Hello', 10, 'x') → «xxxxxHello»

  • lpad('Hello', 3, 'x') → «Hel»

13.2.24.11. regexp_match

Return the first matching position matching a regular expression within an unicode string, or 0 if the substring is not found.

Szintaxis

regexp_match(input_string, regex)

Argumentumok

  • input_string - the string to test against the regular expression

  • regex - The regular expression to test against. Backslash characters must be double escaped (e.g., „\\s” to match a white space character or „\\b” to match a word boundary).

Példák

  • regexp_match('QGIS ROCKS','\\sROCKS') → 5

  • regexp_match('Budač','udač\\b') → 2

13.2.24.12. regexp_replace

Returns a string with the supplied regular expression replaced.

Szintaxis

regexp_replace(input_string, regex, replacement)

Argumentumok

  • input_string - the string to replace matches in

  • regex - The regular expression to replace. Backslash characters must be double escaped (e.g., „\\s” to match a white space character).

  • replacement - The string that will replace any matching occurrences of the supplied regular expression. Captured groups can be inserted into the replacement string using \\1, \\2, etc.

Példák

  • regexp_replace('QGIS SHOULD ROCK','\\sSHOULD\\s',' DOES ') → «QGIS DOES ROCK»

  • regexp_replace('ABC123','\\d+','') → «ABC»

  • regexp_replace('my name is John','(.*) is (.*)','\\2 is \\1') → «John is my name»

13.2.24.13. regexp_substr

Returns the portion of a string which matches a supplied regular expression.

Szintaxis

regexp_substr(input_string, regex)

Argumentumok

  • input_string - the string to find matches in

  • regex - The regular expression to match against. Backslash characters must be double escaped (e.g., „\\s” to match a white space character).

Példák

  • regexp_substr('abc123','(\\d+)') → «123»

13.2.24.14. replace

Returns a string with the supplied string, array, or map of strings replaced.

String & array variant

Returns a string with the supplied string or array of strings replaced by a string or an array of strings.

Szintaxis

replace(string, before, after)

Argumentumok

  • string - the input string

  • before - the string or array of strings to replace

  • after - the string or array of strings to use as a replacement

Példák

  • replace('QGIS SHOULD ROCK','SHOULD','DOES') → «QGIS DOES ROCK»

  • replace('QGIS ABC',array('A','B','C'),array('X','Y','Z')) → «QGIS XYZ»

  • replace('QGIS',array('Q','S'),'') → «GI»

Map variant

Returns a string with the supplied map keys replaced by paired values. Longer map keys are evaluated first.

Szintaxis

replace(string, map)

Argumentumok

  • string - the input string

  • map - the map containing keys and values

Példák

  • replace('APP SHOULD ROCK',map('APP','QGIS','SHOULD','DOES')) → «QGIS DOES ROCK»

  • replace('forty two',map('for','4','two','2','forty two','42')) → «42»

13.2.24.16. rpad

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.

Szintaxis

rpad(string, width, fill)

Argumentumok

  • string - string to pad

  • width - length of new string

  • fill - character to pad the remaining space with

Példák

  • rpad('Hello', 10, 'x') → «Helloxxxxx»

  • rpad('Hello', 3, 'x') → «Hel»

13.2.24.17. strpos

Return the first matching position of a substring within another string, or 0 if the substring is not found.

Szintaxis

strpos(haystack, needle)

Argumentumok

  • haystack - string that is to be searched

  • needle - string to search for

Példák

  • strpos('HELLO WORLD','WORLD') → 7

  • strpos('HELLO WORLD','GOODBYE') → 0

13.2.24.18. substr

Returns a part of a string.

Szintaxis

substr(string, start, [length])

[] marks optional arguments

Argumentumok

  • string - the full input string

  • start - integer representing start position to extract beginning with 1; if start is negative, the return string will begin at the end of the string minus the start value

  • length - integer representing length of string to extract; if length is negative, the return string will omit the given length of characters from the end of the string

Példák

  • substr('HELLO WORLD',3,5) → «LLO W»

  • substr('HELLO WORLD',6) → « WORLD»

  • substr('HELLO WORLD',-5) → «WORLD»

  • substr('HELLO',3,-1) → «LL»

  • substr('HELLO WORLD',-5,2) → «WO»

  • substr('HELLO WORLD',-5,-1) → «WORL»

13.2.24.19. title

Converts all words of a string to title case (all words lower case with leading capital letter).

Szintaxis

title(string)

Argumentumok

  • string - the string to convert to title case

Példák

  • title('hello WOrld') → «Hello World»

13.2.24.20. to_string

Converts a number to string.

Szintaxis

to_string(number)

Argumentumok

  • number - Integer or real value. The number to convert to string.

Példák

  • to_string(123) → «123»

13.2.24.21. trim

Removes all leading and trailing whitespace (spaces, tabs, etc) from a string.

Szintaxis

trim(string)

Argumentumok

  • string - string to trim

Példák

  • trim('   hello world  ') → «hello world»

13.2.24.22. upper

Converts a string to upper case letters.

Szintaxis

upper(string)

Argumentumok

  • string - the string to convert to upper case

Példák

  • upper('hello WOrld') → «HELLO WORLD»

13.2.24.23. wordwrap

Returns a string wrapped to a maximum/minimum number of characters.

Szintaxis

wordwrap(string, wrap_length, [delimiter_string])

[] marks optional arguments

Argumentumok

  • string - the string to be wrapped

  • wrap_length - an integer. If wrap_length is positive the number represents the ideal maximum number of characters to wrap; if negative, the number represents the minimum number of characters to wrap.

  • delimiter_string - Optional delimiter string to wrap to a new line.

Példák

  • wordwrap('UNIVERSITY OF QGIS',13) → «UNIVERSITY OF<br>QGIS»

  • wordwrap('UNIVERSITY OF QGIS',-3) → «UNIVERSITY<br>OF QGIS»

13.2.25. User Expressions

This group contains the expressions saved as user expressions.

13.2.26. Variables

This group contains dynamic variables related to the application, the project file and other settings. The availability of variables depends on the context:

  • from the expressionSelect Select by expression dialog

  • from the calculateField Field calculator dialog

  • from the layer properties dialog

  • from the print layout

To use these variables in an expression, they should be preceded by the @ character (e.g, @row_number).

Variable

Leírás

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

current_parent_feature

represents the feature currently being edited in the parent form. Only usable in an embedded form context.

current_parent_geometry

represents the geometry of the feature currently being edited in the parent form. Only usable in an embedded form context.

form_mode

What the form is used for, like AddFeatureMode, SingleEditMode, MultiEditMode, SearchMode, AggregateSearchMode or IdentifyMode as string.

feature NEW in 3.28

The current feature being evaluated. This can be used with the «attribute» function to evaluate 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

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

geometry_ring_num

Current geometry ring number for feature being rendered (for polygon features only). The 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

layout_pageheight

The active page height in the layout (in mm for standard paper sizes, or whatever unit was used for custom paper size)

layout_pageoffsets

Array of Y coordinate of the top of each page. Allows to dynamically position items on pages in a context where page sizes may change

layout_pagewidth

The active page width in the layout (in mm for standard paper sizes, or whatever unit was used 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

map_crs_projection

The descriptive name of the projection method used by the Coordinate reference system of the 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

map_extent_height

The current height of the map

map_extent_width

The current width of the map

map_id

The ID of current map destination. This will be «canvas» for canvas renders, and the item ID for 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

model_path

Full path (including file name) of current model (or project path if model is embedded in a 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

notification_message

Content of the notification message sent by the provider (available only for actions triggered by provider notifications).

parent

Refers to the current feature in the parent layer, providing access to its attributes and geometry 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

project_distance_units

The distance unit for the current project, used when calculating lengths of geometries and distances

project_ellipsoid

The name of the ellipsoid of the current project, used when calculating geodetic areas or 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

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

Selected file path from file widget selector when uploading a file with an external storage 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)

symbol_label

The label for the symbol (either a user defined label or the default autogenerated label - in the 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

vector_tile_zoom

Exact vector tile zoom level of the map that is being rendered (derived from the current map 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.

with_variable

Allows setting a variable for usage within an expression and avoid recalculating the same value repeatedly

zoom_level

Vector tile zoom level of the map that is being rendered (derived from the current map scale). Normally in interval [0, 20].

Some examples:

  • Return the X coordinate of a map item center in layout:

    x( map_get( item_variables( 'map1'), 'map_extent_center' ) )
    
  • Return, for each feature in the current layer, the number of overlapping airport features:

    aggregate( layer:='airport', aggregate:='count', expression:="code",
                   filter:=intersects( $geometry, geometry( @parent ) ) )
    
  • Get the object_id of the first snapped point of a line:

    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'
      )
    )
    

13.2.27. Recent Functions

This group contains recently used functions. Depending on the context of its usage (feature selection, field calculator, generic), recently applied expressions are added to the corresponding list (up to ten expressions), sorted from more to less recent. This makes it easy to quickly retrieve and reapply previously used expressions.