Select to view content in your preferred language

Model Builder Iteration

1725
4
Jump to solution
01-15-2018 01:41 AM
FelixBuchinger
Emerging Contributor

Hello, i'm using Modelbuilder too analyse a point feture class.

Goal is to iterate different sql expressions out of a tabel to select various features of the point feature class.

Question: is there a possibility to name the output of the selection referring the sql expression out of the iterator.

using the variable %Value% doesnt work because there a spaces in the sql expression (example: YEARS BETWEEN 0 AND 9)

is there a possibility to use for example a different column for the naming?

Currently used iterator: Iterate Field Values

Thanks for the help

1 Solution

Accepted Solutions
curtvprice
MVP Alum

You can use another Calculate Value tool to insert spaces as follows

"%SQL Expr%".replace(" ", "_")

this would convert your expression to the string:

YEARS_BETWEEN_0_AND_9

and use the created variable in your output name instead of %n%:

View solution in original post

4 Replies
curtvprice
MVP Alum

You may want to try the For iterator with Calculate Value tool to generate each sql expression, for example:

Calculate Value expression:

"YEARS BETWEEN {} AND {}".format(%n% * 10, ((%n% + 1) * 10) - 1)

With the For set to be 0 to 2 by 1 you'd get these expressions on each iteration, which you then would pipe into a Select Layer by Attributes or Select tool:

YEARS BETWEEN 0 AND 9
YEARS BETWEEN 10 AND 19
YEARS BETWEEN 20 AND 29‍‍‍‍‍‍

SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop 

Examples of using iterators in ModelBuilder—Tools | ArcGIS Desktop 

0 Kudos
FelixBuchinger
Emerging Contributor

Thank you,

this is working, but not bringing the solution to the main problem.

Even with this way you can't name the output of the Select tool after an iterated input. Like Tool: Select --> Name of the output feature class: "OutputSelect_%Output_Value%" (not working because of the spaces in "YEARS BETWEEN 0 AND 9"). Using the %Value% out of the Iterator `for` doesnt make it any better because then there is only writen "0", "1" an so on... (This can be reached by putting n into the output name of the select tool: "OutputSelect_%n%")

So is there a possibility to tell the iterater so output another column of the iteration tabel?

Thanks for all the help

0 Kudos
curtvprice
MVP Alum

You can use another Calculate Value tool to insert spaces as follows

"%SQL Expr%".replace(" ", "_")

this would convert your expression to the string:

YEARS_BETWEEN_0_AND_9

and use the created variable in your output name instead of %n%:

FelixBuchinger
Emerging Contributor

Thank you so much! That helped a lot

Regards

0 Kudos