Select By Attribute in a model with Field Value Iterator

4079
3
Jump to solution
04-04-2012 02:01 PM
MaximSilin
New Contributor III
Hi All,

Trying to Select Recodrs By Attribute from a feature layer (e.g. Points.shp) based on the field value from a related table (e.g. Points1.dbf). If I run the model as-is (see screenshot), the result is a table view and 4 feature layers (e.g. FLayer0, FLayer1, etc.) in TOC (corresponding to the records in the table view based on my expression). Each 'FLayer' has 1 feature selected in it. However, what I've been trying to achieve is to select all 4 records in a single feature layer. I used ADD_TO_SELECTION selection type on the 'Select Layer By Attribute' tool, but the model doesn't seem to be respecting that. As soon as I remove the %n% from the 'FLayer' output, I end up with FLayer0 with 1 selected feature in it (the selected feature is the last one in the table view, which indicates that the model has iterated 4 times as it was supposed to, but for some reason overwritten all previous selections).

Any ideas on how I might be able to fix this?

Thanks,
Max
0 Kudos
1 Solution

Accepted Solutions
MaximSilin
New Contributor III
My goal was SELECTION (on the original 'Points' layer) based on a field value from a selected recordset in the Related table ('Points1.dbf').


Alright, I have figured this out. Essentially, I had to use a sub-model as per the Help documentation referenced below in order to ensure that the selection set is not overwritten. My issue was that the whole model would get ran on each iteration, overwriting previous layers and therefore not honoring the ADD_TO_SELECTION setting of the Select By Attribute tool.
Branching out the Select By Attribute tool along with the Iterate Field Values iterator into a separate model (as shown on the 'SubModel.jpg' attached) ensures that only the Select By Attribute tool is ran on each iteration, while the rest of tools (i.e. Make Feature Layer and Create Table View) are ran only once. Don't worry that the sub-model doesn't get colored - it will run fine ones the inputs are sent in from within the Main Model. Important thing is to mark all the inputs as well as the Selection Layer output of the sub-model as Model Parameters, so that proper values could be feed in to the Sub-Model from the Main Model. The sub-model is then inserted into the main model as an 'inset model' (see 'MainModel.jpg' attached).

1) "A quick tour of using iterators for iteration???(Looping)"

"If an iterator is added to a model, all tools in the model iterate for each value in the iterator. If you do not want to run each tool in the model for each iterated value, create a submodel/model within a model/nested model that contains only the iterator and add it as a model tool into the main model."

2) "Integrating a model within a model - Advanced use of model iterators"

"When a workflow requires model iteration, the specific tools or processes that need to be run more than once must be separated from those tools or processes that only need to be run once per workflow. In this situation, all tools that need to run multiple times should be placed in one model with a model iterator and used as a submodel. The tools that only need to be run once should be placed in the main model, which calls the iterating submodel."

View solution in original post

0 Kudos
3 Replies
BBicking1
Esri Contributor
Hi All,

Trying to Select Recodrs By Attribute from a feature layer (e.g. Points.shp) based on the field value from a related table (e.g. Points1.dbf). If I run the model as-is (see screenshot), the result is a table view and 4 feature layers (e.g. FLayer0, FLayer1, etc.) in TOC (corresponding to the records in the table view based on my expression). Each 'FLayer' has 1 feature selected in it. However, what I've been trying to achieve is to select all 4 records in a single feature layer. I used ADD_TO_SELECTION selection type on the 'Select Layer By Attribute' tool, but the model doesn't seem to be respecting that. As soon as I remove the %n% from the 'FLayer' output, I end up with FLayer0 with 1 selected feature in it (the selected feature is the last one in the table view, which indicates that the model has iterated 4 times as it was supposed to, but for some reason overwritten all previous selections).

Any ideas on how I might be able to fix this?

Thanks,
Max



Hi Max,

see if Append or Merge get you there.

Barbara
0 Kudos
MaximSilin
New Contributor III
Hi Max,

see if Append or Merge get you there.

Barbara


Barbara,

Thanks for advise, but I don't think that's going to work, because my goal is SELECTION (on the original 'Points' layer). Since all the data I am trying to select is already there, I don't need to append or merge anything. Any other thoughts anyone?

Thanks,
Max
0 Kudos
MaximSilin
New Contributor III
My goal was SELECTION (on the original 'Points' layer) based on a field value from a selected recordset in the Related table ('Points1.dbf').


Alright, I have figured this out. Essentially, I had to use a sub-model as per the Help documentation referenced below in order to ensure that the selection set is not overwritten. My issue was that the whole model would get ran on each iteration, overwriting previous layers and therefore not honoring the ADD_TO_SELECTION setting of the Select By Attribute tool.
Branching out the Select By Attribute tool along with the Iterate Field Values iterator into a separate model (as shown on the 'SubModel.jpg' attached) ensures that only the Select By Attribute tool is ran on each iteration, while the rest of tools (i.e. Make Feature Layer and Create Table View) are ran only once. Don't worry that the sub-model doesn't get colored - it will run fine ones the inputs are sent in from within the Main Model. Important thing is to mark all the inputs as well as the Selection Layer output of the sub-model as Model Parameters, so that proper values could be feed in to the Sub-Model from the Main Model. The sub-model is then inserted into the main model as an 'inset model' (see 'MainModel.jpg' attached).

1) "A quick tour of using iterators for iteration???(Looping)"

"If an iterator is added to a model, all tools in the model iterate for each value in the iterator. If you do not want to run each tool in the model for each iterated value, create a submodel/model within a model/nested model that contains only the iterator and add it as a model tool into the main model."

2) "Integrating a model within a model - Advanced use of model iterators"

"When a workflow requires model iteration, the specific tools or processes that need to be run more than once must be separated from those tools or processes that only need to be run once per workflow. In this situation, all tools that need to run multiple times should be placed in one model with a model iterator and used as a submodel. The tools that only need to be run once should be placed in the main model, which calls the iterating submodel."
0 Kudos