Hitting Max Query Count when specifying IDS_ONLY

403
1
02-28-2023 07:39 AM
JaredFaulk
New Contributor III

Greetings,

I am hitting the max query count for a server when trying to query from the layer. As the API documentation points out--

 

"While there is a limit to the number of features included in the feature set response, there is no limit to the number of object IDs returned in the ID array response. Clients can exploit this to get all the query conforming object IDs by specifying returnIdsOnly=true and subsequently requesting feature sets for subsets of object IDs."

 

Thus, I should request returnIDs only, and expect to get the total list of features with their corresponding ID's, however, when I do, I still get the max count number of features.  Below is the snippet of relevant code I use to query. I specify "IDS_ONLY" in line 55 with 

 

featureTableToQuery.queryFeatureAsync(queryParameterHere, QueryFeatureFields.IDS_ONLY)

 

I get up to 2000 features returned (which corresponds to the max count of the server), but I cannot figure out how to get the full list of Ids. Is there anything I am missing? Is this a bug? Any help would be appreciated! 

 

Note: In this case I am querying based on the queryExtent. The whereClause = "", which should send back all features inside of the queryExtent with no SQL filter applied.  

 

/**
	 * Queries features from a feature layer.
	 * 
	 * @param featureLayerId  - the feature layer from which to query
	 * @param map             - the map to add to
	 * @param whereExpression - an SQL where string
	 * @param queryExtent     - the feature queried must conform to these geometry
	 *                        bounds
	 * @param returnGeometry  - return geometries with query
	 * @param returnIdsOnly   - return ids only
	 * @return list of loaded features or features with ids only
	 */
	public static List<Feature> queryFeaturesFromLayer(String featureLayerId, ArcGISMap map, String whereExpression,
			Geometry queryExtent, boolean returnGeometry, boolean returnIdsOnly) {

		try {

			FeatureLayer featureLayerToQuery = null;
			List<Feature> featureList = new ArrayList<>();

			// get the layer based on its Id
			for (Layer layer : map.getOperationalLayers()) {
				if (layer.getId().equals(featureLayerId)) {
					featureLayerToQuery = (FeatureLayer) layer;
					break;
				}
			}

			// check if feature layer retrieved based on layer Id
			if (featureLayerToQuery == null) {
				String msg = "Specified Id did not match any feature layer in this map";
				System.out.println(msg);
				return featureList;
			}

			// get the feature table from the feature layer: should always be the case right
			// now
			ServiceFeatureTable featureTableToQuery = (ServiceFeatureTable) featureLayerToQuery.getFeatureTable();

			// create a query for the state that was entered
			QueryParameters query = new QueryParameters();
			if (whereExpression != null && !whereExpression.equals(""))
				query.setWhereClause(whereExpression);
			query.setReturnGeometry(returnGeometry);
			query.setMaxFeatures(0); // no max

			if (queryExtent != null) {
				query.setSpatialRelationship(SpatialRelationship.INTERSECTS);
				query.setGeometry(queryExtent);
			}

			// call query features
			ListenableFuture<FeatureQueryResult> future;
			if (returnIdsOnly) {
				future = featureTableToQuery.queryFeaturesAsync(query, QueryFeatureFields.IDS_ONLY);
			} else {
				future = featureTableToQuery.queryFeaturesAsync(query, QueryFeatureFields.LOAD_ALL);
			}
//			featureTableToQuery.
			try {
				// check if there are some results
				FeatureQueryResult featureQueryResult = future.get(); // block until ready!!

				if (featureQueryResult.iterator().hasNext()) {
					for (Feature feature : featureQueryResult) {
						featureList.add(feature);
					}
				} else {
					System.out.println("No features found for " + whereExpression);
					return featureList; // return empty list
				}
			} catch (Exception e) {

				e.printStackTrace();
			}
			return featureList;

		} catch (Exception e) {
			// on any error, display the stack trace
			e.printStackTrace();
			return null;
		}

	}

 

 

0 Kudos
1 Reply
JaredFaulk
New Contributor III

I opened this issue with support and ended up with a feature request for the SDK. A Simple workaround is to hit the REST API directly to get all ID's and then loop through to get all features using the SDK query function.

0 Kudos