outStatistics in a query deletes geometry data

312
3
Jump to solution
12-03-2019 12:44 AM
New Contributor III

So i have a working query that returns a  featureSet that is made into a layer.

 I want to add some stats about the query and add them to a feature.

i added a simple statistic query that works but when its time to create a new layer after the query is returned i get :

name: "feature-layer:missing-property", message: "geometryType not set and couldn't be inferred from the provided features"

this error is automaticly fixed when i cross the query.outStatistics  line from my query.

do i really need to create two identical querys for stats and for visual display?

heres a pen with the query.outStatistics crossed out: https://codepen.io/segev-salman/pen/OJPJGxX 

Reply
0 Kudos
1 Solution

Accepted Solutions
Frequent Contributor

Ok, I think I understand now. As soon as you populate the outStatistics of the query, we assume you only want to get statistics. What you could do, is run the query first to get your features.

Then you can do the statistics query against the layerview, this will run the query on the data already available on the client rather than go back to the server.

We have a number of samples for this kind of pattern.

Sample Code | ArcGIS API for JavaScript 4.13 

So you would need to perform two queries, but you don't have to go back to the server twice if you don't want to.

View solution in original post

3 Replies
Frequent Contributor

outStatistics does not return geometry, as the statistics are based on all the values that meet the where clause of your query.

I'm not quite clear on what you are trying to do.

var avgPricePerMeter = {
onStatisticField: "OBJECTID", // service field for 2015 population
outStatisticFieldName: "PricePerMeter_avg",
statisticType: "avg"
};‍‍‍‍‍

OBJECTID fields don't have any meaning beyond being unique identifiers. Do you intend to do something like this?

var avgPricePerMeter = {
onStatisticField: "PricePerMeter", // field that has price information?
outStatisticFieldName: "PricePerMeter_avg",
statisticType: "avg"
};‍‍‍‍‍‍‍‍‍‍

This will do SQL query similar to this against your data

SELECT AVG(PricePerMeter) AS 'PricePerMeter_avg'
FROM service
WHERE <query.where>‍‍‍

Which only returns a single result with your Average stat on that field.

New Contributor III

This is exactly right, I should have clarified that the layer is just a filler.

The real layer has building groups as id (the input) and i want the avg of their price.

I dont expect outStatistics to return geometry, and wrote the right query(using ObjectID just as a filler expecting to get the same result entered as avg) but in the same query i ask for geometry and outfields.

dont i get them all as part of the featureSet?

can it look like this?

var avgPricePerMeter = {
  onStatisticField: "PricePerMeter",  // field that has price information?
  outStatisticFieldName: "PricePerMeter_avg",
  statisticType: "avg"
};

var query = pointService.createQuery();
query.returnGeometry = true;
query.outFields = ["*"];
query.where = gushHelka + " = " + input
query.outStatistics = [avgPricePerMeter]

giving me the geometry stats and fields all of them essential to my popupTempalte at the same time

I made this new pen : https://codepen.io/segev-salman/pen/YzPPPNo 

Assuming i cant get it all in the same query i made nquey just for the statistics and featureUpdate as a function that builds a new popuptemplate with the basic fields and the stats using only the featureSet from the nquery, problem was

that i got the avg stat but not the name or objectid even tho i had the outfields inside nquery too.

I scraped it after timing issues getting the avg after the template was already made and thinking about making a promise that waits for the stats and then makes the layer.

This has got to be the wrong way to go about it right? I already have a query with the right results do i need to make the same one from 0 and wait for then again just to avg a field? 

*sorry for the formatting im using a phone

Reply
0 Kudos
Frequent Contributor

Ok, I think I understand now. As soon as you populate the outStatistics of the query, we assume you only want to get statistics. What you could do, is run the query first to get your features.

Then you can do the statistics query against the layerview, this will run the query on the data already available on the client rather than go back to the server.

We have a number of samples for this kind of pattern.

Sample Code | ArcGIS API for JavaScript 4.13 

So you would need to perform two queries, but you don't have to go back to the server twice if you don't want to.

View solution in original post