Select to view content in your preferred language

Spatially filter a feature layer of Points by a feature layer of Circles

2211
1
Jump to solution
04-08-2021 06:05 PM
sam__b
by
New Contributor

I was wondering if it is possible to do a client side spatial filter of a feature layer view of Points by a different feature layer view of Circles using the JavaScript API. By that I mean, filter the layer of points such that it only displays the points that are inside any Circle in the other feature layer view. You might call this an intersect of the two layers. I see plenty of examples of ways to do a spatial filter with one geometry on a layer, but haven't found a way to filter a layer with an entire other layer or group of geometries. 

If there isn't a fully built in way to achieve this, is there any way that you know that I could work around this while staying inside the JavaScript API?

If this isn't something that is possible with the JavaScript API, is there was a service that you provide that has this ability?

This page somewhat describes what I'm trying to achieve for more context: https://doc.arcgis.com/en/insights/latest/analyze/spatial-filter.htm

 

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there,

Yes it can be done with the JS API. I can think of couple of ways doing this. Others may have better suggestions. I created a very simple test app for you to show how it can be done. In this app, you can click on a state on the map, the app will filter cities that intersect with the state geometry and the state will be highlighted on the map.

You can also click on Select pacific cities button. It will filter out pacific states and cities. To do this, I am using geometry engine to union pacific states then use the unioned geometry to query cities of pacific states. I also commented out a code where I was querying cities one state at a time (second approach). 

In the app, I used layer view queries, layer view filter and layer view highlights to show case different approaches so that you can pick and choose.  All of this happens on the client side. I added the querying part just in case you need to get additional information associated with the selected/filtered features.

 

Hope this makes sense and is helpful,

-Undral

View solution in original post

0 Kudos
1 Reply
UndralBatsukh
Esri Regular Contributor

Hi there,

Yes it can be done with the JS API. I can think of couple of ways doing this. Others may have better suggestions. I created a very simple test app for you to show how it can be done. In this app, you can click on a state on the map, the app will filter cities that intersect with the state geometry and the state will be highlighted on the map.

You can also click on Select pacific cities button. It will filter out pacific states and cities. To do this, I am using geometry engine to union pacific states then use the unioned geometry to query cities of pacific states. I also commented out a code where I was querying cities one state at a time (second approach). 

In the app, I used layer view queries, layer view filter and layer view highlights to show case different approaches so that you can pick and choose.  All of this happens on the client side. I added the querying part just in case you need to get additional information associated with the selected/filtered features.

 

Hope this makes sense and is helpful,

-Undral

0 Kudos