Using ArcGIS JavaScript API 4.24 and uniqueValues from esri/smartMapping/statistics/uniqueValues I am able to get Count of all features in a FeatureLayer (fcLayer in this code)
In this example respond is based on AppType field from fcLayer
uniqueValues({ layer: fcLayer, field: "AppType", }).then(function(response) { let infos = response.uniqueValueInfos; infos.forEach(function(info) { console.log("Application Type: ", info.value, " are: ", info.count); }); });
Now Can you please let me know how I can robust this code in a way that I can group and query two fields AppType and AppStat instead of field: "AppType" only?
I tried to use sqlExpression and sqlWhere instead of field option like
sqlExpression = "AppType = 'RD' AND AppStat = 'active'" sqlWhere = "AppType = 'RD' AND AppStat = 'active'"
in the code like
uniqueValues({ layer: fcLayer, sqlExpression = "AppType = 'RD' AND AppStat = 'active'" }).then(function(response) {
or
uniqueValues({ layer: fcLayer, sqlWhere= "AppType = 'RD' AND AppStat = 'active'" }).then(function(response) {
But none of them returning any thing!
Solved! Go to Solution.
Getting statistics for two fields like this is not supported at the moment in this function. However, we are adding support for it in our next release.
In the meantime, you can use Query.outStatistics to get the count of features with values from two fields.
// query for the average of the population change for all features
// Notice that you can pass a SQL expression as a field name to calculate statistics
let statDef = {
onStatisticField: "CASE WHEN AppType = ‘RD’ AND AppStat = ‘active’ THEN 1 ELSE 0 END", // service field for 2015 population
outStatisticFieldName: "RD_active",
statisticType: "sum"
}
let query = layer.createQuery();
query.outStatistics = [ statDef ];
const { features } = await layer.queryFeatures(query);
let stats = features[0].attributes;
console.log("Average change:", stats.RD_active);
Getting statistics for two fields like this is not supported at the moment in this function. However, we are adding support for it in our next release.
In the meantime, you can use Query.outStatistics to get the count of features with values from two fields.
// query for the average of the population change for all features
// Notice that you can pass a SQL expression as a field name to calculate statistics
let statDef = {
onStatisticField: "CASE WHEN AppType = ‘RD’ AND AppStat = ‘active’ THEN 1 ELSE 0 END", // service field for 2015 population
outStatisticFieldName: "RD_active",
statisticType: "sum"
}
let query = layer.createQuery();
query.outStatistics = [ statDef ];
const { features } = await layer.queryFeatures(query);
let stats = features[0].attributes;
console.log("Average change:", stats.RD_active);
Thanks Kristian
This was quick and helpful~