Hello everybody,
I'm trying to make a queryFeatures on a feature layer with StatisticDefinition : I would like to calculate statistics on the field "TOTAL" of my feature layer res, with the features which are within my polygon.
Here's my code below : for the moment, I just append a console.log with the result, but the query doesn't work. The array of features stays empty and I don't have any error message. So I guess my query is poorly constructed but I don't see where.
Could you help me please ?
function (polygon, res) {
var queryParams = new Query();
queryParams.spatialRelationship = Query.SPATIAL_REL_WITHIN;
queryParams.geometry = polygon.geometry ;
queryParams.outFields = ["*"];
var countSD = new StatisticDefinition();
var sumSD = new StatisticDefinition();
var avgSD = new StatisticDefinition();
queryParams.outStatistics = [countSD, sumSD, avgSD];
var sqlExpression = "TOTAL";
countSD.statisticType = "count";
countSD.onStatisticField = sqlExpression;
countSD.outStatisticFieldName = "CountResDial";
sumSD.statisticType = "sum";
sumSD.onStatisticField = sqlExpression;
sumSD.outStatisticFieldName = "SumResDial";
avgSD.statisticType = "avg";
avgSD.onStatisticField = sqlExpression;
avgSD.outStatisticFieldName = "AvgResDial";
res.queryFeatures(queryParams,
function (results){
console.log(">>>>>>>>>>>>>> r\351sultats de la query : ");
console.log(results);
},
function (err){
console.log("Impossible r\351cup\351rer le nombre de dialys\351s dans les tranches isochrones : ", err);
}
);
}
You may want to update the StatisticDefintion objects before assigning it on to query parameters.
Thank you for your response. It doesn't change anything however.
what is the value of 'sqlExpression'?
You are using ArcGIS Server 10.1 or greater right?
Requires ArcGIS Server service version 10.1 or greater
The value of 'sqlExpression' is just the name of the field "TOTAL".
And yes, I'm using ArcGIS Server 10.4.
I read that on the API reference for Query :
"The definitions for one or more field-based statistic to be calculated. outStatistics
is only supported on layers/tables where supportsStatistics
is true. If outStatistics
is specified the only other query parameters that will be used are groupByFieldsForStatistics
, orderByFields
, text
, timeExtent
and where
."
Does it mean that the geometry parameter can't work anyway with my query ?
I can get the features in my polygon without the outStatistics property. I can get outStatistics without the geometry parameter for the query. But I can't have both like in this example : ArcGIS API for JavaScript Sandbox : the query have a geometry parameter which is the point clicked by the user, a buffer of 1 mile is calculated around, and the stats are calculated on the features in the buffer from the feature layer. Isn'it contradictory with what is said above ? Or I surely misunderstand...
May be the documentation is not updated. According to the sample, the query does work with geometry and outStatistics. However, they are not using a MapServer to create a FeatureLayer, the sample uses FeatureServer. What kind of service are you using?
Maybe I have an explanation : the spatial reference of my graphic layer (4326) which contains my polygon isn't the same of the one of my map and feature layer (102110), but I don't know why and how to fix this issue. Do you have any idea ?
Thank you !
You can use the esri/geometry/webMercatorUtils | API Reference | ArcGIS API for JavaScript 3.17 to convert the geometry to WebMercator projections system.
Tkanks very much.
The inverse isn't possible I guess ? I would keep wkid 102110 as much as possible.