uniqueValues

AMD: require(["esri/smartMapping/statistics/uniqueValues"], (uniqueValues) => { /* code goes here */ });
ESM: import uniqueValues from "@arcgis/core/smartMapping/statistics/uniqueValues.js";
Function: esri/smartMapping/statistics/uniqueValues
Since: ArcGIS Maps SDK for JavaScript 4.4

A function that queries for unique values from a field in a Layer.

Known Limitations

  • SceneLayers must have the supportsRenderer and supportsLayerQuery capabilities enabled unless a predefined statistics object is provided to the statistics parameter of the method. To check a SceneLayer's capabilities, use the getFieldInfoUsage() method.
  • You cannot generate unique values using SQL expressions for client-side FeatureLayers in a SceneView.

Method Overview

Name Return Type Summary Function

Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category.

uniqueValues

Method Details

uniqueValues

Method
uniqueValues(params){Promise<UniqueValuesResult>}

Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category.

Parameters
Specification
params Object

See the table below for details of each parameter.

Specification

The layer from which to query for unique values.

field String
optional

The name of the numeric or string field from which the unique values will be obtained. This property is ignored if a valueExpression is used.

valueExpression String
optional

An Arcade expression following the specification defined by the Arcade Visualization Profile. Expressions may reference field values using the $feature profile variable and must return a string or a number. This property overrides the field property and therefore is used instead of an input field value.

sqlExpression String
optional

A SQL expression evaluating to a number or string.

sqlWhere String
optional

A SQL where clause used to filter features for the statistics query. For example, this is useful in situations where you want to avoid dividing by zero as is the case with creating a predominance visualization.

returnAllCodedValues Boolean
optional

Indicates that all domain codes should be returned if the given field has domain values.

view View
optional

A SceneView or MapView instance is required when a valueExpression is specified.

filter FeatureFilter
optional

A feature filter used to filter statistic queries by geometry. This parameter is only used for filtering statistics by geometry. Any attribute filters set on the FeatureFilter.where property are ignored. Currently, only the intersects spatial relationship is supported. This is useful if you already define a feature filter by geometry on your layer and want to calculate statistics for the included features. Since version 4.25.

features Graphic[]
Deprecated since version 4.23. Use useFeaturesInView instead.
optional

A subset of features for which to generate the unique values.

useFeaturesInView Boolean
optional

Only applicable when the input layer is a service-backed FeatureLayer. When true, statistics will be calculated on the client from features visible in the view. If false, statistics will be requested from the service. Since version 4.23.

forBinning Boolean
optional

Indicates whether the generated statistics are for a binning or clustering visualization. If true, then the input field(s) in this method should refer to aggregate fields defined in the featureReduction property of the layer.

signal AbortSignal
optional

Allows for cancelable requests. If canceled, the promise will be rejected with an error named AbortError. See also AbortController.

Returns
Type Description
Promise<UniqueValuesResult> Returns a promise that resolves to UniqueValuesResult.
Example
let layer = new FeatureLayer({
  portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" }
});

uniqueValues({
  layer: layer,
  field: "Candidate"
}).then(function(response){
  // prints each unique value and the count of features containing that value
  let infos = response.uniqueValueInfos;
  infos.forEach(function(info){
    console.log("CANDIDATE: ", info.value, " # OF CAMPAIGN STOPS: ", info.count);
  });
});

Type Definitions

UniqueValuesResult

Type Definition
UniqueValuesResult

An object that contains the unique values returned from the uniqueValues() query of a layer's field.

Properties
uniqueValueInfos Object[]

An array of objects, each containing a unique value/type/category present in the field specified in the uniqueValues() query. See table below for the specification of each object.

Specification
value String|Number

A unique value representing a type or category of features in the layer.

count Number

The number of features assigned the given value (or belonging to the given category).

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