Creating Fields & Calculating Field Values in ArcGIS
(e.g., Area, Length, Unique ID's etc.)
Back
to the
GIS Tutorials & Help
Page...
Back to the
SAL Home Page...
See Calculating Areas of Polygons below
See Calculating Length of Lines below
See Calculating Unique ID values below
~ ~ ~ ~ ~
Creating a new field (from the Attribute Table):
Open ArcMAP
NOTE: To add fields you cannot be in an Edit Session. If you are editing data you must first choose Stop Editing from the main drop down menu of the Editor toolbar .
Open the Attribute Table for a data layer
(right-click on the layer in the Table of Contents and choose Open Attribute Table)
Click on the Options button and choose Add Field...
Enter a Name for the new field:
Less than 10 characters long, no spaces or dashes (-)
Numbers, letters and underscores (_) only
Choose a Type of data for the field to contain
Recommended: Use Long Integer for integers (whole numbers, no decimals)
Use Double for decimal numbers
Use Text for text (characters and/or numbers)
For Integers enter the Precision (number of digits the field can contain)
For Doubles, enter the Precision (total number of digits) & Scale (decimal places)
For Text, enter the Length (number of characters) - default is 50
Note that the defaults for Integers and Double are 0 - a field with 0 Precision cannot contain any digits at all and is thus worthless... be sure to enter a precision/scale relevant to your needs.
Click OK
EXAMPLES: Creating a new field (named "New_field" for Integers or "My_field" for Decimals)
Adding a field for Integers |
Adding a field for Decimals |
|
|
Integers
up to 3 digits long (e.g., 123 or 785) For negative numbers the negative sign uses one 'digit' Decimal values rounded off to nearest integer |
Integers
or Decimals up to 12 digits (e.g. 12,345,678.1234) (8 digits to the left of the decimal point and 4 digits to the right of the decimal point) For negative numbers the negative sign uses one 'digit' |
Min. Value = -99 (the negative sign uses one 'digit') | Min Value = -9,999,999.9999 (only 7 digits to left of point) |
Min. Positive Value = 1 | Min. Positive Value = 0.0001 |
Max. Value = 999 | Max. Value = 99,999,999.9999 |
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Creating a New Field (Using ArcToolbox):
Open ArcToolbox
Open the Data Management toolbox
Open the Fields toolset
Open the Add Field tool
Choose the Table to add a field to
Enter a Field Name
Choose a Field Type (see notes above)
Click OK
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Calculating New Values for an Existing Field:
Open Attribute Table
Optionally begin an Edit Session (this will allow you to undo your work if needed)
Optionally select the record or records you want to update (add values to)
If none are selected ALL records will be updated
Right-click on the Field Heading (the title or name at the top of a column) and choose Calculate Values...
(If not in an Edit session click Yes to warning message)
Enter or build an expression to be used to calculate new values
Click OK
(If in an Edit session, choose Save Edits and/or Stop Editing)
See Examples Below
Adding text to a text field (note the use of ")
Adding numerical data (no ")
Using two existing fields to calculate the value of a third field
Using the FID field (a unique value which always begins with 0) to create a unique ID field. If calculated for all records this will result in a unique ID number for each record with no 0's (1, 2, 3...)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Calculating AREA for a shapefile field:
To calculate the area of an existing polygon (or polygons) you need to check the Advanced option:
Open the Attribute Table
Optionally Select the record or records to update
Right-click on the Area field
(see above for creating a new field and/or general notes on calculating field values)
Check the box beside Advanced
(the dialog box should change to include an additional input box)
In the upper input box (Pre-Logic VBA Script Code) enter:
Dim dblArea as double
Dim pArea as IArea
Set pArea = [shape]
dblArea = pArea.area
In the lower input box (Area = or something like that) enter:
dblArea
Click OK
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Calculating LENGTH for a shapefile field:
To calculate the length of an existing line (or lines) you need to check the Advanced option:
Open the Attribute Table
Optionally Select the record or records to update
Right-click on the Area field
(see above for creating a new field and/or general notes on calculating field values)
Check the box beside Advanced
(the dialog box should change to include an additional input box)
In the upper input box (Pre-Logic VBA Script Code) enter:
Dim dblLength as double
Dim pCurve as ICurve
Set pCurve = [shape]
dblLength = pCurve.Length
In the lower input box (Area = or something like that) enter:
dblLength
Click OK
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
For Perimeter, X & Y coordinates, etc. refer to the ArcGIS help
Back
to the
GIS Tutorials & Help
Page...
Back to the
SAL Home Page...