0

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?

asked Nov 12, 2020 at 3:19

2 Answers 2

0

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, where query.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)
answered Nov 13, 2020 at 1:59
2
  • What about adding a GeometryEngine.Union between the buffer and the query? then you get a dissolved buffer and can query only once. Commented 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 suggestion Commented Dec 11, 2020 at 3:47
0

You can add Sketch widget to create a graphicslayer and use that geometry to select features in target featurelayer. Sketch widget

answered Mar 25, 2021 at 19:43
1
  • 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 user Commented Mar 25, 2021 at 23:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.