Skip to main content

Computation helpers

Discover the helper functions and what they do

To make some aspects of data processing easier for the data types used in Alloy, we've defined various helper functions for you to use in Workflow Computation scripts.

General functions

FunctionDescription
Local(DateTime utc)Convert UTC time to LocalTime
NowGet the current UTC time
Date(DateTime dateTime)Get the Date from a UTC DateTime
Seasonal(DateTime dateTime)Get the Seasonal Date from a UTC DateTime
Time(DateTime dateTime)Get the Time from a UTC DateTime
AlloyId(string idString)Convert a string to an AlloyId
GloballyUniqueCode(string guc)Convert a string to a GUC, e.g. designInterfaces_defects
List(T[] items)Convert an array of items to a List
Set(T[] items)Convert a Set (unordered, no duplicates) of items to a List
Aqs(object data)Convert an object to a AQS node
Json(object data)Convert an object to Json
Variables.<variable name>.<SingleValue or AllValues>.<key-value pairs>.<Value>.<SingleValue or AllValues>Access to the values held in variables
GeometryCollection(IGeometryObject[] geometryObjects)Create a Geometry Collection from an array of geometry objects
LineString(IPosition[] positions)Create a LineString geometry object from an array of positions
Position(double latitude, double longitude, double? altitude = null)Create a Position from longitude, latitude, altitude (optional)
MultiLineString(LineString[] lineStrings)Create a MultiLineString geometry object from a set of LineString objects
MultiPoint(Point[] points)Create a MultiPoint geometry object from an array of Point objects
Point(Position position)Create a Point geometry object from a position
Polygon(LineString[] lineStrings)Create a Polygon geometry object from an array of LineString objects
MultiPolygon(Polygon[] polygons)Create a MultiPolygon geometry object from an array of Polygon objects

DateTime functions

FunctionDescription
Floor(DateTime value, Resolution resolution)Get the Floor of a DateTime value to the specified resolution
(Sec, Min, Hr, Day, Week, Month, Year)
Ceiling(DateTime value, Resolution resolution)Get the Ceiling of a DateTime value to the specified resolution
(Sec, Min, Hr, Day, Week, Month, Year)
Round(DateTime value, Resolution resolution)Round the DateTime value to the nearest resolution
(Sec, Min, Hr, Day, Week, Month, Year)

GeometryMath functions

FunctionDescription
Length(IGeometryObject[] values)Compute the Length of an array of geometry objects
Area(IGeometryObject[] values)Compute the Area of an array of geometry objects
Centroid(IGeometryObject[] values)Compute the Centroid of an array of geometry objects
ConvexHull(IGeometryObject[] values)Compute the Convex Hull of an array of geometry objects
Buffer(double distance, IGeometryObject[] values)Compute the new Buffered geometry with distance from an array of geometry objects
Clip(IGeometryObject clipBounds, IGeometryObject[] values)Clip a geometry array by the specified bounds
BoundingBox(IGeometryObject[] values)Compute the Bounding Box of an array of geometry objects

The Variables dictionary

As with standard C#, you can use the Variables dictionary to access the values of variables. You can retrieve single values or value arrays.

Additionally, value arrays can be aggregated using LINQ functions.

For example:

  • This script aggregates the average of Heights returned by the userHeight1 variable:
    var averageHeight = Variables.userHeight1.AllValues.Average(x => x.Height.SingleValue);

  • This script returns the value of an aggregation, grouped by Green:
    var greenUserHeights = Variables.userHeight2.AllValues["Green"].SingleValue;