[GIS] Using a feature iterator Value variable in a SQL expression of select by attribute

arcgis-desktoparcmapiteratormodelbuildersql

I am using Iterate feature selection to select dealers one by one as input features to the Near tool. I'm using Select by Attributes to select sales points from that same dealer. How do I sync the Select by Attribute (dlr_no=%value%) with the current feature selection that is being selected by the iterator?

enter image description here

Best Answer

I suggest few modification to your model and it should work, but in general you are on the right way.

My data (hopefully as yours) include: Dealers point feature class and Sales point feature class. Each sale row has a dealer ID which relates the sale to its dealer.

My modifications are:

  1. I used the Iterate by Row. Iterate by feature iterates through different feature classes, I believe this isn't the case for you, based on the model you attached.
  2. I used Make feature layer instead of select by attributes. This subset only the selected features to a tmp layer, than it can be exported to a new output layer. This is important in particular when using tools like near, that write new fields into the input table, that is to prevent Null Values.

However, my model outputs many output, actually as much outputs as dealers in the input dealer layer. Thus merge can create one output layer from all (either using the suggested model as a nested model within an input and merge model, or trying writing in the input table, hopefuly it won't cause troubles).

The model provided in the image below: Example model I used copy feature to export the tmp layer, and used the %Value% variable within the output name string to mark it by the dealer ID.

The syntax of the SQL expression is showed in the image below (Make Feature Layer tool): Make Feature Layer SQL Expression

The result (an example for one of my two sales with distance from dealers outputs are shown below (note that the input layer: Sales is not being displayed and that the coordinates system is WGS 84, thus near distance is using DD) Example for Result

Related Question