ArcGIS Arcade
http://127.0.0.1/Resource/JavaScript/arcgis_js_api/sdk/4.10/latest/guide/arcade/index.html
https://developers.arcgis.com/arcade/function-reference/logical_functions/#when
Constants
The following constants are available for your convenience in writing expressions:
- Numbers: Infinity - PI
- Text: BackwardSlash - DoubleQuote - ForwardSlash - NewLine - SingleQuote - Tab
Infinity
Represents a value greater than any other number. -Infinity
may also be used as a value smaller than any number.
Example
Calculates the maximum of four field values
varvalues = [
$feature.field1,
$feature.field2,
$feature.field3,
$feature.field4 ];
varmax = -
Infinity;
for(
vari in values){
max = IIF(values[i] > max, values[i], max);
}
return max;
PI
The value of a circle's circumference divided by its diameter, approximately 3.14159
.
Example
Returns the area of a circle feature
varr =
$feature.radius;
PI * r * r;
TextFormatting.BackwardSlash
Inserts a backslash character \
into the text.
Example
Returns '\\serverName\foo\bar'
TextFormatting.BackwardSlash +
TextFormatting.BackwardSlash +
$feature.FILE_PATH
TextFormatting.DoubleQuote
Inserts a double quote character "
into the text.
Example
Returns 'Nicholas "Nick" Anderson'
$feature.NAME +
" "+
TextFormatting.
DoubleQuote+
$feature.ALIAS +
TextFormatting.
DoubleQuote+
" "+
$feature.SURNAME
TextFormatting.ForwardSlash
Inserts a forward slash character /
into the text.
Example
Returns '151/low'
$feature.POP_DENSITY +
TextFormatting.
ForwardSlash+
$feature.CLASS
TextFormatting.NewLine
Inserts a new line, or line break, into the text. Multi-line labels are NOT supported in the ArcGIS API 3.x for JavaScript nor in the ArcGIS Online map viewer.
Example
Returns "T2N R1W"
"T"+
$feature.TOWNSHIP +
TextFormatting.
NewLine+
"R"+
$feature.RANGE
TextFormatting.SingleQuote
Inserts a single quote character '
into the text.
Example
Returns "Nicholas 'Nick' Anderson"
$feature.NAME +
" "+
TextFormatting.
SingleQuote+
$feature.ALIAS +
TextFormatting.
SingleQuote+
" "+
$feature.SURNAME
TextFormatting.Tab
Inserts a tab into the text.
Example
Returns "T2N R1W"
"T"+
$feature.TOWNSHIP +
TextFormatting.
Tab+
"R"+
$feature.RANGE
Logical Functions
These functions provide convenient one-line methods for evaluating expressions. They include methods for checking for empty values, using if-else logic, and implementing switch-case statements among others.
Boolean
Boolean( value ) -> returns: Boolean
Attempts to convert the given non-boolean value to a boolean value. For example a string 'true' would become true.
Name | Type | Description |
value | A text or number value to be converted to a boolean. |
Returns: Boolean
Example
// returns `true`
Boolean('true')
// returns `false`. A value of 1 would return `true`
Boolean(0)
// returns `false`
Boolean('hello')
Decode
Decode( expression, [compare1, return1, ...compareN, returnN]?, default? ) -> returns: *
Evaluates an expression to a value and compares the result value with the value of subsequent parameters. If the expression evaluates to a matching value, it returns the subsequent parameter value. If no matches are found, then a default value may be provided. This is similar to a switch/case statement
Name | Type | Description |
expression | * | An Arcade expression that must evaluate to a value that can be compared with the provided case values. |
[compare1, return1, ...compareN, returnN] | * | optional A set of compare values and return value pairs. |
default | * | optional A default value to return if none of the compare values match. This may be a value of any type. |
Returns:
Type | Description |
* | Returns the matched return value. If no matches are found, then the default value is returned. |
Example
// returns a meaningful value when a field contains coded values
var code = $feature.codedValue;
var decodedValue = Decode(code, 1, 'Residential', 2, 'Commercial', 3, 'Mixed', 'Other');
DefaultValue
DefaultValue( value, defaultValue? ) -> returns: *
Replaces an empty value with a provided default value.
Name | Type | Description |
value | * | The input value to compare against null or ''. This may be a value of any type. However, if this value is an empty array, then the empty array will be returned. |
defaultValue | * | optional Return this value if the provided value is empty. This may be a value of any type. |
Returns:
Type | Description |
* | If value is empty, then the defaultValue is returned. Otherwise, the value of value is returned. This may be a value of any type. |
Example
// If a feature has no value in the POP_2000 field
// then 'no data' is returned
DefaultValue($feature.POP_2000, 'no data')
IIf
IIf( condition, trueValue, falseValue ) -> returns: *
Returns a given value if a conditional expression evaluates to true, and returns an alternate value if that condition evaluates to false.
Name | Type | Description |
condition | A logical expression that must evaluate to true or false. | |
trueValue | * | The value to return if the condition evaluates to true. This may be a value of any type. |
falseValue | * | The value to return if the condition evaluates to false. This may be a value of any type. |
Returns:
Type | Description |
* | If condition is true, then the trueValue is returned. Otherwise, the value of falseValue is returned. |
Example
// returns 'below' if the value is less than 1,000,000.
// if the value is more than 1,000,000, then returns 'above'
var population = $feature.POP_2007;
IIf(population < 1000000, 'below', 'above');
IsEmpty
IsEmpty( value ) -> returns: Boolean
Returns true if the provided value is null or an empty string (e.g. ''). Returns false for all other cases, including empty arrays and dictionaries.
Name | Type | Description |
value | * | The value that is compared against null or ''. This may be a value of any type. |
Returns: Boolean
Example
// Returns true
IsEmpty(null)
// Returns false
IsEmpty('hello world')
When
When( [expr1, result1, ...exprN, resultN], default ) -> returns: *
Evaluates a series of conditional expressions until one evaluates to true.
Name | Type | Description |
[expr1, result1, ...exprN, resultN] | * | A series of conditional expressions and return values if the given expression evaluates to true. This may be a value of any type. |
default | * | Returns this value if all expressions evaluate to false. This may be a value of any type. |
Returns: *
Example
Reclassify a numeric field value to a generic ranking (string)
If all expressions are false, then 'n/a' is returned
var density = $feature.densityField;
var ranking = When(density < 50, 'low', density >=50 && density < 100, 'medium', density >= 100, 'high', 'n/a');
Geometry Functions
Since Arcade expressions execute for each feature, using multiple geometry operations within the context of the labeling and visualization profiles can be expensive and severely impact the performance of the application. Also note that geometries fetched from feature services, especially polylines and polygons, are generalized according to the view's scale resolution. Be aware that using a feature's geometry (i.e. $feature) as input to any geometry function will yield results only as precise as the view scale. Therefore, results returned from geometry operations in the visualization and labeling profiles may be different at each scale level. Use these functions at your discretion within these contexts.
The following functions allow you to create and evaluate geometry objects. For convenience, you may pass a Feature object (e.g. $feature) as input to any of these methods, and the feature will internally cast as a geometry. These functions are grouped into the following categories:
Create geometries
- Geometry() - Extent() - MultiPartToSinglePart() - Multipoint() - Point() - Polyline() - Polygon() - SetGeometry()
Measurement
Topological relationship testing
- Contains() - Crosses() - Disjoint() - Equals() - Intersects() - Overlaps() - Touches() - Within()
Overlay
Proximity
If a function references units, then any of the values described in the table below may be used. Units can either be identified as a number or a string. If the value is a number, it will be based on the standard referenced here. Where appropriate, linear and areal units may be used interchangeably. For example, if calculating an area and meters is specified as the unit, then the unit will be treated as square-meters and vice versa.
Unit value | Alternate values |
*acres | acre, ac |
feet | foot, ft, square-feet, square-foot, squarefeet, squarefoot |
*hectares | hectare, ha |
kilometers | kilometer, km, square-kilometers, square-kilometer, squarekilometers, squarekilometer |
miles | mile, square-miles, square-mile, squaremiles, squaremile |
meters | meter, m, square-meters, square-meter, squaremeters, squaremeter |
yards | yard, yd, square-yards, square-yard, squareyards, squareyard |
* Indicates the unit may only be used for calculating areas.
Area
Area( geometry, unit? ) -> returns: Number
Since version 1.3
Returns the area of the input geometry in the given units. This is a planar measurement using Cartesian mathematics.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The Polygon or Extent geometry for which to calculate the planar area. | |
unit | optional Measurement unit of the return value. Use one of the string values listed in the Units reference or any of the numeric codes for area units. |
Returns: Number
Example
Returns the area of the feature in square meters
Area($feature, 'square-meters')
AreaGeodetic
AreaGeodetic( geometry, unit? ) -> returns: Number
Since version 1.3
Returns the geodetic area of the input geometry in the given units. This is more reliable measurement of area than Area() because it takes into account the Earth's curvature. Support is limited to geometries with a Web Mercator (wkid 3857) or a WGS 84 (wkid 4326) spatial reference.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The Polygon or Extent geometry for which to calculate the planar area. | |
unit | optional Measurement unit of the return value. Use one of the string values listed in the Units reference or any of the numeric codes for area units. |
Returns: Number
Example
Returns the geodetic area of the feature in square meters
AreaGeodetic($feature, 'square-meters')
Buffer
Buffer( geometry, distance, unit? ) -> returns: Polygon
Since version 1.3
Returns the planar (or Euclidean) buffer at a specified distance around the input geometry. This is a planar measurement using Cartesian mathematics.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry to buffer. | |
distance | The distance to buffer from the geometry. | |
unit | optional Measurement unit of the buffer distance. Use one of the string values listed in the Units reference or any of the numeric codes. |
Returns: Polygon
Example
Returns a polygon representing a 1/2-mile buffer around the input geometry
Buffer($feature, 0.5, 'miles')
BufferGeodetic
BufferGeodetic( geometry, distance, unit? ) -> returns: Polygon
Since version 1.3
Returns the geodetic buffer at a specified distance around the input geometry. This is a geodesic measurement, which calculates distances on an ellipsoid. Support is limited to geometries with a Web Mercator (wkid 3857) or a WGS 84 (wkid 4326) spatial reference.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry to buffer. | |
distance | The distance to buffer from the geometry. | |
unit | optional Measurement unit of the buffer distance. Use one of the string values listed in the Units reference or any of the numeric codes. |
Returns: Polygon
Example
Returns a polygon representing a 1/2-mile buffer around the input geometry
BufferGeodetic($feature, 0.5, 'miles')
Centroid
Centroid( geometry ) -> returns: Point
Since version 1.3
Returns the centroid of the input geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The polygon or feature for which to calculate the centroid. |
Returns: Point
Example
Returns the centroid of the given polygon
Centroid($feature)
Clip
Clip( geometry, envelope ) -> returns: Geometry
Since version 1.3
Calculates the clipped geometry from a target geometry by an envelope.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry to be clipped. | |
envelope | The envelope used to clip the geometry. |
Returns: Geometry
Example
Returns the area of the clipped geometry
var envelope = Extent({ ... });
Area(Clip($feature, envelope), 'square-miles');
Contains
Contains( containerGeometry, insideGeometry ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry contains another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
containerGeometry | The geometry that is tested for the 'contains' relationship to insideGeometry. Think of this geometry as the potential 'container' of the insideGeometry. In profiles that support accessing data, this can be a FeatureSet. | |
insideGeometry | The geometry that is tested for the 'within' relationship to the containerGeometry. |
Returns: Boolean | FeatureSet
Example
Returns true if the feature is contained within the given polygon
var container = Polygon({ ... });
Contains(container, $feature);
Returns the number of features that contain the given polygon
var projectArea = Polygon({ ... });
Count(Contains($layer, projectArea));
Crosses
Crosses( geometry1, geometry2 ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry crosses another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The geometry to cross. In profiles that support accessing data, this can be a FeatureSet. | |
geometry2 | The geometry being crossed. |
Returns: Boolean | FeatureSet
Example
Returns true if the feature crosses the given polygon
var geom2 = Polygon({ ... });
Crosses($feature, geom2);
Returns the number of features in the feature set that cross the given polygon
var geom2 = Polygon({ ... });
Count( Crosses($layer, geom2) );
Cut
Cut( geometry, cutter ) -> returns: Geometry[]
Since version 1.3
Splits the input Polyline or Polygon where it crosses a cutting Polyline. For Polylines, all resulting left cuts are grouped together in the first Geometry. Right cuts and coincident cuts are grouped in the second Geometry. Each undefined cut, along with any uncut parts, are output as separate Polylines.
For Polygons, all resulting left cuts are grouped in the first Polygon, all right cuts are grouped in the second Polygon, and each undefined cut, along with any left-over parts after cutting, are output as a separate Polygon. If no cuts are returned then the array will be empty. An undefined cut will only be produced if a left cut or right cut was produced and there was a part left over after cutting, or a cut is bounded to the left and right of the cutter.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry to cut. | |
cutter | The Polyline used to cut the geometry. |
Returns: Geometry[]
Example
Cuts the feature's geometry with the given polyline
var cutter = Polyline({ ... });
Cut($feature, cutter));
Difference
Difference( inputGeometry, subtractor ) -> returns: Geometry
Since version 1.3
Performs the topological difference operation for the two geometries. The resultant geometry comes from inputGeometry, not the subtractor. The dimension of subtractor has to be equal to or greater than that of inputGeometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
inputGeometry | The input geometry from which to subtract. | |
subtractor | The geometry to subtract from inputGeometry. |
Returns: Geometry
Example
Subtracts the given polygon area from the feature.
var subtractor = Polygon({ ... });
Difference($feature, subtractor);
Disjoint
Disjoint( geometry1, geometry2 ) -> returns: Boolean
Since version 1.3
Indicates if one geometry is disjoint (doesn't intersect in any way) with another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The base geometry that is tested for the 'disjoint' relationship to geometry2. | |
geometry2 | The comparison geometry that is tested for the 'disjoint' relationship to geometry1. |
Returns: Boolean
Example
Returns true if the geometries don't intersect
var geom2 = Polygon({ ... });
Disjoint($feature, geom2);
Distance
Distance( geometry1, geometry2, unit? ) -> returns: Number
Since version 1.3
Returns the planar distance between two geometries in the given units. This is a planar measurement using Cartesian mathematics.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The geometry used to measure the distance from geometry2. | |
geometry2 | The geometry used to measure the distance from geometry1. | |
unit | optional Measurement unit of the return value. Use one of the string values listed in the Units reference or any of the numeric codes. |
Returns: Number
Example
Returns the distance between two geometries in meters
var geom2 = Point({ ... });
Distance($feature, geom2, 'meters')
Equals
Equals( geometry1, geometry2 ) -> returns: Boolean
Since version 1.3
Indicates if two geometries are equal, or geographically equivalent given the spatial reference and tolerance of the data. The two input geometries don't have to be clones to be considered equal.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The first input geometry. | |
geometry2 | The second input geometry. |
Returns: Boolean
Example
Returns true if the geometries are equal
var geom2 = Point({ ... });
Equals($feature, geom2);
Extent
Extent( json ) -> returns: Extent
Constructs an Extent object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for Envelope geometries. This function may also return the extent of an input Polygon, Point, Polyline or Multipoint.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
json | The JSON or Geometry from which to construct the extent geometry object. |
Returns: Extent
Example
// Creates an Extent object
var extentJSON = {
'xmin' : -109.55, 'ymin' : 25.76, 'xmax' : -86.39, 'ymax' : 49.94,
'spatialReference' : {'wkid' : 4326}
};
Extent(extentJSON);
// Returns the Extent of the given feature
Extent($feature)
Geometry
Geometry( feature ) -> returns: Geometry
Constructs a Geometry object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for geometries. This function may also return the Geometry of an input feature.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
feature | The Feature or JSON from which to construct the geometry object. |
Returns: Geometry
Example
Returns the geometry of the feature
Geometry($feature)
Constructs a point geometry. This can be done with any geometry type.
var pointJSON = {'x' : -118.15, 'y' : 33.80, 'spatialReference' : {'wkid' : 4326}};
Geometry(pointJSON);
Intersection
Intersection( geometry1, geometry2 ) -> returns: Geometry
Since version 1.3
Constructs the set-theoretic intersection between two geometries and returns a new geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The geometry to intersect with geometry2. | |
geometry2 | The geometry to intersect with geometry1. |
Returns: Geometry
Example
Returns the area common to both polygons
var geom2 = Polygon({ ... });
Area(Intersection($feature, geom2), 'square-miles');
Intersects
Intersects( geometry1, geometry2 ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry intersects another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The geometry that is tested for the intersects relationship to the other geometry. In profiles that support accessing data, this can be a FeatureSet. | |
geometry2 | The geometry being intersected. |
Returns: Boolean | FeatureSet
Example
Returns true if the geometries intersect
var geom2 = Polygon({ ... });
Intersects($feature, geom2);
Returns the number of features that intersect the polygon
var geom2 = Polygon({ ... });
Count( Intersects($layer, geom2) );
Length
Length( geometry, unit? ) -> returns: Number
Since version 1.3
Returns the length of the input geometry in the given units. This is a planar measurement using Cartesian mathematics.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry for which to calculate the planar length. | |
unit | optional Measurement unit of the return value. Use one of the string values listed in the Units reference or any of the numeric codes. |
Returns: Number
Example
Returns the planar length of the feature in kilometers
Length($feature, 'kilometers')
LengthGeodetic
LengthGeodetic( geometry, unit? ) -> returns: Number
Since version 1.3
Returns the geodetic length of the input geometry in the given units. This is more reliable measurement of length than Length() because it takes into account the Earth's curvature. Support is limited to geometries with a Web Mercator (wkid 3857) or a WGS 84 (wkid 4326) spatial reference.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The geometry for which to calculate the geodetic length. | |
unit | optional Measurement unit of the return value. Use one of the string values listed in the Units reference or any of the numeric codes. |
Returns: Number
Example
Returns the geodetic length of the feature in kilometers
LengthGeodetic($feature, 'kilometers')
MultiPartToSinglePart
MultiPartToSinglePart( geometry ) -> returns: Geometry[]
Since version 1.3
Converts a multi-part geometry into separate geometries.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry | The multi-part geometry to break into single parts. |
Returns: Geometry[]
Example
Returns an array of single-part geometries from a multi-part geometry
var allParts = MultiPartToSinglePart($feature)
Multipoint
Multipoint( json ) -> returns: Multipoint
Constructs a Multipoint object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for multipoint geometries.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
json | The JSON from which to construct the multipoint geometry object. |
Returns: Multipoint
Example
// Creates a Multipoint object
var multipointJSON = {
'points' : [[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
'spatialReference' : {'wkid' : 4326}
};
Multipoint(multipointJSON);
Overlaps
Overlaps( geometry1, geometry2 ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry overlaps another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The base geometry that is tested for the 'overlaps' relationship with geometry2. In profiles that support accessing data, this can be a FeatureSet. | |
geometry2 | The comparison geometry that is tested for the 'overlaps' relationship with geometry1. |
Returns: Boolean | FeatureSet
Example
Returns true if the geometries overlap
var geom2 = Polygon({ ... });
Overlaps($feature, geom2);
Returns the number of features that overlap the polygon
var geom2 = Polygon({ ... });
Count( Overlaps($layer, geom2) );
Point
Point( json ) -> returns: Point
Constructs a Point object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for Point geometries.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
json | The JSON from which to construct the point geometry object. |
Returns: Point
Example
// Creates a Point object
var pointJSON = {'x' : -118.15, 'y' : 33.80, 'spatialReference' : {'wkid' : 4326}};
Point(pointJSON)
Polygon
Polygon( json ) -> returns: Polygon
Constructs a Polygon object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for Polygon geometries.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
json | The JSON from which to construct the polygon geometry object. |
Returns: Polygon
Example
// Creates a Polygon object
var polygonJSON = {
'rings' : [ [[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832], [-97.06138,32.837]],[[-97.06326,32.759],[-97.06298,32.755],[-97.06153,32.749], [-97.06326,32.759]] ],
'spatialReference' : {'wkid' : 4326}
};
Polygon(polygonJSON);
Polyline
Polyline( json ) -> returns: Polyline
Constructs a Polyline object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for Polyline geometries.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
json | The JSON from which to construct the polyline geometry object. |
Returns: Polyline
Example
// Creates a Polyline object
var polylineJSON = {
'paths' : [ [[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]], [[-97.06326,32.759],[-97.06298,32.755]] ],
'spatialReference' : {'wkid' : 4326}
};
Polyline(polylineJSON);
SetGeometry
SetGeometry( internalFeature, geometry )
Since version 1.3
Sets or replaces a geometry on a user-defined Feature. Note that features referenced as global variables are immutable; their geometries cannot be changed.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
internalFeature | A feature whose geometry will be updated. | |
geometry | The geometry to set on the input feature. |
Example
Sets a new geometry on the feature
var feature = Feature(Point( ... ), 'name', 'buffer centroid');
var buffer = BufferGeodetic(Geometry(feature), 1, 'mile');
SetGeometry(feature, buffer);
SymmetricDifference
SymmetricDifference( leftGeometry, rightGeometry ) -> returns: Geometry
Since version 1.3
Performs the Symmetric difference operation on the two geometries. The symmetric difference includes the parts of both geometries that are not common with each other.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
leftGeometry | The geometry instance to compare to rightGeometry in the XOR operation. | |
rightGeometry | The geometry instance to compare to leftGeometry in the XOR operation. |
Returns: Geometry
Example
Returns a polygon representing areas where both inputs do not overlap
var geom2 = Polygon({ ... });
SymmetricDifference($feature, geom2);
Touches
Touches( geometry1, geometry2 ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry touches another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometry1 | The geometry to test the 'touches' relationship with geometry2. In profiles that support accessing data, this can be a FeatureSet. | |
geometry2 | The geometry to test the 'touches' relationship with geometry1. |
Returns: Boolean | FeatureSet
Example
Returns true if the geometries touch
var geom2 = Polygon({ ... });
Touches($feature, geom2);
Returns the number of features in the layer that touch the geometry.
var geom = Polygon({ ... });
Count( Touches($layer, geom) );
Union
Union( geometries ) -> returns: Geometry
Since version 1.3
Constructs the set-theoretic union of the geometries in an input array, or list, and returns a single Geometry. All inputs must have the same geometry type and share the same spatial reference.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
geometries | An array, or list, of geometries to union into a single geometry. This can be any number of geometries. |
Returns: Geometry
Example
Unions geometries passed as an array
var geom2 = Polygon({ ... });
Union([ $feature, geom2 ]);
Unions geometries passed as a list
var geom2 = Polygon({ ... });
var geom3 = Polygon({ ... });
var geom4 = Polygon({ ... });
Union(Geometry($feature), geom2, geom3, geom4);
Within
Within( innerGeometry, outerGeometry ) -> returns: Boolean / FeatureSet
Since version 1.3
Indicates if one geometry is within another geometry.
Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales. Read more here.
Name | Type | Description |
innerGeometry | The base geometry that is tested for the 'within' relationship to outerGeometry. In profiles that support accessing data, this can be a FeatureSet. | |
outerGeometry | The comparison geometry that is tested for the 'contains' relationship to innerGeometry. |
Returns: Boolean | FeatureSet
Example
Returns true if the feature is within the given polygon
var outerGeom = Polygon({ ... });
Within($feature, outerGeom);
Returns the number of features in the layer within the polygon
var outerGeom = Polygon({ ... });
Count( Within($feature, outerGeom) );
Data Functions
A set of convenient functions for working with and manipulating various types of data values.
Console
Console( message [,obj,text, ...objN,textN] ) -> returns: Text
Logs a message in the messages window for debugging purposes. This function can be especially useful for inspecting variable values within a custom function at runtime. Unlike other functions and the return statement, Console() doesn't actually return a value; rather, it logs messages in a separate window for inspection purposes only. The successful use of this function has no computational impact on the evaluation of the expression.
Name | Type | Description |
message [,obj,text, ...objN,textN] | * | A list of variables, messages, or objects to output in the messages window. |
Returns: Text
Example
Prints the value of max for each iteration of the loop within the function
// The messages window will log the following:
// 'current item is: 10, but max = 10'
// 'current item is: 0, but max = 10'
// 'current item is: 84, but max = 84'
// 'current item is: 30, but max = 84'
// The expression evaluates to 84
function findMax(yourArray) {
var max = -Infinity;
for (var i in yourArray) {
max = IIf(yourArray[i] > max, yourArray[i], max);
Console('current item is: ' + i + ', but max = ' + max);
}
return max;
}
var myArray = [ 10, 0, 84, 30];
findMax(myArray);
Count
Count( values ) -> returns: Number
Returns the number of items in an array or FeatureSet, or the number of characters in a string.
Name | Type | Description |
values | Array | Text | FeatureSet | An array or string on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. |
Returns: Number
Example
Returns 6
Count([12,21,32,44,58,63])
Returns 13
Count('Graham County')
Returns the number of features in a layer
Count($layer)
Dictionary
Dictionary( name1, value1, [...nameN, compareN]? ) -> returns: Dictionary
Returns a new dictionary based on the provided arguments. The arguments are name/value pairs. e.g. dictionary('field1',val,'field2',val2,...).
Name | Type | Description |
name1 | The attribute name. | |
value1 | * | The attribute value. |
[...nameN, compareN] | * | optional Ongoing name/value pairs. |
Returns: Dictionary
Example
prints 3
var d = Dictionary('field1', 1, 'field2',2)
return d.field1 + d.field2
Distinct
Distinct( values ) -> returns: Array
Since version 1.1
Returns a set of distinct, or unique, values for a given array or list of values.
Name | Type | Description |
values | An array or list of values on which to perform the operation. |
Returns: Array
Example
Returns [1,2,3,4,5]
Distinct([1,1,2,1,1,2,2,3,4,5])
Returns ['high','medium','low',0]
Distinct('high','medium','low',0,'high','high','low')
DomainCode
DomainCode( feature, fieldName, value, subtype? ) -> returns: Text
Returns the code of an associated a domain description in a feature.
Name | Type | Description |
feature | The feature with a field that has a domain. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName | The name of the field (not the alias of the field) containing the domain. | |
value | The value to be converted back into a code. This parameter is required when a FeatureSet is passed to the featureparameter. The returned code comes from the service metadata. | |
subtype | optional The coded number for the subtype if the feature supports subtyping. If not provided, the current feature's subtype (if it has one), will be used. |
Returns: Text
Example
prints the domain description for the field referenced.
DomainCode($feature, 'Enabled', 'True')
DomainName
DomainName( feature, fieldName, code?, subtype? ) -> returns: Text
Returns the descriptive name for a domain code in a feature.
Name | Type | Description |
feature | The feature with a field that has a domain. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName | The name of the field (not the alias of the field) containing the domain. | |
code | optional The code associated with the desired descriptive name. If not provided, the field value in the feature will be returned. This parameter is required when a FeatureSet is passed to the feature parameter. The returned code comes from the service metadata. | |
subtype | optional The coded number of the subtype if the feature supports subtyping. If not provided, the feature's subtype (if it has one) will be used. |
Returns: Text
Example
prints the domain description for the referenced field
DomainName($feature, 'fieldName')
Feature
Feature( geometry, name1, value1, [... nameN, valueN]? ) -> returns: Feature
Creates a new feature. Alternatively, it can be called with object notation: Feature({geometry: {}, attributes: {...}}) or with two parameters: Feature(geometry, attributes);.
Name | Type | Description |
geometry | The geometry of the feature. | |
name1 | The first attribute's name. | |
value1 | The first attribute's value. | |
[... nameN, valueN] | * | optional Ongoing name/value pairs for each attribute in the feature. |
Returns: Feature
Example
Feature(pointGeometry, 'city_name', 'Spokane', 'population', 210721)
Create a feature from another feature.
var dict = { hello:10 }
var p = point({x:10, y:20, spatialReference:{wkid:102100}})
var ftr1 = Feature(p,dict)
var ftr2 = Feature(ftr1)
Create a feature from a JSON string.
var JSONString = "{'geometry':{'x':10,'y':20,'spatialReference':{'wkid':102100}},'attributes':{'hello':10}}"
var feature = Feature(JSONString)
FeatureSet
FeatureSet( definition ) -> returns: FeatureSet
Since version 1.5
Profiles: Attribute Rules | Popup | Field Calculate
Creates a new FeatureSet from JSON according to the ArcGIS REST spec. See the snippet below for an example of this.
Name | Type | Description |
definition | The JSON describing a set of features. The JSON must be contained in a string. |
Returns: FeatureSet
Example
Create a FeatureSet from JSON.
// JSON representation of the feature used in the snippet below
// {
// 'fields': [{
// 'alias': 'RANK',
// 'name': 'RANK',
// 'type': 'esriFieldTypeInteger'
// }, {
// 'alias': 'ELEV_m',
// 'name': 'ELEV_m',
// 'type': 'esriFieldTypeInteger'
// }],
// 'spatialReference': { 'wkid': 4326 },
// 'geometryType': 'esriGeometryPoint',
// 'features': [{
// 'geometry': {
// 'spatialReference': { 'wkid': 4326 },
// 'x': -151.0063,
// 'y': 63.069
// },
// 'attributes': {
// 'RANK': 1,
// 'ELEV_m': 6168
// }
// }]
// };
// The Dictionary representation of the FeatureSet must be a stringified object
var features = FeatureSet('{"fields":[{"alias":"RANK","name":"RANK","type":"esriFieldTypeInteger"},{"alias":"ELEV_m","name":"ELEV_m","type":"esriFieldTypeInteger"}],"spatialReference":{"wkid":4326},"geometryType":"esriGeometryPoint","features":[{"geometry":{"spatialReference":{"wkid":4326},"x":-151.0063,"y":63.069},"attributes":{"RANK":1,"ELEV_m":6168}}]}')
FeatureSetById
FeatureSetById( map, id, fieldList?, includeGeometry? ) -> returns: FeatureSet
Since version 1.5
Profiles: Attribute Rules | Popup | Field Calculate
Creates a FeatureSet from a Feature Layer based on its layer ID within a map or feature service. Limiting the number of fields in the request and excluding the geometry can improve the performance of the script.
Name | Type | Description |
map | The map or feature service containing one or more layers from which to create a FeatureSet. Typically, this value is the $map or $datastore global. | |
id | The ID of the layer within the given map. | |
fieldList | optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script. | |
includeGeometry | optional Indicates whether to include the geometry in the features. By default, this is true. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions. |
Returns: FeatureSet
Example
Returns the number of features in the layer with the id DemoLayerWM_1117 in the given map.
var features = FeatureSetById($map,'DemoLayerWM_1117', ['*'], true);
Count( features );
FeatureSetByName
FeatureSetByName( map, title, fieldList?, includeGeometry? ) -> returns: FeatureSet
Since version 1.5
Profiles: Attribute Rules | Popup | Field Calculate
Creates a FeatureSet from a Feature Layer based on its name within a map or feature service. Keep in mind this name is not necessarily unique. It is therefore more appropriate to create a FeatureSet using FeatureSetById(). Limiting the number of fields in the feature set and excluding the geometry can improve the performance of the script.
Name | Type | Description |
map | The map or feature service containing one or more layers from which to create a FeatureSet. Typically, this value is the $map or $datastore global. | |
title | The title of the layer within the given map. | |
fieldList | optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script. | |
includeGeometry | optional Indicates whether to include the geometry in the features. By default, this is true. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions. |
Returns: FeatureSet
Example
Returns the number of features in the layer with the title 'Bike routes' in the given map.
var features = FeatureSetByName($map,'Bike routes', ['*'], true);
Count( features );
FeatureSetByPortalItem
FeatureSetByPortalItem( itemId, layerId, fieldList?, includeGeometry? ) -> returns: FeatureSet
Since version 1.5
Profiles: Field Calculate
Creates a FeatureSet from a Feature Layer in a portal item. Limiting the number of fields in the feature set and excluding the geometry can improve the performance of the script.
Name | Type | Description |
itemId | The GUID of the portal item referencing a feature layer or feature service. | |
layerId | The ID of the layer in the feature service. | |
fieldList | optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script. | |
includeGeometry | optional Indicates whether to include the geometry in the features. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions. |
Returns: FeatureSet
Example
Returns the number of features in the layer with the title 'Bike routes' in the given map.
var features = FeatureSetByPortalItem('7b1fb95ab77f40bf8aa09c8b59045449', 0, ['Name', 'Count'], false);
Count( features );
Filter
Filter( featureSet, filter ) -> returns: FeatureSet
Since version 1.5
Profiles: Attribute Rules | Popup | Field Calculate
Filters a FeatureSet based on a SQL92 expression.
Name | Type | Description |
featureSet | The FeatureSet, or layer, to filter. | |
filter | The SQL92 expression used to filter features in the layer. This expression can substitute an Arcade variable using the @ character. See the snippet below for an example. |
Returns: FeatureSet
Example
Filter features using a SQL92 expression
// Returns all features with a Population greater than 10,000
var result = Filter($layer, 'POPULATION > 10000');
Filter features using a SQL92 expression with a variable substitute
// Returns all features with a Population greater than the dataset average
var averageValue = Average($layer, 'POPULATION')
var result = Filter($layer, 'POPULATION > @averageValue');
First
First( items ) -> returns: *
Returns the first element in an array or FeatureSet.
Name | Type | Description |
items | The array from which to return the first feature. In profiles that support accessing data, this can be a FeatureSet. |
Returns: *
Example
prints 'orange'
First(['orange', 'purple', 'gray'])
returns the area of the first feature in the layer.
Area( First($layer) )
Guid
Guid( format? ) -> returns: Text
Since version 1.3
Returns a random GUID as a string.
Name | Type | Description |
format | optional An named format for the GUID. The default value is digits-hyphen-braces. |
Returns: Text
Example
Returns a value similar to {db894515-ed21-4df1-af67-36232256f59a}
Guid()
Returns a value similar to d00cf4dffb184caeb8ed105b2228c247
Guid('digits')
HasKey
HasKey( feature, key ) -> returns: Boolean
Indicates whether a dictionary or feature has the input key.
Name | Type | Description |
feature | The dictionary or feature to check for a key or field name. | |
key | The key or field name to check. |
Returns: Boolean
Example
prints true
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
HasKey(d, 'Cobourg');
IndexOf
IndexOf( inputArray, item ) -> returns: Number
Returns the zero-based index location of the input item in an array. If item does not exist, then -1 is returned.
Name | Type | Description |
inputArray | The array to search. | |
item | * | The item to locate in the array. |
Returns: Number
Example
prints 2
var array = [1,2,3,4];
return indexof(array, 3);
IsNan
IsNan( value ) -> returns: Boolean
Since version 1.5
Indicates whether the input value is not a number (NaN). A number is considered NaN in one of the following scenarios:
- 0/0
- Infinity / Infinity
- Infinity * 0
- Any operation in which NaN is an operand
- Casting a non-numeric string or undefined to a number
Name | Type | Description |
value | * | The value to check if it is NaN. |
Returns: Boolean
Example
// Returns true
IsNan(Infinity / Infinity)
// Returns false
IsNan('4')
NextSequenceValue
NextSequenceValue( inputSequenceName ) -> returns: Number
Since version 1.4
Profiles: Attribute Rules
Returns the next sequence value from the database sequence specified. If inputSequenceName does not exist, the expression will error. This function is only valid in the calculation profile when used in attribute rules.
Name | Type | Description |
inputSequenceName | The name of the sequence. This must already be configured in the database. |
Returns: Number
Example
Returns a number with the next sequence value
NextSequenceValue('PipeIDSeq')
Number
Number( value, pattern? ) -> returns: Number
Parses the input value to a number.
Name | Type | Description | ||||||||
value | * | The value to convert to a number. | ||||||||
pattern | optional The format pattern string used to parse numbers formatted in a localized context from a string value to a number. The table below describes the characters that may be used in the pattern.
|
Returns: Number
Example
Parses a number using a grouping separator appropriate for the local in which the expression is executed
returns 1365
Number('1,365', ',###')
Remove strings from number.
prints 10
Number('abc10def', 'abc##def')
Specify minimum digits past 0 as two and maximum digits past 0 as 4.
prints 10.456
Number('10.456','00.00##')
Specify minimum digits past 0 as two and maximum digits past 0 as 4. The left and right side of the function must match or NaN is returned.
prints NaN
Number('10.4','00.00##')
Indicate the size of the repeated group and the final group size of the input value.
prints 1212456
Number('12,12,456', ',##,###')
If there is a negative subpattern, it serves only to specify the negative prefix and suffix.
prints -1223345
Number('-12,23,345', ',##,###;-,##,###')
Divide by 100. Maximum of three decimal places can be input.
prints 0.9999
Number('99.99%', '#.##%')
OrderBy
OrderBy( featureSet, expression ) -> returns: FeatureSet
Since version 1.5
Profiles: Attribute Rules | Popup | Field Calculate
Orders a FeatureSet by using a SQL92 OrderBy clause.
Name | Type | Description |
featureSet | The FeatureSet, or layer, to order. | |
expression | The SQL92 expression used to order features in the layer. |
Returns: FeatureSet
Example
Order features by population where features with the highest population are listed first
OrderBy($layer, 'POPULATION DESC')
Order features by rank in ascending order
OrderBy($layer, 'Rank ASC')
Reverse
Reverse( inputArray ) -> returns: Array
Reverses the contents of the array in place.
Name | Type | Description |
inputArray | The array to be reversed. |
Returns: Array
Example
returns ['grey', 'purple', 'orange']
Reverse(['orange', 'purple', 'grey'])
Sort
Sort( inputArray, comparator? ) -> returns: Array
Sorts an array by ASCII value. If all the items in the array are the same type, an appropriate sort function will be used. If they are different types, the items will be converted to strings. If the array contains objects, and no user defined function is provided, no sort will happen.
Name | Type | Description |
inputArray | The array to sort. | |
comparator | optional The name of a user defined function to be used for the sort. |
Returns: Array
Example
returns ['$', 1, 'A', 'a']
Sort([1, 'a', '$', 'A'])
Sort using a user defined function
returns '[{ 'AGE': 24, 'NAME': 'Emma' }, { 'AGE': 25, 'NAME': 'Sam' }, { 'AGE': 27, 'NAME': 'Bob' } ]'
var peopleArray = [{ 'NAME': 'Sam', 'AGE': 25 }, {'NAME': 'Bob', 'AGE': 27 },{ 'NAME': 'Emma', 'AGE': 24 }];
function compareAge(a,b){
if (a['AGE']<b['AGE'])
return -1;
if (a['AGE']>b['AGE'])
return 1;
return 0;
}
return Sort(peopleArray, compareAge);
Text
Text( value, format? ) -> returns: Text
Converts its argument into a string and optionally formats it. Returns null if it fails.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||
value | * | A value to be converted to a string (e.g. date, number or other type). | ||||||||||||||||||||||||||||||||||||||||||||||
format | optional Formatting string for dates or numbers. See the list of possible values below.
|
Returns: Text
Example
Pad the number to the left of the decimal
prints '0123'
Text(123, '0000')
Restrict the number to the left of the decimal
prints '23'
Text(123, '00')
Group the number by thousands
prints '1,234'
Text(1234, '#,###')
Round the number to two decimal places
prints '12,345,678.12'
Text(12345678.123, '#,###.00')
Format number as currency
prints '$1,234.55'
Text(1234.55, '$#,###.00')
Round the number to two decimal places
prints '1.24'
Text(1.236, '#.00')
Maintain significant digits and group by thousands
prints '1,234.568'
Text(1234.5678, '#,##0.00#')
Format the number and format positive/negative - if there is a negative subpattern, it serves only to specify the negative prefix and suffix
prints 'Basement 2'
Text(-2, 'Floor #;Basement #')
prints 'Floor 2'
Text(2, 'Floor #;Basement #')
Multiply by 100 and format as percentage
prints '30%'
Text(0.3, '#%')
Format date and time
prints the date at the moment. eg 'Tuesday, October 25, 2016 @ 08:43:11'
Text(Now(), 'dddd, MMMM D, yyyy @ h:m:s')
Top
Top( items, numElements ) -> returns: Array / FeatureSet
Since version 1.3
Truncates the input array or FeatureSet and returns the first given number of elements.
Name | Type | Description |
items | The array to truncate. In profiles that support accessing data, this can be a FeatureSet. | |
numElements | The number of elements to return from the beginning of the array or FeatureSet. |
Returns: Array | FeatureSet
Example
returns [ 43,32,19 ]
Top([ 43,32,19,0,3,55 ], 3)
Returns the top 5 features with the highest population
Top( OrderBy($layer, 'POPULATION DESC'), 5 )
TypeOf
TypeOf( value ) -> returns: Text
Returns the type of the input value. Will return one of the following types: Array, Date, Text, Boolean, Number, Dictionary, Feature, Point, Polygon, Polyline, Multipoint, Extent, Function, Unrecognized Type.
Name | Type | Description |
value | * | The input value, variable, or feature attribute. |
Returns: Text
Example
prints 'Boolean'
TypeOf(true)
prints 'Date'
TypeOf(Now())
Text Functions
Functions for formatting text values. These are commonly used in the labeling and popup profiles.
Concatenate
Concatenate( values, separator?, format? ) -> returns: Text
Concatenates values together and returns a text value.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||
values | An array of text values to concatenate. | |||||||||||||||||||||||||||||||||||||||||||||||
separator | 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 | 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? ) -> returns: Number
Finds a string of characters within a text value. Wildcards are NOT supported.
Name | Type | Description |
searchText | The character string to search for. | |
text | The text to search. | |
startpos | 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 ) -> returns: Text
Returns the specified number of characters from the beginning of a text value.
Name | Type | Description |
value | The text from which to get characters. | |
charCount | 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 ) -> returns: Text
Makes a text value lower case.
Name | Type | Description |
value | The text to be made lowercase. |
Returns: Text
Example
prints 'hello'
Lower('HELLO')
Mid
Mid( value, startpos, charCount ) -> returns: Text
Gets a number of characters from the middle of a text value.
Name | Type | Description |
value | The text from which to get characters. | |
startpos | The starting position from which to get the text. 0 is the first position. | |
charCount | The number of characters to extract. |
Returns: Text
Example
prints 'quick'
Mid('the quick brown fox', 4, 5)
Proper
Proper( value, applyTo? ) -> returns: 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 | The text to convert to title case. | |
applyTo | 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? ) -> returns: Text
Replaces a string within a text value or an element within an array. Defaults to replacing all occurrences.
Name | Type | Description |
value | The value in which to make replacements. | |
searchText | The text to search for. | |
replacementText | The replacement text. | |
allOccurrences | 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 ) -> returns: Text
Returns the specified number of characters from the end of a text value.
Name | Type | Description |
value | The text from which to get characters. | |
charCount | 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? ) -> returns: Text[]
Splits a text value into an array.
Name | Type | Description |
value | The text value to be split. | |
separator | The separator used to split the text. | |
limit | optional An integer that specifies the number of splits. | |
removeEmpty | 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 ) -> returns: Text
Removes spaces from the beginning or end of an input text value.
Name | Type | Description |
value | The text to be trimmed. |
Returns: Text
Example
prints 'hello world'
Trim(' hello world')
Upper
Upper( value ) -> returns: Text
Makes text upper case.
Name | Type | Description |
value | The text value to be made uppercase. |
Returns: Text
Example
prints 'HELLO'
Upper('Hello')
Mathematical Functions
Functions for performing mathematical operations.
Abs
Abs( value ) -> returns: Number
Returns the absolute value of a number. If the input is null
, then it returns 0.
Name | Type | Description |
value | A number on which to perform the operation. |
Returns: Number
Example
prints 3
Abs(
-3)
Acos
Acos( value ) -> returns: 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 | A number between -1 and 1 on which to perform the operation. |
Returns: Number
Example
prints 1.266104
Acos(
0.3)
Asin
Asin( value ) -> returns: 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 | A number between -1 and 1 on which to perform the operation. |
Returns: Number
Example
prints 0.304693
Asin(
0.3)
Atan
Atan( value ) -> returns: Number
Returns the arctangent of the input value in radians, in the range of -PI/2 and PI/2.
Name | Type | Description |
value | A number on which to perform the operation. |
Returns: Number
Example
prints 0.785398
Atan(
1)
Atan2
Atan2( y, x ) -> returns: 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 | A number representing the y-coordinate. | |
x | A number representing the x-coordinate. |
Returns: Number
Example
prints -2.356194
Atan2(
-1,
-1)
Average
Average( values, fieldName? ) -> returns: 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 | A list or array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
Returns: Number
Example
prints 5
vararray = [
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? ) -> returns: Number
Returns the input value rounded upwards to the given number of decimal places.
Name | Type | Description |
value | The number to round upward. | |
numPlaces |
|
Returns: Number
Example
prints 2135.1
Ceil(
2135.0905,
2)
Constrain
Constrain( value, min, max ) -> returns: 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 | The value to constrain to the given | |
min | The lower bound by which to constrain the input | |
max | The upper bound by which to constrain the input |
Returns: Number
Example
returns 5
Constrain(
5,
0,
10)
returns 0
Constrain(
-3,
0,
10)
returns 10
Constrain(
553,
0,
10)
Cos
Cos( value ) -> returns: Number
Returns the cosine of the input value in radians.
Name | Type | Description |
value | A number in radians on which to perform the operation. |
Returns: Number
Example
prints 0.540302
Cos(
1)
Exp
Exp( x ) -> returns: 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 | The power, or number of times to multiply |
Returns: Number
Example
prints 7.389056
Exp(
2)
Floor
Floor( value, numPlaces? ) -> returns: Number
Returns the input value rounded downward to the given number of decimal places.
Name | Type | Description |
value | A number to round downward. | |
numPlaces |
|
Returns: Number
Example
prints 2316.25
Floor(
2316.2562,
2)
Log
Log( x ) -> returns: Number
Returns the natural logarithm (base e) of x.
Name | Type | Description |
x | A number on which to perform the operation. |
Returns: Number
Example
prints 2.302585
Log(
10)
Max
Max( values, fieldName? ) -> returns: 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 | An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
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? ) -> returns: 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 | A list or array of numbers from which to calculate the mean. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
Returns: Number
Example
Use a single array as input
returns 5
varvals = [
1,
2,
3,
4,
5,
6,
7,
8,
9];
Mean(vals);
Use comma separated values with array element
returns 5
vararray = [
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? ) -> returns: 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 | An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
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 ) -> returns: Number
Returns the value of x to the power of y.
Name | Type | Description |
x | The base value. | |
y | The exponent. This indicates the number of times to multiply |
Returns: Number
Example
prints 9
Pow(
3,
2)
Random
Random( ) -> returns: Number
Returns a random number between 0 and 1.
Name | Type | Description |
Returns: Number
Example
Random()
Round
Round( value, numPlaces? ) -> returns: Number
Returns the input value, rounded to the given number of decimal places.
Name | Type | Description |
value | A number to round. | |
numPlaces |
|
Returns: Number
Example
prints 2316.26
Round(
2316.2562,
2)
Sin
Sin( value ) -> returns: Number
Returns the sine of the input value.
Name | Type | Description |
value | A number in radians on which to perform the operation. |
Returns: Number
Example
prints 0.841741
Sin(
1)
Sqrt
Sqrt( value ) -> returns: Number
Returns the square root of a number.
Name | Type | Description |
value | A number on which to calculate the square root. |
Returns: Number
Example
prints 3
Sqrt(
9)
Stdev
Stdev( values, fieldName? ) -> returns: 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 | An array or list of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
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? ) -> returns: 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 | An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
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 ) -> returns: Number
Returns the tangent of an angle in radians.
Name | Type | Description |
value | A number on which to calculate the tangent. |
Returns: Number
Example
prints 0.57389
Tan(
0.521)
Variance
Variance( values, fieldName? ) -> returns: 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 | An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet. | |
fieldName |
|
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')