Skip to content
import AttributeBinsQuery from "@arcgis/core/rest/support/AttributeBinsQuery.js";
Inheritance:
AttributeBinsQueryAccessor
Since
ArcGIS Maps SDK for JavaScript 4.32

This class configures parameters for the queryAttributeBins method, which groups features in a layer or layer view into bins based on numeric or date fields. This operation is useful for summarizing and analyzing large datasets by organizing them into meaningful groups, or bins, making it easier to detect patterns, trends, and anomalies across different ranges or time periods.

The binParameters property defines bin characteristics like size and start value, while the outStatistics parameter specifies the information each bin provides. Features can be filtered using a where condition and a spatial filter. Bins are arranged consecutively with no gaps: they are left-inclusive and right-exclusive, except for the last bin, which is right-inclusive. The method supports multiple statistical aggregations per bin and defaults to a histogram of value frequencies/counts if no specific aggregations are provided in outStatistics.

Bins are defined using one of the bin parameters, each supporting distinct parameters for handling boundaries between bins. Understanding the purpose of each bin parameter is crucial for understanding binning and boundary settings. There are four types of bin parameters:

Bin parameter typeDescription
AutoIntervalBinParametersYou specify the number of numBins, start and end values of the binning. The bin size is calculated by dividing the dataset's range by this number of bins.
FixedBoundariesBinParametersThe bins strictly follow the specified input values. The first item in the array specifies the lower boundary of the first bin, while the last item specifies the upper boundary of the last bin. Intermediate values represent the lower boundaries of each bin.
FixedIntervalBinParametersThe number of bins is not important, but the interval size must match the input data. Each bin will cover a range that exactly fits the specified interval.
DateBinParametersThe intervals are based on calendar units. For example, with monthly intervals, each bin represents an entire month.
See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
PropertyTypeClass
"ascending" | "descending" | null | undefined
declaredClass
readonly inherited
"intersects" | "contains" | "crosses" | "disjoint" | "envelope-intersects" | "index-intersects" | "overlaps" | "touches" | "within" | "relation"
"feet" | "miles" | "nautical-miles" | "us-nautical-miles" | "meters" | "kilometers" | null | undefined

binOrder

Property
Type
"ascending" | "descending" | null | undefined

Bins can be returned in ascending or descending order. The default is ascending.

Default value
"ascending"

binParameters

autocast Property
Type
BinParameters

Bin parameters describe the characteristics of the bins, including their size and starting value. Each bin's size can either be specified by a parameter or calculated dynamically. Additionally, bins can be based on either date or numeric values.

cacheHint

Property
Type
boolean | null | undefined

Indicates if the service should cache the query results. It only applies if the layer's capabilities.query.supportsCacheHint is set to true. Use only for queries that have the same parameters every time the app is used. Some examples of cacheable queries:

datumTransformation

Property
Type
DatumTransformation | null | undefined

Datum transformation used for projecting geometries in the query results when outSpatialReference is different than the layer's spatial reference. Requires ArcGIS Server service 10.5 or greater.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

distance

Property
Type
number | null | undefined

Specifies a search distance from a given Query.geometry in a spatial query. The units property indicates the unit of measurement. In essence, setting this property creates a buffer at the specified size around the input Query.geometry. The query will use that buffer to return features in the layer or layer view that adhere to the to the indicated spatial relationship.

If querying a feature service, the supportsQueryWithDistance capability must be true.

geometry

autocast Property
Type
GeometryWithoutMeshUnion | null | undefined

The geometry to apply to the spatial filter. The Query.spatialRelationship will indicate how the geometry should be used to query features.

Known Limitations

Mesh geometry types are currently not supported.

lowerBoundaryAlias

Property
Type
string | null | undefined

Sets the name of the lower boundary property in the response. By default, the lower boundary is name lowerBoundary and indicates the value at the edge of each bin.

outSpatialReference

autocast Property
Type
SpatialReference | null

The spatial reference for the returned geometry. If not specified, the geometry is returned in the spatial reference of the queried layer.

outStatistics

autocast Property
Type
StatisticDefinition[] | null | undefined

The definitions for one or more field-based statistics to be calculated. For service-based queries, check the layer's query.queryAttributeBins.supportedStatistics capabilities to ensure that the layer supports statistics queries.

Example
// get the average temperature for each bin
let statisticDefinition = new StatisticDefinition({
statisticType: "avg",
onStatisticField: "temp",
outStatisticFieldName: "temp_avg"
});
// Query bins with fixed interval bin parameters based on field "temp" with 5 degrees interval.
const binQuery = new AttributeBinsQuery({
binParameters: new FixedIntervalBinParameters({
interval: 5, // the interval size for each bin. In this case, 5 degrees celsius
field: "temp", // the field to bin, containing the temperature data
start: 0, // the lower boundary of the first bin. 0 degrees celsius
end: 30 // the upper boundary of the last bin. 30 degrees celsius
}),
// get the average temperature for each bin
outStatistics: [statisticDefinition]
});

outTimeZone

Property
Type
IANATimeZone | null | undefined

Defines the IANA time zone used for bin calculations when the bin parameter field is a date field. If not specified, the UTC time zone is used for binning calculations. When a time zone is specified, dates and times will be adjusted according to that IANA time zone.

See also
Example
// Query bins with date interval bin parameters based on field "date" with monthly intervals.
const binQuery = new AttributeBinsQuery({
binParameters: new DateBinParameters({
interval: 3,
field: "RecordedDate",
start: new Date(Date.UTC(1980, 0, 2, 0, 0)),
end: new Date(Date.UTC(1980, 2, 1, 0, 0)),
number: "1",
unit: "months"
}),
outTimeZone: "America/New_York" // Get the binning results in Eastern Time Zone
});

returnDistinctValues

Property
Type
boolean | null | undefined

If true, all aggregations apply on distinct values.

Default value
false

spatialRelationship

Property
Type
"intersects" | "contains" | "crosses" | "disjoint" | "envelope-intersects" | "index-intersects" | "overlaps" | "touches" | "within" | "relation"

For spatial queries, this parameter defines the spatial relationship to query features in the layer or layer view against the input Query.geometry. The spatial relationships discover how features are spatially related to each other. For example, you may want to know if a polygon representing a county completely contains points representing settlements.

The spatial relationship is determined by whether the boundaries or interiors of a geometry intersect.

  • Boundary — The endpoints of all linear parts for line features, or the linear outline of a polygon. Only lines and polygons have boundaries.
  • Interior — Points are entirely interior and have no boundary. For lines and polygons, the interior is any part of the geometry that is not part of the boundary.

The possible values for this parameter are described below and the images highlight the geometries returned for the specified spatial relationship for given geometries.

The intersects spatial relationship returns features in the layer view that intersect the query Query.geometry.

intersects

The contains spatial relationship returns features in the layer view that are completely contained by the query Query.geometry.

contains

The crosses spatial relationship returns features in the layer view when the interior of a query Query.geometry comes into contact with the interior or boundary of features in the layer view. In other words, the geometries share some interior area, but not all interior area.

crosses

The envelope-intersects spatial relationship returns features in the layer view that intersect the envelope (or extent) of the filter Query.geometry.

envelope-intersects

The overlaps spatial relationship returns features in the layer view that overlap the query Query.geometry. Only features of the same geometry can be compared.

overlaps

The touches spatial relationship returns features in the layer view that touch the query Query.geometry. The boundaries of the geometries intersect, but not their interiors.

touches

The within spatial relationship returns features in the layer view that completely contain the query Query.geometry. In other words, the filter geometry is completely within the features in the layer view. It is opposite of contains.

within

The disjoint spatial relationship returns features in the layer view that do not intersect the query Query.geometry in anyway. Opposite of intersects.

disjoint

Known Limitations

For spatial queries on 3D Object SceneLayers and BuildingSceneLayers the spatial relationship is evaluated based on the Extent of the feature and not the footprint. This means that a feature might be returned from the query, even though its footprint is not in a spatial relationship with the Query.geometry. Currently only intersects, contains, and disjoint spatialRelationships are supported on spatial queries for 3D Object SceneLayers and BuildingSceneLayers.

Default value
"intersects"
Example
let query = new Query({
spatialRelationship: "contains"
});

timeExtent

autocast Property
Type
TimeExtent | null | undefined

A time extent for a temporal query against time-aware layers. For example, it can be used to discover all crimes that occurred during the night shift from 10 PM to 6 AM on a particular date.

Example
let layer = new FeatureLayer( ... );
let timeExtent = new TimeExtent({
start: new Date(1992, 0, 1),
end: new Date(1992, 11, 31)
});
let timeQuery = new Query({
timeExtent: timeExtent
});
layerView.queryFeatures(timeQuery).then(function(featureSet) { ... });

units

Property
Type
"feet" | "miles" | "nautical-miles" | "us-nautical-miles" | "meters" | "kilometers" | null | undefined

The unit for calculating the buffer distance when Query.distance is specified in spatial queries. If units is not specified, the unit is derived from the geometry spatial reference. If the geometry spatial reference is not specified, the unit is derived from the feature service data spatial reference. For service-based queries, this parameter only applies if the layer's capabilities.query.supportsDistance is true.

Example
// Query at a distance in pixels of the query geometry.
// Use the unit of the query geometry's spatial reference.
layerView.queryFeatures({
geometry: event.mapPoint,
distance: 2 * view.resolution,
returnGeometry: true
}).then(processResults);

upperBoundaryAlias

Property
Type
string | null | undefined

Sets the name of the upper boundary property in the response. By default, the upper boundary is name upperBoundary and indicates the value at the edge of each bin.

where

Property
Type
string | null | undefined

A where clause for the query. Any legal SQL where clause operating on the fields in the layer is allowed. Be sure to have the correct sequence of single and double quotes when writing the where clause in JavaScript.

Default value
"1=1"
Examples
query.where = "NAME = '" + stateName + "'";
query.where = "POP04 > " + population;

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
clone
inherited
clone(): this
toJSON
inherited
toJSON(): any

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameters
ParameterTypeDescriptionRequired
json
any

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
any

Returns a new instance of this class.

clone

inherited Method
Signature
clone (): this
Inherited from: ClonableMixin

Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.

Returns
this

A deep clone of the class instance that invoked this method.

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
any

The ArcGIS portal JSON representation of an instance of this class.

Type definitions

BinParameters

Type definition

Bin parameters describe the characteristics of the bins, including their size and starting value. Each bin's size can either be specified by a parameter or calculated dynamically. Additionally, bins can be based on either date or numeric values.

See also