Buffer and Select

1940
12
03-16-2020 12:11 PM
jaykapalczynski
Frequent Contributor

I am looking for a down and dirty example of taking an XY coordinate from user and running a buffer (set distance), then selecting all the poly features that touch or are within the buffer.....

Any examples out there?

0 Kudos
12 Replies
UndralBatsukh
Esri Regular Contributor

Yes you should modify the query parameters to meet your needs. So LayerView.queryFeatures() returns features only available for drawing on the client side. If you must query all features in your service then you must use FeatureLayer.queryFeatures() method. This will issue a network request to your service. So you should change your code to use layer.queryFeatures instead of layerView.queryFeatures() method.

I want to point out the following query parameters will create a 10 mile buffer around the view extent. So you need to decide on within 500 miles of what? The view.extent? View center? User defined location? You as a developer need to be responsible for setting the geometry for your query.

layerView.queryFeatures({
  geometry: view.extent, view.center? user defined location?
  returnGeometry: true, => Set to this to false if you do not need geometries
  orderByFields: ["WMA_Name"],
  distance: 10, 
  units: "miles"
 });

Also how many features do you have in your service? Querying features within 500 miles sounds like may put strain.  When you query features do you need to get geometries? If not, then set your returnGeometry to false. Do you only need certain attributes? Then please specify outFields property on your query parameter. 

Take a look at this sample to see how spatial queries work. 

0 Kudos
UndralBatsukh
Esri Regular Contributor

Make the following change in your code:

featureLayer.queryFeatures({
  geometry: view.center,
  returnGeometry: false,
  orderByFields: ["WMA_Name"],
  distance: 500,
  units: "miles"
})
0 Kudos
jaykapalczynski
Frequent Contributor

Making great progress....will be posting my solution in the next day or so...Undral thank you for your guidance and thoughts....

weird transition from 3.x to 4.x

0 Kudos