Feature functions

A set of functions for working with features.


DefaultValue

DefaultValue(container, fieldName, defaultValue) -> Any

Since version 1.26

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 defaultValue.

Example

Return "n/a" if feature attribute does not exist or is empty

Use dark colors for code blocksCopy
1
2
3
DefaultValue($feature, "population", "n/a")
// Returns the population value if available
// or n/a if not available

Domain

Domain(inputFeature, fieldName) -> Dictionary

Since version 1.11

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 codedValue or range.
  • name: Text - The domain name.
  • dataType: Text - The data type of the domain field. It can be one of the following values: esriFieldTypeSmallInteger, esriFieldTypeInteger, esriFieldTypeBigInteger, esriFieldTypeSingle, esriFieldTypeDouble, esriFieldTypeString, esriFieldTypeDate, esriFieldTypeOID, esriFieldTypeGeometry, esriFieldTypeBlob, esriFieldTypeRaster, esriFieldTypeGUID, esriFieldTypeGlobalID, esriFieldTypeXML.
  • codedValues: Array<Dictionary> - Only applicable to codedValue domains. An array of dictionaries describing the valid values for the field. Each dictionary has a code property, which contains the actual field value, and a name 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

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
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

Since version 1.7

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.

Return value: Number | Text

Example

prints the domain code for the field referenced.

Use dark colors for code blocksCopy
1
DomainCode($feature, 'Enabled', 'True')

DomainName

DomainName(inputFeature, fieldName, code?, subtype?) -> Text

Since version 1.7

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

Use dark colors for code blocksCopy
1
DomainName($feature, 'fieldName')

Expects

Expects(inputFeature, field1, [field2, ..., fieldN]?) -> Null

Since version 1.15

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 very 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

Use dark colors for code blocksCopy
1
2
3
4
5
6
// 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

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 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

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
// 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

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
Use dark colors for code blocksCopy
1
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
Use dark colors for code blocksCopy
1
2
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
Use dark colors for code blocksCopy
1
2
3
var dict = { hello:10 }
var p = point({x:10, y:20, spatialReference:{wkid:102100}})
var ftr = Feature(p,dict)

Feature(inputDictionary) -> Feature

Since version 1.23

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 the Geometry function. If geometry is null or missing from the dictionary, then the Feature will be created with a null geometry.
    • attributes: Dictionary - A dictionary containing the attributes and their values.

Return value: Feature

Example

Create a new feature from a dictionary

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
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

Since version 1.23

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

Use dark colors for code blocksCopy
1
var copiedFeature = Feature($feature);

GdbVersion

GdbVersion(inputFeature) -> Text

Since version 1.12

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

Use dark colors for code blocksCopy
1
GdbVersion($feature)

HasValue

HasValue(inputFeature, fieldName) -> Boolean

Since version 1.20

Function bundle: Core

Indicates whether a feature has a given field and if that field has a value.

Parameters

  • inputFeature: Feature - The feature to check.
  • fieldName: Text - The field name to check.

Return value: Boolean

Example

Return false if feature attribute does not exist or is empty

Use dark colors for code blocksCopy
1
2
3
4
if(HasValue($feature, "population")){
  return $feature.population / AreaGeodetic($feature)
}
// Returns the population density if population is available

Schema

Schema(inputFeature) -> Dictionary

Since version 1.11

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 is editable and nullable.
  • geometryType: Text - The geometry type of features in the Feature. Returns esriGeometryNull for tables with no geometry.
    Possible values: esriGeometryPoint, esriGeometryLine, esriGeometryPolygon, esriGeometryNull
  • 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

Since version 1.11

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

Use dark colors for code blocksCopy
1
2
3
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeCode($feature)  // returns 1

SubtypeName

SubtypeName(inputFeature) -> Text

Since version 1.11

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

Use dark colors for code blocksCopy
1
2
3
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeName($feature) // returns "Single Phase"

Subtypes

Subtypes(inputFeature) -> Dictionary

Since version 1.11

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 a name property containing a user-friendly description of the value (e.g. { code: 1, name: "pavement" })
Example

Returns subtypes with coded values from a feature

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
Subtypes($feature)
// returns the following dictionary
// {
//   subtypeField: 'assetGroup',
//   subtypes: [
//     { name: "Unknown", code: 0 },
//     { name: "Single Phase", code: 1 },
//     { name: "Two Phase", code: 2 }
//   ]
// }

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