arcade函数
来自:https://developers.arcgis.com/arcade/function-reference/math_functions/
Abs
Abs( value ) -> Number
Returns the absolute value of a number. If the input is null
, then it returns 0.
Name | Type | Description |
---|---|---|
value | Number | A number on which to perform the operation. |
Returns: 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.
Name | Type | Description |
---|---|---|
value | Number | A number between -1 and 1 on which to perform the operation. |
Returns: 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.
Name | Type | Description |
---|---|---|
value | Number | A number between -1 and 1 on which to perform the operation. |
Returns: 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.
Name | Type | Description |
---|---|---|
value | Number | A number on which to perform the operation. |
Returns: 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.
Name | Type | Description |
---|---|---|
y | Number | A number representing the y-coordinate. |
x | Number | A number representing the x-coordinate. |
Returns: Number
Example
prints -2.356194
Atan2(-1, -1)
Average
Average( values, fieldName? ) -> Number
Returns the average of a set of numbers. In profiles that support accessing data, this function can return the average value of a given numeric field in a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | A list or array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 5
var array = [0,10]
Average(0,10,5,array)
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.
Name | Type | Description |
---|---|---|
value | Number | The number to round upward. |
numPlaces | Number | optional The number of decimal places to round the value to. Default is 0. Trailing zeros will be truncated. |
Returns: Number
Example
prints 2135.1
Ceil(2135.0905, 2)
Constrain
Constrain( value, min, max ) -> 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.
Name | Type | Description |
---|---|---|
value | Number | The value to constrain to the given min and max bounds. |
min | Number | The lower bound by which to constrain the input value . If the given value is less than the min , then min is returned. |
max | Number | The upper bound by which to constrain the input value . If the given value is greater than the max , then max is returned. |
Returns: Number
Example
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.
Name | Type | Description |
---|---|---|
value | Number | A number in radians on which to perform the operation. |
Returns: 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
.
Name | Type | Description |
---|---|---|
x | Number | The power, or number of times to multiply e to itself. |
Returns: 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.
Name | Type | Description |
---|---|---|
value | Number | A number to round downward. |
numPlaces | Number | optional The number of decimal places to round the number. Default is 0. Trailing zeros will be truncated. |
Returns: Number
Example
prints 2316.25
Floor(2316.2562, 2)
Log
Log( x ) -> Number
Returns the natural logarithm (base e) of x.
Name | Type | Description |
---|---|---|
x | Number | A number on which to perform the operation. |
Returns: Number
Example
prints 2.302585
Log(10)
Max
Max( values, fieldName? ) -> Number
Returns the highest value from an array of numbers. In profiles that support accessing data, this function can return the highest value for a given numeric field from a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 89
Max([23,56,89])
prints 120
Max(23,5,120,43,9)
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
Mean( values, fieldName? ) -> Number
Since version 1.1
Returns the mean value of an array of numbers. In profiles that support accessing data, this function can return the mean value of a given numeric field in a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | A list or array of numbers from which to calculate the mean. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
Use a single array as input
returns 5
var vals = [1,2,3,4,5,6,7,8,9];
Mean(vals);
Use comma separated values with array element
returns 5
var array = [0,10];
Mean(0,10,5,array);
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
Min( values, fieldName? ) -> Number
Returns the lowest value in a given array. In profiles that support accessing data, this function can return the lowest value for a given numeric field from a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 23
Min([23,56,89])
prints 5
Min(23,5,120,43,9)
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.
Name | Type | Description |
---|---|---|
x | Number | The base value. |
y | Number | The exponent. This indicates the number of times to multiply x by itself. |
Returns: Number
Example
prints 9
Pow(3, 2)
Random
Random( ) -> Number
Returns a random number between 0 and 1.
Name | Type | Description |
---|
Returns: 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.
Name | Type | Description |
---|---|---|
value | Number | A number to round. |
numPlaces | Number | optional The number of decimal places to round the number to. Default is 0 . Trailing zeros will be truncated. |
Returns: Number
Example
prints 2316.26
Round(2316.2562, 2)
Sin
Sin( value ) -> Number
Returns the sine of the input value.
Name | Type | Description |
---|---|---|
value | Number | A number in radians on which to perform the operation. |
Returns: Number
Example
prints 0.841741
Sin(1)
Sqrt
Sqrt( value ) -> Number
Returns the square root of a number.
Name | Type | Description |
---|---|---|
value | Number | A number on which to calculate the square root. |
Returns: Number
Example
prints 3
Sqrt(9)
Stdev
Stdev( values, fieldName? ) -> Number
Returns the standard deviation (population standard deviation) of a set of numbers. In profiles that support accessing data, this function can return the standard deviation for the values from a given numeric field in a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | An array or list of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 27.5
Stdev(23,56,89,12,45,78)
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
Sum( values, fieldName? ) -> Number
Returns the sum of a set of numbers. In profiles that support accessing data, this function can return the sum of values returned from a given numeric field in a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 303
Sum(23,56,89,12,45,78)
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.
Name | Type | Description |
---|---|---|
value | Number | A number on which to calculate the tangent. |
Returns: Number
Example
prints 0.57389
Tan(0.521)
Variance
Variance( values, fieldName? ) -> Number
Returns the variance (population variance) of a set of numbers. In profiles that support accessing data, this function can return the variance of the values from a given numeric field in a FeatureSet.
Name | Type | Description |
---|---|---|
values | Number[] | FeatureSet | An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. |
fieldName | Text | optional Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified. |
Returns: Number
Example
prints 756.25
Variance(12,23,45,56,78,89)
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')
=================================================
Text Functions
Concatenate
Concatenate( values, separator?, format? ) -> Text
Concatenates values together and returns a text value.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
values | Text[] | An array of text values to concatenate. | ||||||||||||||||||||||||||||||||||||||||||||||
separator | Text | optional Separator to use for concatenation if values parameter is an array. Or text to concatenate, if a single value is provided for the first parameter. If not provided will be empty. |
||||||||||||||||||||||||||||||||||||||||||||||
format | Text | optional Formatting text for dates or numbers. This parameter is available in Arcade version 1.3 and later. See the list of possible values below.
|
Returns: Text
Example
prints 'red/blue/green'
Concatenate(['red', 'blue', 'green'], '/')
Find
Find( searchText, text, startpos? ) -> Number
Finds a string of characters within a text value. Wildcards are NOT supported.
Name | Type | Description |
---|---|---|
searchText | Text | The character string to search for. |
text | Text | The text to search. |
startpos | Number | optional The zero-based index of the location in the text to search from. |
Returns: Number
Example
prints 6
Find('380', 'Esri, 380 New York Street', 0)
Left
Left( value, charCount ) -> Text
Returns the specified number of characters from the beginning of a text value.
Name | Type | Description |
---|---|---|
value | Text | Array | Number | Boolean | The text from which to get characters. |
charCount | Number | The number of characters to get from the beginning of the text. |
Returns: Text
Example
prints 'the'
Left('the quick brown fox', 3)
Lower
Lower( value ) -> Text
Makes a text value lower case.
Name | Type | Description |
---|---|---|
value | Text | The text to be made lowercase. |
Returns: Text
Example
prints 'hello'
Lower('HELLO')
Mid
Mid( value, startpos, charCount ) -> Text
Gets a number of characters from the middle of a text value.
Name | Type | Description |
---|---|---|
value | Text | Array | Number | Boolean | The text from which to get characters. |
startpos | Number | The starting position from which to get the text. 0 is the first position. |
charCount | Number | The number of characters to extract. |
Returns: Text
Example
prints 'quick'
Mid('the quick brown fox', 4, 5)
Proper
Proper( value, applyTo? ) -> Text
Converts a text value to title case. By default, the beginning of every word is capitalized. The option firstword
will capitalize only the first word.
Name | Type | Description |
---|---|---|
value | Text | The text to convert to title case. |
applyTo | Text | optional A text value specifying the type of capitalization to be performed. By default every word is capitalized. This parameter accepts one of two values: everyword or firstword . |
Returns: Text
Example
prints 'The Quick Brown Fox'
Proper('the quick brown fox', 'everyword')
Replace
Replace( value, searchText, replacementText, allOccurrences? ) -> Text
Replaces a string within a text value or an element within an array. Defaults to replacing all occurrences.
Name | Type | Description |
---|---|---|
value | Text | Array | Number | Boolean | The value in which to make replacements. |
searchText | Text | The text to search for. |
replacementText | Text | The replacement text. |
allOccurrences | Boolean | optional Indicates if all occurrences of the searchText should be replaced in the text. Defaults to true . |
Returns: Text
Example
prints 'the quick red fox'
Replace('the quick brown fox', 'brown', 'red')
Right
Right( value, charCount ) -> Text
Returns the specified number of characters from the end of a text value.
Name | Type | Description |
---|---|---|
value | Text | Array | Number | Boolean | The text from which to get characters. |
charCount | Number | The number of characters to get from the end of the text value. |
Returns: Text
Example
prints 'fox'
Right('the quick brown fox', 3)
Split
Split( value, separator, limit?, removeEmpty? ) -> Text[]
Splits a text value into an array.
Name | Type | Description |
---|---|---|
value | Text | The text value to be split. |
separator | Text | The separator used to split the text. |
limit | Number | optional An integer that specifies the number of splits. |
removeEmpty | Boolean | optional Indicates whether to remove empty values. By default this is false . |
Returns: Text[]
Example
returns '[red,green]'
Split('red,green,blue,orange', ',', 2)
Trim
Trim( value ) -> Text
Removes spaces from the beginning or end of an input text value.
Name | Type | Description |
---|---|---|
value | Text | The text to be trimmed. |
Returns: Text
Example
prints 'hello world'
Trim(' hello world')
Upper
Upper( value ) -> Text
Makes text upper case.
Name | Type | Description |
---|---|---|
value | Text | The text value to be made uppercase. |
Returns: Text
Example
prints 'HELLO'
Upper('Hello')
UrlEncode
UrlEncode( url ) -> Text
Since version 1.7
Encodes a URL by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.
Name | Type | Description |
---|---|---|
url | Text | Dictionary | The URL to be encoded. |
Returns: Text
Example
Encodes the URL provided
var urlsource ='arcgis-survey123://?';
var params = {
itemID:'36ff9e8c13e042a58cfce4ad87f55d19',
center: '43.567,-117.380'
};
return urlsource + UrlEncode(params);
//arcgis-survey123://?center=43.567%2C-117.380&itemID=36ff9e8c13e042a58cfce4ad87f55d19