import WhereClause from "@arcgis/core/core/sql/WhereClause.js";const WhereClause = await $arcgis.import("@arcgis/core/core/sql/WhereClause.js");- Since
- ArcGIS Maps SDK for JavaScript 4.14
The WhereClause is used to extract the features that meet a specified condition by parsing the provided results in to a value. The parseWhereClause() method returns a Promise that resolves to an instance of this module.
Properties
| Property | Type | Class |
|---|---|---|
| readonly | string[] | |
| readonly | | |
| readonly | |
fieldNames
- Type
- string[]
An array of the field names used in the where clause. It can be used to get the appropriate fields when querying layers.
- Example
- // parse layer's definition expression into where clause objectsql.parseWhereClause(layer.definitionExpression, layer.fieldsIndex).then(function(clause){layer.queryFeatures({where: "1=1",// where clause object returns layer fields// use these fields to query features from the layeroutFields: clause.fieldsNames}).then(function(results) {// process query results});});
isStandardized
- Type
- boolean
Returns true if the parsed where clause meets the requirements of standardized sql.
parseTree
- Type
- SQLNode
- Since
- ArcGIS Maps SDK for JavaScript 4.24
A parse tree is a data structure for representing a parsed sql statement. Parsing a statement requires the grammar of the language that the statement was written.
Methods
| Method | Signature | Class |
|---|---|---|
| calculateValue(feature: SimpleAttributes): any | | |
| testFeature(feature: SimpleAttributes): boolean | |
calculateValue
- Signature
-
calculateValue (feature: SimpleAttributes): any
Executes the where clause against a feature to generate a value. It is used when the WhereClause is being
used as a simple expression. For example, you can use the expression to gather values for statistics.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| feature | The feature to check against the where clause. | |
- Returns
- any
Returns a value after check feature against the provided where clause. Returns
nullif the provided value is unknown.
- Example
- // calculate the grand total sales price of all featuresfeatureLayer.queryFeatures().then(function(results){let total;const expression = "totalSales * totalPrice";sql.parseWhereClause(expression, layer.fieldsIndex).then(function(whereClause){// check if the where clause meets requirements of standardized sqlif (whereClause.isStandardized){features.forEach(function(feature){total += whereClause.calculateValue(feature)});console.log(total); // prints the total sales price of all features}});});
testFeature
- Signature
-
testFeature (feature: SimpleAttributes): boolean
Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| feature | The feature to test against the | |
- Returns
- boolean
Returns
trueif the test passes,falseotherwise.
- Example
- sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex).then(function(clause){let testResult = clause.testFeature(new Graphic({attributes: {POPULATION: 300000}});console.log(testResult); // prints true});