Mathematical Functions

Functions for performing mathematical operations.


Abs

Abs(value) -> Number

Returns the absolute value of a number. If the input is null, then it returns 0.

Parameter

  • value: Number - A number on which to perform the operation.

Return value: Number

Example

prints 3

Abs(-3)

Acos

Acos(value) -> Number

Returns the arccosine of the input value in radians, in the range of zero to PI. If the input value is outside the appropriate range of +/- 1, then NaN is returned.

Parameter

  • value: Number - A number between -1 and 1 on which to perform the operation.

Return value: Number

Example

prints 1.266104

Acos(0.3)

Asin

Asin(value) -> Number

Returns the arcsine of the input value in radians, in the range of -PI/2 and PI/2. If the input value is outside the appropriate range of +/- 1, then NaN is returned.

Parameter

  • value: Number - A number between -1 and 1 on which to perform the operation.

Return value: Number

Example

prints 0.304693

Asin(0.3)

Atan

Atan(value) -> Number

Returns the arctangent of the input value in radians, in the range of -PI/2 and PI/2.

Parameter

  • value: Number - A number on which to perform the operation.

Return value: Number

Example

prints 0.785398

Atan(1)

Atan2

Atan2(y, x) -> Number

Returns the arctangent of the quotient of the input values in radians, in the range of -PI and zero or zero and PI depending on the sign of arguments.

Parameters

  • y: Number - A number representing the y-coordinate.
  • x: Number - A number representing the x-coordinate.

Return value: Number

Example

prints -2.356194

Atan2(-1, -1)

Average

This function has 2 signatures:

Average(numbers) -> Number

Returns the average of a set of numbers.

Parameter

  • numbers: Array<Number> - A list or array of numbers on which to perform the operation.

Return value: Number

Example

prints 5

var values = [0,5,10]
Average(values)

Average(features, fieldNameOrSQLExpression) -> Number

Returns the average value of a given numeric field in a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operation.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

calculates the difference between the feature's population and the average population of all features in the layer

$feature.population - Average($layer, 'population')

calculates the average population per square mile of all features in the layer

Average($layer, 'population / area')

Ceil

Ceil(value, numPlaces?) -> Number

Returns the input value rounded upwards to the given number of decimal places.

Parameters

  • value: Number - The number to round upward.
  • numPlaces (Optional): Number - The number of decimal places to round the value to. Default is 0. Trailing zeros will be truncated.

Return value: Number

Example

prints 2135.1

Ceil(2135.0905, 2)

Constrain

Constrain(value, lowerBound, upperBound) -> Number

Since version 1.2

Constrains the given input value to minimum and maximum bounds. For example, if the input value is 10, the lower bound is 50, and the upper bound is 100, then 50 is returned.

Parameters

  • value: Number - The value to constrain to the given min and max bounds.
  • lowerBound: Number - The lower bound by which to constrain the input value. If the given value is less than the min, then min is returned.
  • upperBound: Number - The upper bound by which to constrain the input value. If the given value is greater than the max, then max is returned.

Return value: Number

Examples

returns 5

Constrain(5, 0, 10)

returns 0

Constrain(-3, 0, 10)

returns 10

Constrain(553, 0, 10)

Cos

Cos(value) -> Number

Returns the cosine of the input value in radians.

Parameter

  • value: Number - A number in radians on which to perform the operation.

Return value: Number

Example

prints 0.540302

Cos(1)

Exp

Exp(x) -> Number

Returns the value of e to the power of x, where e is the base of the natural logarithm 2.718281828.

Parameter

  • x: Number - The power, or number of times to multiply e to itself.

Return value: Number

Example

prints 7.389056

Exp(2)

Floor

Floor(value, numPlaces?) -> Number

Returns the input value rounded downward to the given number of decimal places.

Parameters

  • value: Number - A number to round downward.
  • numPlaces (Optional): Number - The number of decimal places to round the number. Default is 0. Trailing zeros will be truncated.

Return value: Number

Example

prints 2316.25

Floor(2316.2562, 2)

Log

Log(x) -> Number

Returns the natural logarithm (base e) of x.

Parameter

  • x: Number - A number on which to perform the operation.

Return value: Number

Example

prints 2.302585

Log(10)

Max

This function has 2 signatures:

Max(numbers) -> Number

Returns the highest value from an array of numbers.

Parameter

  • numbers: Array<Number> - An array or list of numbers.

Return value: Number

Examples

prints 89

Max([23,56,89])

prints 120

Max(23,5,120,43,9)

Max(features, fieldNameOrSQLExpression) -> Number

Returns the highest value for a given numeric field from a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operation.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

prints the max value of the population field for all features in the layer

Max($layer, 'population')

calculates the max population per square mile of all features in the layer

Max($layer, 'population / area')

Mean

This function has 2 signatures:

Mean(numbers) -> Number

Since version 1.1

Returns the mean value of an array of numbers.

Parameter

  • numbers: Array<Number> - A list or array of numbers from which to calculate the mean.

Return value: Number

Examples

Use a single array as input.

var values = [1,2,3,4,5,6,7,8,9];
Mean(values);
// returns 5

Use comma separated values with array element.

var values = [0,10];
Mean(0,10,5,values);
// returns 5

Mean(features, fieldNameOrSQLExpression) -> Number

Since version 1.1

Returns the mean value of a given numeric field in a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to calculate the mean.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

calculates the difference between the feature's population and the mean population of all features in the layer

$feature.population - Mean($layer, 'population')

calculates the mean population per square mile of all features in the layer

Mean($layer, 'population / area')

Min

This function has 2 signatures:

Min(numbers) -> Number

Returns the lowest value in a given array.

Parameter

  • numbers: Array<Number> - An array or list of numbers.

Return value: Number

Examples

prints 23

Min([23,56,89])

prints 5

Min(23,5,120,43,9)

Min(features, fieldNameOrSQLExpression) -> Number

Returns the lowest value for a given numeric field from a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operaiton.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

prints the min value of the population field for all features in the layer

Min($layer, 'population')

returns the minimum population per square mile of all features in the layer

Min($layer, 'population / area')

Pow

Pow(x, y) -> Number

Returns the value of x to the power of y.

Parameters

  • x: Number - The base value.
  • y: Number - The exponent. This indicates the number of times to multiply x by itself.

Return value: Number

Example

prints 9

Pow(3, 2)

Random

Random() -> Number

Returns a random number between 0 and 1.

Return value: Number

Example
Random()

Round

Round(value, numPlaces?) -> Number

Returns the input value, rounded to the given number of decimal places.
Note: If you're looking to format a value for display in a label or popup, use the text function.

Parameters

  • value: Number - A number to round.
  • numPlaces (Optional): Number - The number of decimal places to round the number to. Default is 0. Trailing zeros will be truncated.

Return value: Number

Example

prints 2316.26

Round(2316.2562, 2)

Sin

Sin(value) -> Number

Returns the sine of the input value.

Parameter

  • value: Number - A number in radians on which to perform the operation.

Return value: Number

Example

prints 0.841741

Sin(1)

Sqrt

Sqrt(value) -> Number

Returns the square root of a number.

Parameter

  • value: Number - A number on which to calculate the square root.

Return value: Number

Example

prints 3

Sqrt(9)

Stdev

This function has 2 signatures:

Stdev(numbers) -> Number

Returns the standard deviation (population standard deviation) of a set of numbers.

Parameter

  • numbers: Array<Number> - An array or list of numbers on which to perform the operation.

Return value: Number

Example

prints 27.5

Stdev(23,56,89,12,45,78)

Stdev(features, fieldNameOrSQLExpression) -> Number

Returns the standard deviation for the values from a given numeric field in a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operation.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

prints the standard deviation of values from the 'population' field

Stdev($layer, 'population')

calculates the standard deviation of the population per square mile of all features in the layer

Stdev($layer, 'population / area')

Sum

This function has 2 signatures:

Sum(numbers) -> Number

Returns the sum of a set of numbers.

Parameter

  • numbers: Array<Number> - An array of numbers on which to perform the operation.

Return value: Number

Example

prints 303

Sum(23,56,89,12,45,78)

Sum(features, fieldNameOrSQLExpression) -> Number

Returns the sum of values returned from a given numeric field in a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operation.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

calculates the population of the current feature as a % of the total population of all features in the layer

( $feature.population / Sum($layer, 'population') ) * 100

calculates the total number of votes cast in an election for the entire dataset

Sum($layer, 'democrat + republican + other')

Tan

Tan(value) -> Number

Returns the tangent of an angle in radians.

Parameter

  • value: Number - A number on which to calculate the tangent.

Return value: Number

Example

prints 0.57389

Tan(0.521)

Variance

This function has 2 signatures:

Variance(numbers) -> Number

Returns the variance (population variance) of a set of numbers.

Parameter

  • numbers: Array<Number> - An array of numbers on which to perform the operation.

Return value: Number

Example

prints 756.25

Variance(12,23,45,56,78,89)

Variance(features, fieldNameOrSQLExpression) -> Number

Returns the variance of the values from a given numeric field in a FeatureSet.

Parameters

  • features: FeatureSet - A FeatureSet on which to perform the operation.
  • fieldNameOrSQLExpression: Text - Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet.

Return value: Number

Examples

prints the variance for the population field in the given layer

Variance($layer, 'population')

calculates the variance of the population per square mile of all features in the layer

Variance($layer, 'population / area')

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.