Thursday, 8 August 2019

If/then VBScript/Python code equivalent to SQL IN ('x','y',z') expression in ArcGIS Field Calculator?



we need just like the following, only with multiple records selected... have tried the "xyz" in (1,2,3,4,5) SQL code but of course VB Script wants something else.


dim f2
if [field1] = "foo" then
f2 = "bar"
end if

Screen shot of this being used in the field calculator.


enter image description here



Answer



If you like SQL, you can apply a Definition Query:



IN('x','y','z')

then process your field calculator results. Only the filtered records will be modified.




If you want Python, it will look similar to the SQL:


if !field1! in ("x","y","z"):
f2 = "field1 is yep"

[Added as solution] Or as a 1-liner without any preprocessing required:


'yes' if !field1! in ('x','y','z') else ''

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...