Is it possible to perform the equivalent of "select by location" in the ArcGIS Server JavaScript API v4.x? The use-case is "find features in Layer 1 which are within x kilometres of features in Layer 2".
Here are the options I've considered:
- a QueryTask with Query.geometry - this will query an entire layer, but only has the option to query against a single geometry object, not another layer
- GeometryEngine.intersect - only works between 2 geometry objects, not 2 layers
- The FindExistingLocations spatial analysis service, which seems to require special licensing which I don't have (I don't have access to ArcGIS Portal on this project)
- Use the GeometryEngine.intersect approach in a JavaScript loop - which would require comparing every feature in both layers against each other (?)
I'm a little surprised that something so commonplace in a desktop GIS doesn't seem to be easily achievable in a web map. Am I missing something obvious?
2 Answers 2
In the absence of a better answer, here's what I've come up with.
For each feature in Layer 2:
GeometryEngine.buffer
the feature's geometry to create the "within X km" buffer- run
QueryTask.execute()
against Layer 1, wherequery.geometry
is the buffer polygon - batch the QueryTasks to avoid overloading the server with too many concurrent queries
- de-duplicate the returned features (if there are overlapping buffers, features will be returned multiple times)
-
What about adding a
GeometryEngine.Union
between the buffer and the query? then you get a dissolved buffer and can query only once.Dror Bogin– Dror Bogin2020年12月09日 11:13:27 +00:00Commented Dec 9, 2020 at 11:13 -
That's an excellent suggestion and it may work well for some cases. After testing, however, I found that it's actually a lot slower to run one mega-query than running a series of smaller queries. Also a series of smaller queries means I can show a progress bar. But many thanks for the suggestionStephen Lead– Stephen Lead2020年12月11日 03:47:22 +00:00Commented Dec 11, 2020 at 3:47
You can add Sketch widget to create a graphicslayer and use that geometry to select features in target featurelayer. Sketch widget
-
Thanks for the suggestion. However in my case I want to "find features in Layer 1 which are within x kilometres of features in Layer 2" rather than finding features which intersect with a polygon drawn manually by the userStephen Lead– Stephen Lead2021年03月25日 23:10:18 +00:00Commented Mar 25, 2021 at 23:10
Explore related questions
See similar questions with these tags.