NYGeog

Geography, GIS, Geospatial, NYC, etc.

Friday, December 17, 2010

Replace((Right([ID],3)), "_", "") in ArcGIS Field Calculator

It seems like for the longest time I've used multiple temp fields for parsing values out of non-standard length text or integer unique ID values. For example, in a text field, unique (shown here in a python list format for no reason in particular other than I am learning python) ID's like;

list = [12345_N1, 12345_B25, 6789_N1, 6789_B25, 6789_B50]

Normally, I would create a temp field and say;

Right([list], 3)

create a temp2 field and select the '_N1' values and calculate that separately with;

Right([list], 2)

and then combine the two things together into one field in a haphazardly but workable way.

Granted, the more complex a statement is, the more chances for error, but once the syntax is set and ingrained in your vocabulary its amazing how much work you'll save in the future. So a more elegant solution to the problem stated above with just one field and one calculation is;

Replace((Right([ID],3)), "_", "") *

So what we are doing here is using the Replace function, which is like;
replace([FIELD_name],"",""

So instead of using [FIELD_name] I'm saying remove these stupid underscores from our selection of the 3 characters from the right side of the field and replace them with "" or nothing.

*Replace (see http://resources.arcgis.com/content/kbase?fa=articleShow&d=20119)

According to Neocartography, the Replace function "kicks ass" (see http://neocartography.wordpress.com/2009/12/22/kicking-ass-with-the-replace-function-in-arcmap-field-calculator/).