Reusable calculations in ArcGIS for Desktop
Previously I'd only used the field calculator for simple tasks but this week needed to do a slightly more complex calculation. I wanted to have both a record of the formula and be able to repeat the calculation. Creating a custom tool (either with model builder or python) would do this but seemed excessive for something I won't use more than a couple of times and don't need to share. Then I spotted the option to save and load a calculation. This creates a text file with the expression, giving it the extension .cal to make its purpose more obvious.
The hidden power of Python
The other thing I'd missed was the real significance of being able to use Python. I had seen this as just an alternative script language. I needed to calculate the geodetic distance along a set of lines that represent sea routes. I unearthed some impressive scripts but then stumbled on a way to do it in the field calculator with a single Python expression. As well the standard Python libraries (which cover maths, strong and date functions) you also get access to ArcPy. This set of objects and their methods provide GIS specific functions, so all I needed for my calculation was: !shape.geodesicLength! A quick look at the other examples here shows just what can be done. Don't tell anyone but before now I've resorted to manually counting vertices, I won't be doing that again.
For my next trick
I need to combine logic statements and string manipulation in a code block so I'm going to getting to grips with some more Python. Working with geoprocessing had convinced me I should learn Python and I now have another motivation. By the way, if you need to work with date fields in the field calculator this was covered in detail in a previous post.