QueryTask Distinct Geometry query

284
0
03-09-2021 09:38 AM
AndyWhitaker1
New Contributor III

Hi, in my application, I'm using the ArcGIS for JavaScript, version 3.35. 

In JavaScript, I've created a QueryTask to find all of the features in a layer which are contained in the specified geometry.  This will often exceed 1,000 features as indicated in the exceededTransferLimit property of the resultant FeatureSet.  I have a loop in JavaScript, which loops over the results and adds the unique values to an array.

Is there a way to set the returnDistinctValues property of the Query while also providing the geometry

When we set returnDistinctValues to true, the query does not return any features.  If using Distinct is possible, we could do the processing on the server instead of on the client.  Note: The data is in a file geodatabase.

let myArray = [];
const queryTask = new QueryTask(url);
const query = new Query();
query.geometry = geometry;
query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
query.outFields = ["SOMEVALUE"];
//query.returnDistinctValues = true; // this returns no results when true
query.distance = 10;
query.units = "feet";
queryTask.execute(query,
    function(featureSet) {
	$.each(featureSet.features,
		function(index, feature) {
			const someValue = 
                            feature.attributes["SOMEVALUE"];
            if (someValue &&
			  parseInt(someValue) >= 0) {
			if (myArray.indexOf(someValue) === -1) {										 
                              myArray.push(someValue);
			}
	     }
		});
		resolve(myArray));
	},
	function(err) {
		reject(err);
	});

The FeatureLayer that we're querying has the supportsAdvancedQueries set to true.  ESRI’s documentation says Distinct is supported if the layer has the supportsAdvancedQueries option set to true.

https://developers.arcgis.com/javascript/3/jsapi/query-amd.html#returndistinctvalues

Thanks for any insight or assistance.

0 Kudos
0 Replies