Select to view content in your preferred language

Model builder: Select Layer by Attributes_select subsets and export to new shapefile

5834
5
Jump to solution
12-16-2012 02:39 AM
ChristinaKassara
Emerging Contributor
Hi,
i would like to create an automated process which will import a text file in ArcMap, convert it to event layer, then select different rows at a time given the value of a field defined as group parameter and export these rows in a different shapefile.

Until now i have figured out how to import the text file and make an event layer for it, but i am stuck with the iteration for attribute selection.
It would also be great if the user could be given the option to choose which rows to be selected (i.e. the value of the group field) each time  they run the model, instead of creating shapefiles for every subset. Is it also possible to name the final shapefile after the value selected for the group field in an automated way? Or if not, is it possible to give the user this opportunity (i.e. by clicking Run Entire Model, a window appears asking them to enter first the value of the group field and then the name of the output shapefile)?

Thanks in advance for your help!
0 Kudos
1 Solution

Accepted Solutions
JeffWard
Honored Contributor
You won't need to iterate the selection, you can use the select tool in Analysis Tools > Extract toolbox.

Use the output from the event layer creation as the input features for the select tool.

You can then make the optional expression for the select tool a model parameter by going to the Insert menu and selecting "Create Variable..." and choose string as the variable type.  You can then right click on the string variable and select "Model Parameter".

Then connect the string variable to the select tool as the Expression input.

For the string variable I would pre-load it with a default expression that works with the data to be selected - while editing the model double click the select tool and click on the SQL button to the right of the Expression input box to build a where clause.  Build a valid expression, copy the text of the expression and click cancel.  Then open the string variable and paste the expression into the string box in the string variable.  If you want you can rename the string variable by right clicking on it and selecting "Rename".  Rename it to be something like "Where Clause:", or "Selection Expression:"  This name will show up when a user runs the tool and is asked for the parameters.

You can also right click on the output of the select tool and make it a model parameter and create a default location and name.  Model parameters allow the user of the tool to specify what goes in that box of the tool.

The tool might look like the attached image when done.

I hope that helps.
Jeff Ward
Summit County, Utah

View solution in original post

0 Kudos
5 Replies
JeffWard
Honored Contributor
You won't need to iterate the selection, you can use the select tool in Analysis Tools > Extract toolbox.

Use the output from the event layer creation as the input features for the select tool.

You can then make the optional expression for the select tool a model parameter by going to the Insert menu and selecting "Create Variable..." and choose string as the variable type.  You can then right click on the string variable and select "Model Parameter".

Then connect the string variable to the select tool as the Expression input.

For the string variable I would pre-load it with a default expression that works with the data to be selected - while editing the model double click the select tool and click on the SQL button to the right of the Expression input box to build a where clause.  Build a valid expression, copy the text of the expression and click cancel.  Then open the string variable and paste the expression into the string box in the string variable.  If you want you can rename the string variable by right clicking on it and selecting "Rename".  Rename it to be something like "Where Clause:", or "Selection Expression:"  This name will show up when a user runs the tool and is asked for the parameters.

You can also right click on the output of the select tool and make it a model parameter and create a default location and name.  Model parameters allow the user of the tool to specify what goes in that box of the tool.

The tool might look like the attached image when done.

I hope that helps.
Jeff Ward
Summit County, Utah
0 Kudos
ChristinaKassara
Emerging Contributor
Thank you for your prompt reply.
I tried to follow your instructions but in the end, when i pressed "Run entire model" i was never prompted to choose the value for the Where Clause expression, nor for the name of the output shapefile.

I have attached an image of the design of the model i built.

I made a XY event layer (input_data_layer) from the original table "input_data.txt".
Then i inserted the "Select" tool.
I linked the event layer with the tool (as Input features).
I opened the tool, clicked the SQL button and i wrote a valid expression [this is how it looks like (FieldName = 'value')], i copied the expression and i clicked on cancel to exit the SQL.
I inserted a new variable of the type "String".
I opened the variable and pasted the aforementioned expression.
I linked the variable to the tool (as Expression).
I set both this variable and the output file as model parameters.
I ran the entire model but it created only one output file based on the value of the expression i had created.
I was never prompted to choose among the available values in the layer, nor to give a name to the output.
I repeated the steps above and instead of specifying a particular value in the SQL expression i left it blank [(FieldName = '')] and reran the model. Then i got an error warning that no selection was made..

Any ideas of what i might be doing wrong?

Thanks in advance
0 Kudos
ChristinaKassara
Emerging Contributor
You can ignore the previous message.
I just got the model running following your instructions (i.e. prompting the user to add the desired value for feature selection and the desired name for the output file).
Thanks again for your help
0 Kudos
JeffWard
Honored Contributor
The parameters are for a user running the tool outside of model builder.  So if you were to double click the tool, or model in ArcCatalog, the two parameters would be shown in the tool's dialog.  You could then specify what you want those parameters to be and run the tool.  I also found that you could have used an SQL Expression as your variable type instead of String, that way when you set it as a parameter, the user could build the expression in a SQL Expression builder.  When the SQL Expression variable is connected to the Select tool, the fields are available to the expression builder.  This would be much better than the string variable because your user could build their own expression using the desired field and the unique values in that field instead of having to have the field and values memorized.

I hope that clarifies things.
Jeff Ward
Summit County, Utah
0 Kudos
ChristinaKassara
Emerging Contributor
Thank you for getting back to me so quickly.
I will try out your advice to see which method suits me better (String vs SQL expression).
Thx!
0 Kudos