English

How To: Calculate Latitude and Longitude values using the Field Calculator.

Summary

Instructions provided describe how to use the Field Calculator to calculate latitude and longitude values for point features.

Procedure

Using VBA Script Code in the Field Calculator, a field of type double can be populated with latitude or longitude values.

  1. Add a field of type double to the attribute table to store either latitude or longitude values.
  2. Start an edit session.
  3. Open the attribute table.
  4. Right-click the field and select Calculate Values.
  5. Check the 'Advanced' check box.
  6. Paste the following code into the 'Pre-Logic VBA Code' box:

    Code:
    Dim Output As Double
    Dim pPoint As IPoint
    Set pPoint = [Shape]
    Output = pPoint.X


    Note:
    The above code is for calculating Longitude. X should be changed to Y to calculate Latitude values.


  7. Type 'Output' into the lower text box.
  8. Click OK.

Related Information