Friday, 10 January 2020

arcmap - Adding hyphen in ArcGIS Field Calculator to merge two columns?


I am trying to build a field calculator expression to merge two columns into one. I am looking for the word that makes it a range.


Example: I have 2 columns in elevation, From and To. I want to make them like "4100 - 4200" where I add the hyphen. How do I do that ?


table showing data being worked with



Answer



You will want to concatenate the two fields together.


To do this in ArcMap you can use the VB Script function "&". So using your example, the calculation would be


[FROM] & "-" & [TO]


You could also use Python syntax, in which case your code would be:


str(!FROM!) + "-" + str(!TO!)

With Python you want to be sure to enclose the fields in the string function -- str()--, so that Python knows you are trying to concatenate two strings together, and not do a mathematical computation.


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...