A set of functions for working with features.
DefaultValue
DefaultValue(container, fieldName, defaultValue) -> Any
Function bundle: Core
Returns a specified default value if a field name in a feature does not exist or the value at the specified field is null
or an empty text value.
Parameters
- container: Feature - The input feature to check.
- fieldName: Text - The field name to check.
- defaultValue: Any - This value is returned if the field name does not exist or the value at the specified field is
null
or an empty text value.
Return value: Any
Returns the value for the specified field if defined. Otherwise, returns the value specified in default
.
Example
Return "n/a" if feature attribute does not exist or is empty
DefaultValue($feature, "population", "n/a")
// Returns the population value if available
// or n/a if not available
Domain
Domain(inputFeature, fieldName) -> Dictionary
Function bundle: Core
Returns the domain assigned to the given field of the provided feature
. If the feature
belongs to a class with a subtype, this returns the domain assigned to the subtype.
Parameters
- inputFeature: Feature - The Feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) assigned the domain.
Return value: Dictionary
Returns a dictionary described by the properties below.
- type: Text - The type of domain - either
coded
orValue range
. - name: Text - The domain name.
- dataType: Text - The data type of the domain field. It can be one of the following values:
esri
,Field Type Small Integer esri
,Field Type Integer esri
,Field Type Big Integer esri
,Field Type Single esri
,Field Type Double esri
,Field Type String esri
,Field Type Date esri
,Field Type OID esri
,Field Type Geometry esri
,Field Type Blob esri
,Field Type Raster esri
,Field Type GUID esri
,Field Type Global ID esri
.Field Type XML - codedValues: Array<Dictionary> - Only applicable to
coded
domains. An array of dictionaries describing the valid values for the field. Each dictionary has aValue code
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code
).: 1, name : "pavement" } - min: Number - Only applicable to
range
domains. The minimum value of the domain. - max: Number - Only applicable to
range
domains. The maximum value of the domain.
Example
The domain assigned to the feature's subtype
var d = Domain($feature, "poleType")
// the poleType field has a coded value domain called poleTypes
// the value of d will be
// {
// type: "codedValue" ,
// name: "poleTypes",
// dataType: "number",
// codedValues: [
// { name: "Unknown", code: 0 },
// { name: "Wood", code: 1 },
// { name: "Steel", code: 2 }
// ]
// }
DomainCode
DomainCode(inputFeature, fieldName, value?, subtype?) -> Number | Text
Function bundle: Core
Returns the code of an associated domain description in a feature.
Parameters
- inputFeature: Feature - The feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- value (Optional): Text - The value to be converted back into a code.
- subtype (Optional): Number | Text - The coded number or name for the subtype if the feature supports subtyping. If not provided, the current feature's subtype (if it has one), will be used.
Example
prints the domain code for the field referenced.
DomainCode($feature, 'Enabled', 'True')
DomainName
DomainName(inputFeature, fieldName, code?, subtype?) -> Text
Function bundle: Core
Returns the descriptive name for a domain code in a feature.
Parameters
- inputFeature: Feature - The feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- code (Optional): Number | Text - The code associated with the desired descriptive name. If not provided, the field value in the feature will be returned.
- subtype (Optional): Number | Text - The coded number or name of the subtype if the feature supports subtyping. If not provided, the feature's subtype (if it has one) will be used.
Return value: Text
Example
prints the domain description for the referenced field
DomainName($feature, 'fieldName')
Expects
Expects(inputFeature, field1, [field2, ..., fieldN]?) -> Null
Function bundle: Core
Requests additional attributes for the given feature. In some profiles, such as Visualization and Labeling, apps only request the data attributes required for rendering each feature or label. Some expressions dynamically reference field names with variables rather than text literals. This makes it hard for rendering and labeling engines to detect fields required for rendering. This function allows you to explicitly indicate required fields as a list. You can also request all or a subset of fields using a wildcard. Because expressions execute on a per feature basis, the wildcard should be used with caution, especially in layers containing many features. Requesting too much data can result in poor app performance.
Parameters
- inputFeature: Feature - The feature to which the requested fields will be attached.
- field1: Text - A field name to request for the given feature. List only fields required for use in the expression. If necessary, you can request all fields using the wildcard
*
character. However, this should be avoided to prevent loading an unnecessary amount of data that can negatively impact app performance. - [field2, ..., fieldN] (Optional): Text - An ongoing list of field names to request for the given feature. List only fields required for use in the expression.
Return value: Null
Examples
Requests fields not easily detected by the renderer
// Request multiple years of population data if the
// fields cannot be easily detected by the renderer or labels
Expects($feature, 'POP_2020', 'POP_2010')
var thisYear = 2020;
var lastDecade = thisYear - 10;
return $feature['POP_'+thisYear] - $feature['POP_'+lastDecade]
Requests all data matching a pattern in the field name
// Request all the data beginning with 'POP'. This is
// necessary because the renderer can't easily detect
// the required fields based on this expression
Expects($feature, 'POP*')
var startYear = 1880;
var endYear = 2020;
var changes = [];
for(var y=startYear; y<endYear; y+=10){
var startPop = $feature['POP_' + y];
var endPop = $feature['POP_' + (y+10)];
var change = endPop - startPop;
Push(changes, change);
}
Max(changes);
Requests all data for the feature
// Request all fields because the required fields may
// be based on unknown information like a relative date
Expects($feature, '*')
var casesToday = $feature[ 'CASES_' + Text(d, 'MM_DD_Y') ];
var casesYesterday = $feature[ 'CASES_' + Text(DateAdd( Today(), -1, 'days', 'MM_DD_Y') ];
// Change in cases from yesterday
return casesToday - casesYesterday;
Feature
This function has 5 signatures:
- Feature(inputGeometry, attribute1, value1, [attribute2, value2, ..., attributeN, valueN]?) -> Feature
- Feature(jsonText) -> Feature
- Feature(inputGeometry, attributes) -> Feature
- Feature(inputDictionary) -> Feature
- Feature(inputFeature) -> Feature
Feature(inputGeometry, attribute1, value1, [attribute2, value2, ..., attributeN, valueN]?) -> Feature
Function bundle: Core
Creates a new feature.
Parameters
- inputGeometry: Geometry - The geometry of the feature.
- attribute1: Text - The first attribute's name.
- value1: Text | Date | Number | Boolean - The first attribute's value.
- [attribute2, value2, ..., attributeN, valueN] (Optional): Any - Ongoing name/value pairs for each attribute in the feature.
Return value: Feature
Example
Feature(pointGeometry, 'city_name', 'Spokane', 'population', 210721)
Feature(jsonText) -> Feature
Function bundle: Core
Creates a new feature from a serialized JSON string.
Parameter
- jsonText: Text - The serialized JSON representing a feature.
Return value: Feature
Example
var JSONString = '{"geometry":{"x":10,"y":20,"spatialReference":{"wkid":102100}},"attributes":{"hello":10}}'
var ftr1 = Feature(JSONString)
Feature(inputGeometry, attributes) -> Feature
Function bundle: Core
Creates a new feature from a geometry and dictionary of attributes.
Parameters
- inputGeometry: Geometry - The geometry of the feature.
- attributes: Dictionary - A dictionary containing the attributes and their values.
Return value: Feature
Example
var dict = { hello:10 }
var p = point({x:10, y:20, spatialReference:{wkid:102100}})
var ftr = Feature(p,dict)
Feature(inputDictionary) -> Feature
Function bundle: Core
Creates a new feature from a dictionary.
Parameter
-
inputDictionary: Dictionary - A dictionary with the feature geometry and attributes.
- geometry: Geometry | Dictionary - The geometry of the feature. If
geometry
is a Dictionary, then a new Geometry will be constructed using theGeometry
function. Ifgeometry
is null or missing from the dictionary, then the Feature will be created with anull
geometry. - attributes: Dictionary - A dictionary containing the attributes and their values.
- geometry: Geometry | Dictionary - The geometry of the feature. If
Return value: Feature
Example
Create a new feature from a dictionary
var featureDict = {
geometry: Point({ x: -97.06138, y: 32.837, spatialReference: { wkid: 3857 } }),
attributes: {
name1: "value1",
name2: "value2"
}
};
// create a new feature from a dictionary of geometry and attributes
var newFeature = Feature(featureDict);
Feature(inputFeature) -> Feature
Function bundle: Core
Creates a copy of a feature.
Parameter
- inputFeature: Feature - The feature to copy
Return value: Feature
Example
Creates a copy of a feature
var copiedFeature = Feature($feature);
GdbVersion
GdbVersion(inputFeature) -> Text
Function bundle: Core
Returns the name of the current geodatabase version for branch or versioned data. When the data is not in a multi-user geodatabase, an empty text value will be returned.
Parameter
- inputFeature: Feature - A Feature from which to return the current geodatabase version of the associated layer.
Return value: Text
Additional resources
Example
Returns the geodatabase version of the given feature
GdbVersion($feature)
HasValue
HasValue(inputFeature, fieldName) -> Boolean
Function bundle: Core
Indicates whether a feature has a given field and if that field has a value.
Parameters
Return value: Boolean
Example
Return false if feature attribute does not exist or is empty
if(HasValue($feature, "population")){
return $feature.population / AreaGeodetic($feature)
}
// Returns the population density if population is available
Schema
Schema(inputFeature) -> Dictionary
Function bundle: Core
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Velocity | Tasks
Returns the schema description of the provided Feature.
Parameter
- inputFeature: Feature - The feature whose schema to return.
Return value: Dictionary
Returns a dictionary described by the properties below.
- fields: Array<Dictionary> - Returns an array of dictionaries describing the fields in the Feature. Each dictionary describes the field
name
,alias
,type
,subtype
,domain
,length
, and whether it iseditable
andnullable
. - geometryType: Text - The geometry type of features in the Feature. Returns
esri
for tables with no geometry.Geometry Null
Possible values:esri
,Geometry Point esri
,Geometry Line esri
,Geometry Polygon esri
Geometry Null - globalIdField: Text - The global ID field of the Feature. Returns
""
if not globalId-enabled. - objectIdField: Text - The objectId field of the Feature.
SubtypeCode
SubtypeCode(inputFeature) -> Number | Text | Date
Function bundle: Core
Returns the subtype code for a given feature.
Parameter
- inputFeature: Feature - The Feature from which to get the subtype code.
Return value: Number | Text | Date
Example
Returns the code of the subtype
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeCode($feature) // returns 1
SubtypeName
SubtypeName(inputFeature) -> Text
Function bundle: Core
Returns the subtype name for a given feature.
Parameter
- inputFeature: Feature - The Feature from which to get the subtype name.
Return value: Text
Example
Returns the name of the subtype
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeName($feature) // returns "Single Phase"
Subtypes
Subtypes(inputFeature) -> Dictionary
Function bundle: Core
Returns the subtype coded value Dictionary. Returns null
when subtypes are not enabled on the layer.
Parameter
- inputFeature: Feature - The Feature from which to get subtypes.
Return value: Dictionary
Returns a dictionary described by the properties below.
- subtypeField: Text - The field containing a subtype.
- subtypes: Array<Dictionary> - An array of dictionaries describing the subtypes. Each dictionary has a
code
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code
): 1, name : "pavement" }
Example
Returns subtypes with coded values from a feature
Subtypes($feature)
// returns the following dictionary
// {
// subtypeField: 'assetGroup',
// subtypes: [
// { name: "Unknown", code: 0 },
// { name: "Single Phase", code: 1 },
// { name: "Two Phase", code: 2 }
// ]
// }