AGSFeatureLayer.selectFeatures is very slow for point selection

961
8
07-15-2019 03:16 PM
SteveMiller4
New Contributor II

I'm trying to select polygons based on where the user clicks. In order to do that I have

let mapPointQuery = AGSQueryParameters()
mapPointQuery.geometry = mapPoint

This eventually works, but is EXTREMELY slow. When I pass in a rectangle for the geometry it is able to select a dozen or so polygons in ~2 seconds, but when I pass in a point it takes ~13 seconds to select a single polygon. It's roughly the same no matter what spatialRelationship I choose. I've tried a few alternative that haven't worked very well:

- The identifyLayers function is faster, but I need to be able to pass in a whereClause query and selection mode

- expanding the point into a small envelope works ok, but it almost always selects multiple polygons and I really want to only select a single one.

Is there some way to speed things up so that point select and rectangle select perform similarly? It seems like the huge difference in performance points to something that can be optimized on the ArcGIS side.

0 Kudos
8 Replies
Nicholas-Furness
Esri Regular Contributor

Is this when querying against a hosted polygon feature layer in ArcGIS Online or some polygon layer in Enterprise?

0 Kudos
SteveMiller4
New Contributor II

Both the 2 second and the 13 second selections are on a polygon layer in Enterprise, via the iOS SDK

0 Kudos
Nicholas-Furness
Esri Regular Contributor

It's a bit of a long shot, but I wonder if your spatial indexes need updating on the backing datastore? I would expect both point and rectangle to perform about the same, at least on the timescales you're talking about. One suggestion would be to connect to the backing dataset in Pro or ArcMap and see if you see similarly poor performance.

0 Kudos
SteveMiller4
New Contributor II

It's fast when selecting a single polygon using the Web Map or the Collector App, and when selecting multiple polygons in the SDK. It's only when selecting a single polygon using selectFeatures in the SDK that it's slow.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Ok, let's back up a bit then. There's some new information there. What's confusing is that it is faster with a polygon geometry on the AGSQueryParameters than with a point. But then with both the Map Viewer and with Collector, it's fast.

Could you share the layer with me over DM? I'd like to try to repro this.

0 Kudos
SteveMiller4
New Contributor II

It's looking like this might be a difficult one to reproduce. The layer is internal data on ArcGIS Enterprise, and when I used an official Esri layer I couldn't recreate the problem (both single and multiple selected in 2-3 seconds). If I get more info I'll follow up.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Thanks. The reason I suggested checking the spatial indexes is because you initially said you were only having trouble when selecting by point rather than by polygon. I've seen spatial queries using a point cause issues with outdated indexes (albeit a long time ago) when compared with the same query using an envelope/polygon.

But it seems more complicated than that.

What you could do is inspect the REST call made by the ArcGIS Online Map Viewer, and inspect the call made by the AGSServiceFeatureTable.query() and compare them. To see the Runtime call, set AGSRequestConfiguration.global().debugLogRequests to true (you could also set debugLogResponses), and you'll see output in the console.

It would be interesting to see if the slowness is in the reply from the query(), or in the visual update from the selectFeature() call.

Or are you calling selectFeaturesWithQuery()?

0 Kudos
SteveMiller4
New Contributor II

It turned out the problem was that I put

mapPointQuery.maxFeatures = 1

in my query. I thought it would make the selection faster by having it return as soon as it found a matching feature, but it actually made it much slower.

0 Kudos