English

How To: Get X and Y coordinates for a point or a polygon centroid

Summary

ArcView GIS 3.x comes with a sample script that adds X and Y coordinates to the attribute table of the active point or polygon theme. The script adds two new fields named X-coord and Y-coord and populates those fields accordingly. If the active theme is a polygon theme, the X and Y coordinates of the polygon centroid are calculated. The polygon centroid is based on the polygon's center of mass. The centroid coordinate values are in the same units as the theme.

Procedure

  1. Open a new view.
  2. Load the desired theme.
  3. Open a new script window.
     
    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.
  4. Select Load Text File from the Script menu.
  5. Navigate to the ..\esri\av_gis30\arcview\samples\scripts directory.
  6. Select the file addxycoo.ave and click OK.
  7. Attach the script to a button.
     
    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.
  8. Switch back to the view and make the target theme active.
  9. Click the new button to run the script.