require(["esri/smartMapping/statistics/uniqueValues"], (uniqueValues) => { /* code goes here */ });
import uniqueValues from "@arcgis/core/smartMapping/statistics/uniqueValues.js";
esri/smartMapping/statistics/uniqueValues
A function that queries for unique values from a field in a Layer.
Known Limitations
- SceneLayers must have the
supportsRenderer
andsupportsLayerQuery
capabilities enabled unless a predefined statistics object is provided to thestatistics
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 |
---|---|---|---|
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. | uniqueValues |
Method Details
-
uniqueValues
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.
ParametersSpecificationparams ObjectSee the table below for details of each parameter.
Specificationlayer FeatureLayer|SceneLayer|CSVLayer|PointCloudLayer|GeoJSONLayer|WFSLayer|OGCFeatureLayer|StreamLayer|OrientedImageryLayer|CatalogFootprintLayer|CatalogLayer|KnowledgeGraphSublayer|SubtypeGroupLayer|SubtypeSublayerThe layer from which to query for unique values.
field StringoptionalThe 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 StringoptionalAn 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 thefield
property and therefore is used instead of an inputfield
value.sqlExpression StringoptionalA SQL expression evaluating to a number or string.
sqlWhere StringoptionalA 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 BooleanoptionalIndicates that all domain codes should be returned if the given field has domain values.
view ViewoptionalA SceneView or MapView instance is required when a
valueExpression
is specified.filter FeatureFilteroptionalA 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 theintersects
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.Deprecated since version 4.23. UseuseFeaturesInView
instead.A subset of features for which to generate the unique values.
useFeaturesInView BooleanoptionalOnly applicable when the input
layer
is a service-backed FeatureLayer. Whentrue
, statistics will be calculated on the client from features visible in the view. Iffalse
, statistics will be requested from the service. Since version 4.23.forBinning BooleanoptionalIndicates 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 thefeatureReduction
property of the layer.signal AbortSignaloptionalAllows for cancelable requests. If canceled, the promise will be rejected with an error named
AbortError
. See also AbortController.ReturnsType Description Promise<UniqueValuesResult> Returns a promise that resolves to UniqueValuesResult. Examplelet 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
-
An object that contains the unique values returned from the uniqueValues() query of a layer's field.
- Properties
-
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.