Summary
Instructions provided describe how to use a VBA script in the Field Calculator to calculate latitude and longitude values for polygon centroids.
Procedure
- Open the attribute table for the polygon feature class.
- In the attribute table, navigate to Options > Add Field and add two new Double fields. Name one Latitude and the other Longitude.
- Start an edit session.
- Right-click the Longitude Field > Field Calculator.
- Select Advanced.
- Paste the following script into the 'Pre-Logic VBA Code' Box:
Code:
Dim Output As Double
Dim pArea As IArea
Set pArea = [Shape]
Output = pArea.Centroid.X
- Type 'Output' with no quotes into the lower text box.
- Click OK.
- For the Latitude field, repeat steps 4 through 8 except change the X in the last line of the script to a Y.