Arcade expressions

Arcade is a portable, lightweight, and secure expression language written for use in the ArcGIS platform, and can also be used in some GeoAnalytics for Microsoft Fabric tools. Like other expression languages, it can perform mathematical calculations, manipulate text, and evaluate logical statements. It also supports multi-statement expressions, variables, and flow control statements. Some GeoAnalytics for Microsoft Fabric tools can use Arcade expressions in analysis. In addition to performing mathematical equations, manipulating text and evaluating logical statements, Arcade can leverage the geometry and record values from your input DataFrame. These advanced capabilities enable you to build custom expressions to explore your data. Tool usage and example expressions are outlined below.

Expression formatting

Using Arcade, field names are formatted as $feature["field name"] or $feature.fieldname. The first option, $feature["field name"], is required when a field name includes a space. All examples below use this option. All tools use the $feature["field name"] format except Spatiotemporal Join. For Spatiotemporal Join, use $target["field name"] and $join["field name"] to specify which input DataFrame will be used.

Learn more about Arcade expressions

Arcade expressions and tools

Arcade expressions are used in GeoAnalytics for Microsoft Fabric by the following analysis tools:

  • Reconstruct Tracks can use Arcade in the following ways:

    • Buffer expressions—Use buffer expressions to perform a mathematical calculation to set the buffer size. You can perform simple and advanced calculations that can be applied to all records. Buffer calculations are applied to each record.

    • Split expressions—Use split expressions to specify a condition to split tracks. When records meet the criteria, tracks are split and summarized into different tracks. You can apply simple conditions as well as track-aware conditions. For example, you can split tracks when the speed of the current point is less than two meters per second (TrackCurrentSpeed() < 2).

  • Spatiotemporal Join—Use join expressions to specify a condition to select records to include in the join. You can perform simple join conditions (such as $target["field a"] > $join["field c"]) as well as advanced conditions. The conditions are tested on each record to determine which records are analyzed. Spatiotemporal Join does not support track-aware expressions.

  • Calculate Field—Perform simple and advanced calculations that are applied to all records. This calculation is applied to each record. Calculate field supports track-aware expressions when a track field is specified.

  • Detect Incidents—Determine start and end conditions for incidents. Use start and end expressions to detect incidents. A Detect Incidents condition must always result in true or false. Use a condition to determine whether a record is included in an incident. You can use simple conditions as well as track-aware conditions. The evaluation of conditions is applied to each record.

Example calculations

The following sections outline example calculations using various types of expressions, including mathematical, text, date, track-aware, and more. For more examples, see the Arcade Function Index.

Geometry functions

Arcade expressions can create and evaluate geometry objects. Note, when you are analyzing multiple geometries they must use the same spatial reference. For example, use Bearing() to calculate the direction your geometries are moving in. The following example uses two records, pointA and pointB, and returns a numeric value indicating the bearing between them.

Use dark colors for code blocksCopy
1
2
3
pointA = Point({ "x":66.23, "y":44.18, "spatialReference": { "wkid":4267 } });
pointB = Point({ "x":62.12, "y":43.22, "spatialReference": { "wkid":4267 } });
Bearing(pointA,pointB)

Returns 256.8528

Learn more about geometry functions available in Arcade

Mathematical operation and functions

Expressions can mathematically process numbers. For example, use Abs() to get the positive values for column values representing change in temperature. The following example uses a column named Temp Change containing a value of -9:

Abs($feature["Temp Change"])

Returns 9

Learn more about mathematical operations and functions available in Arcade

Text functions

Arcade expressions can process text. For example, use Find() and Lower() to search a string for a given value. In the following example, "North" occurs at position 3 of the input string "146NorthStreet":

Find(("north"), Lower("146NorthStreet"))

Returns 3

Learn more about text functions available in Arcade

Date functions

Arcade expressions can process dates. In Arcade, month values range from 0 (January) to 11 (December), days from the 1st to the 31st, hours from 0 (12:00 a.m.) to 23 (11:00 p.m.), minutes and seconds from 0 to 59, and milliseconds from 0 to 999.

For example, use Date() to convert date values stored in milliseconds from epoch to a formatted date. In the following example the column My Date contains a value of 1476987783555.

Date($features["My Date"])

Returns 20 Oct 2016 11:23:03 AM

Learn more about date functions available in Arcade

Conditional operators

Conditional statements can use the following simple mathematical operators:

OperatorExplanationExampleResults
a > ba is greater than b10 > 2True
a < ba is less than b10 < 2False
a >= ba is greater than or equal to babs(-10) >= 10True
a <= ba is less than or equal to babs(-10) <= 10True
a != ba is not equal to babs(-3) != -3True
a == ba is equal to babs(-5) == 5True
<condition1> ║ <condition2>Condition 1 or condition 2 is met.(abs(-5) == 5) ║ (10 < 2)True
<condition1> && <condition2>Condition 1 and condition 2 are met.(abs(-5) == 5) && (10 < 2)False

Logical functions

In addition to simple mathematical expressions, you can use advanced Arcade functions to evaluate conditions or calculate values.

For example, use Iif() to return specified values when the given conditions are met. Using the following example, a value of 1 is returned if cost1 is greater than cost2. If not, a value of 0 is returned.

Iif($feature["cost1"] > $feature["cost2"],1, 0)

Learn more about logical functions available in Arcade

Track-aware functions

Detect Incidents, Calculate Field, and Reconstruct Tracks can use track-aware equations in Arcade. In Calculate Field, track equations can be used when the input DataFrame has a single timestamp (instant) and a track field. Use the following expressions to calculate track-aware equations:

FunctionExplanationExampleResult
TrackStartTime()Calculate the start time of a track in milliseconds from epoch.Using a track that starts on January 2, 2017.1483315200000
TrackDuration()Calculate the duration of a track in milliseconds from the start until the current time step.Using a track that starts on January 2, 2017, and the current time is January 4, 2017.172800000
TrackCurrentTime()Calculate the current time in a track.Using a feature that occurs on January 3, 2017, at 9:00 a.m.1483434000000
TrackIndexReturn the time index of the record being calculated.Calculating this value on the first record in a track.0
TrackFieldWindow(<fieldName>, <startIndex>, <endIndex>)

Return an array of values in the given field for the specified time index. The window function allows you to go forward and backward in time. The expression is evaluated at each record in the track.

  • The current record is at index 0.
  • Positive values represent records that occur in the future, after the current value. For example, position 1 is the next value in the array.
  • Negative numbers represent records that occurred in the past, before the previous record. For example, -1 is the previous value in the array.

MyField has sequentially ordered values of [10, 20, 30, 40, 50]. The expression is evaluated at each record in the track. Results are returned inclusive of the start record and exclusive of the end record.

Example 1: TrackFieldWindow("MyField,-1,2)

Example 2: TrackFieldWindow("MyField,-2,0)[0]

Example 3: TrackFieldWindow("MyField,0,3)[2]

Example 1: When evaluated at each record, the table shows the following results:

Evaluated recordResult
10[10,20]
20[10, 20, 30]
30[20,30,40]
40[30,40,50]
50[40, 50]

Example 2: When evaluated at index 2 (value is 30), it returns 10.

Example 3: When evaluated at index 2 (value is 30), it returns 50.

TrackGeometryWindow(<startIndex>, <endIndex>)

Return an array of values representing geometry for the specified time index. The window function allows you to go forward and backward in time. The expression is evaluated at each record in the track.

  • The current record is at index 0.
  • Positive values represent records that occur in the future, after the current value. For example, position 1 is the next value in the array.
  • Negative numbers represent records that occurred in the past, before the previous record. For example, -1 is the previous value in the array.

MyField has sequentially ordered values of [10, 20, 30, 40, 50]. The expression is evaluated at each record in the track. Results are returned inclusive of the start record, and exclusive of the end record. The input geometries are:

[{x: 1, y: 1}, {x: 2, y: 2}, {x: null, y: null}, {x: 4, y: 4}, {x: 5, y: 5}]

Example 1: TrackGeometryWindow(-1,2)

Example 2: TrackGeometryWindow(0,1)[0] on a polyline DataFrame

Example 3: TrackGeometryWindow(0,1)[0] on a polygon DataFrame

Example 4: Find the X value of the previous point TrackGeometryWindow(-1,0)[0]["x"]

Example 1: When evaluated at each record, the following table shows the results:

Evaluated recordResult
10

[{x: 1, y: 1},{x: 2, y: 2}]

20

[{x: 1, y: 1},{x: 2, y: 2} ,{x: null, y: null}]

30

[{x: 2, y: 2} ,{x: null, y: null},{x: 4, y: 4}]

40

[{x: null, y: null},{x: 4, y: 4}, {x: 5, y: 5}]

50

[{x: 4, y: 4}, {x: 5, y: 5}]

TrackWindow(<value1>, <value2>)

Return an array of values representing geometry and all attributes for the specified time index. The window function allows you to go forward and backward in time.

  • The current record is at index 0.
  • Positive values represent records that occur in the future, after the current value. For example, position 1 is the next value in the array.
  • Negative numbers represent records that occurred in the past, before the previous record. For example, -1 is the previous value in the array.

MyField has sequentially ordered values of [10, 20, 30, 40, 50], in addition to the objectID, globalID, and instant_datetime fields. The input geometries are:

[{x: 1, y: 1},{x: 2, y: 2} ,{x: null, y: null},{x: 4, y: 4}, {x: 5, y: 5}]

Example 1: TrackWindow(-1,0)[0]

Example 2: geometry(TrackWindow(-1,0)[0]["x"]

Example 1: When evaluated at each record, the table shows the following results:

Evaluated recordResult
10
20

[{"geometry": {x: 1, y: 1}},{"attributes": {"MyField" : 10, "trackName":"ExampleTrack1"}}]

30

[{"geometry": {x: 2, y: 2}},{"attributes": {"MyField" : 20, "trackName":"ExampleTrack1"}}]

40

[{"geometry": {x: null, y: null}},{"attributes": {"MyField" : 30, "trackName":"ExampleTrack1"}}]

50

[{"geometry": {x: 4, y: 4}},{"attributes": {"MyField" : 40, "trackName":"ExampleTrack1"}}]

Example 2: Evaluated at index 2 (value is 30): 2

Use the following track expressions to calculate distance, speed, and acceleration on tracks. These are similar to calculations used in the Calculate Motion Statistics tool.

All distance calculations are calculated in meters, speed in meters per second, and acceleration in meters per second squared. Distances are measured using geodesic distances.

FunctionExplanation
TrackCurrentDistance()The sum of the distances travelled between observations from the first to current observation.
TrackDistanceAt(value)The sum of the distances travelled between observations from the first to the current observation plus the given value.
TrackDistanceWindow(value1, value2)The distances between the first value (inclusive) to the last value (exclusive) in a window about the current observation (0).
TrackCurrentSpeed()The speed between the previous observation and the current observation.
TrackSpeedAt(value1)The speed at the observation relative to the current observation. For example, at value 2, it's the speed at the observation two observations after the current.
TrackSpeedWindow(value1, value2)The speed values between the first value (inclusive) to the last value (exclusive) in a window around the current observation (0).
TrackCurrentAcceleration()The acceleration between the previous observation and the current observation.
TrackAccelerationAt(value1)The acceleration at the observation relative to the current observation.
TrackAccelerationWindow(value1, value2)The acceleration values between the first value (inclusive) to the last value (exclusive) in a window around the current observation (0).

The example calculations for distance, speed, and acceleration in the table below use examples from the following image.

Track example image with six points
Example of a track with six points.
FunctionExample result
TrackCurrentDistance()
Point IDResult (meters)
P10
P260
P380 + 60 = 140
P430 + 80 + 60 = 170
P535 + 30 + 80 + 60 = 205
P625 + 35 + 30 + 80 + 60 = 230
TrackDistanceAt(2)
Point IDResult (meters)
P10 + 80 + 60 = 140
P230 + 80 + 60 = 170
P335 + 30 + 80 + 60 = 205
P425 + 35 + 30 + 80 + 60 = 230
P5null
P6null
TrackDistanceWindow(-1, 2)
Point IDResult (meters)
P1[0,60]
P2[0, 60, 140]
P3[60, 140, 170]
P4[140, 170, 205]
P5[170, 205, 230]
P6[205, 230]
TrackCurrentSpeed()
Point IDResult (meters/second)
P10
P2

60/60

1

P3

80/60

1.33

P4

30/60

.5

P5

35/60

0.5833

P6

25/60

0.4167

TrackSpeedAt(2)
Point IDResult (meters/second)
P1

80/60

1.33

P2

30/60

.5

P3

35/60

0.5833

P4

25/60

0.4167

P5null
P6null
TrackSpeedWindow(-1, 2)
Point IDResult (meters/second)
P1[0, 1]
P2[0, 1, 1.3]
P3[1, 1.3, 0.5]
P4[1.3, 0.5, 0.583]
P5[0.5, 0.583, -0.4167]
P6[0.583, -0.4167]
TrackCurrentAcceleration()
Point IDResult (meters/second2)
P10
P20.0167
P30.0056
P4-0.0014
P50.0014
P6-0.0028
TrackAccelerationAt(2)
Point IDResult (meters/second2)
P10.0056
P2-0.0014
P30.0014
P4-0.0028
P5null
P6null
TrackAccelerationWindow(-1, 2)
Point IDResult (meters/second2)
P1[0, 0.0167]
P2[0, 0.0167, 0.0056]
P3[0.0167, 0.0056 , -0.0014]
P4[ 0.0056 , -0.0014, 0.0014]
P5[-0.0014, 0.0014, -0.0028]
P6[0.0014, -0.0028]

What's next?

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