queryFeatures is not returning all intersected features

200 Views Asked by At

Intended effect

When user clicks on a polygon feature (a county, region, or neighborhood/municipality) or uses the "Draw" widget, a dashboard card displays the number of intersected point features returned by queryFeatures() (see below).

localitiesLayer.queryFeatures(query).then(function(results) {
    var queriedLocalities = results.features;
    if (queriedLocalities.length > 0) {
        var fossilsFound = queriedLocalities.length;
    } 
}

Issue

The maximum number of returned intersected features is 2,000 even when more than 2,000 point features have been selected.

In the photo below, there are only "2000 fossil sites in the area!" when there should be over 3,000 features returned.

"2000 fossil sites should be over" 3,000

Troubleshooting

The issue is fixed when instead of querying the localitiesLayer feature layer, a feature layer view is instead queried. This introduces the unsolvable issue of the number of localities returned by queryFeatures changing depending on the level of zoom (as detailed in the API Reference for queryFeatures of FeatureLayerView).

Since it seems I'm stuck using a server-side query, I need to understand why this is happening at such a seemingly arbitrary number.

At first I thought it was related to possible topology issues between features, but why would that affect the polygon generated by the Draw widget? Before writing this question I also ran the integrate tool on all features layers just to make sure that there wasn't any non-coincident polygons.

Question

Why is the upper limit of features returned by the queryFeatures() on the localitiesLayer 2,000 even when more than 2,000 point features intersect with a selected polygon?

Why does querying with a feature layer view fix this issue (though as detailed above is not a valid solution to this problem)?

CodePen of app with bug

1

There are 1 best solutions below

0
On

Usually feature services has a maximum amount of features to retrieve in one query. This is what is happening here.

You can check the service endpoint of the layer (LAU_Localities_View - 0) to find these value in Max Record Count, here set to 2000.

So you will have to use some other technique in order to have all the values. One simple way is to iterate and query with an extra condition using a field as last index, for example OBJECTID. You will have to order the result by the index field.