In this post, we will use the attribute table field calculator to derive values to populate new fields on the attribute table.
The sample dataset is a polygon shapefile of administrative units in Africa and a point feature shapefile of the most populated cities in Africa. Add the sample dataset to the map. In the Table of Contents on the left pane-Right Click on the Point feature layer and select Open Attribute Table from the drop down list.
Click on the red boxed drop down button and select Add Field (cursor finger position) to create a new attribute field on the table.
The Add Field dialog box pops up. Give the field a name and select a Type-whether integer for whole numbers or text for alphabets etc. For the demonstration, short integer is selected. Click OK and the new field is added to the attribute table.
The new attribute field –per_urban- was created to house the percentage of the ratio of the urban population against the population of each country where the urban area is situated in.
Right Click on the attribute field and Choose Field Calculator from the drop down menu.
(Note: It is better to use the Field Calculator when in a editing mode. This will allow for changes to be made in the event that mistakes were made).
In the Field Calculator window, write the VB Script that as [urban_area]/[country_po]*100. Simply interpreted as populate the field – per_urban with the values in the field-urban_area divided by the values in the column multiplied by a 100.
The result (red boxed) is shown on the attribute table in the screenshot below. Note that when the attribute field-per_urban was created, the field type was given as a short integer. This will allow the percentage round up to whole numbers leaving no decimal places. Save edits before closing the attribute table.
In the Table of Contents-Right Click on the Point feature layer. Choose Properties on the drop down list.
Click on Symbology tab and select Categories on the left pane under Features > Graduated colors and classify the newly created attribute field-per_urban.
On the map window we can visualize the different classes created.
You can use the field calculator for other types of functions which are not mathematical or numeric in nature. We will deal with more complex use of the attribute field calculator in ArcMap in later posts. We hope you enjoyed this post.