Variable Integration with Extract by Attributes

1412
5
Jump to solution
02-08-2021 04:06 PM
AustinGootee
New Contributor III

Hi Everyone Quick Question,

I am trying to build a model in model builder that ask for a user to define a value in a parameter (string variable) and then integrate this string variable into my raster's extract by attribute tool (spatial analyst). Basically I want a user to be able to enter say "3.2" which is related to a string variable and then utilize this string variable in the where statement of the extract by attribute tool. 

Where value <= (User define value in string variable)

The problem I have is I don't know how to integrate the separate string variable into the sql where clause.

 

AustinGootee_0-1612829181703.png

 

 

0 Kudos
1 Solution

Accepted Solutions
KoryKramer
Esri Community Moderator

Are you familiar using inline variable substitution in ModelBuilder?  https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/modelbuilder/inline-variable-su...

I made a quick mock-up based on your screenshot and this works fine.

KoryKramer_0-1612876527088.png

Note, though, that my Critical Value variable is a Float, not a String.  Why do you need the variable to be a String when ultimately it has to be a number in order to compare against a numerical value in the raster?  The users would be expected to enter a number for that parameter, correct?

View solution in original post

0 Kudos
5 Replies
DavinWalker2
Esri Contributor

Hi Austin,

This should hopefully help out.

Your SQL query should formatted like this:

'"FieldName" = \'{0}\'' .format(Critical_Value)

 

AustinGootee
New Contributor III

I apologize, I am new to this whole sql coding, python is where my expertise lie, but i am trying to build my model out in model builder for other coworkers who are less skilled in python. I am still running into some errors and I think it's just because I am having a hard time wrapping my head around the coding.

AustinGootee_0-1612833814456.png

 

0 Kudos
DavinWalker2
Esri Contributor

Sorry I didn't explain it well enough. The FieldName represents the field you are doing the WHERE clause against. In your case it's VALUE

'"VALUE" = \'{0}\'' .format(NOAA_IH_Year_1_Crit_Value)

KoryKramer
Esri Community Moderator

Are you familiar using inline variable substitution in ModelBuilder?  https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/modelbuilder/inline-variable-su...

I made a quick mock-up based on your screenshot and this works fine.

KoryKramer_0-1612876527088.png

Note, though, that my Critical Value variable is a Float, not a String.  Why do you need the variable to be a String when ultimately it has to be a number in order to compare against a numerical value in the raster?  The users would be expected to enter a number for that parameter, correct?

0 Kudos
AustinGootee
New Contributor III

I am, I had wanted to use inline variable substitution but was unsure if it would work with the SQL coding. The reason I had used a string was simply because I couldn't find a number/float variable type in the model builder options and figured that I could just as easily utilize a float() function to transform the string into a float.

0 Kudos