How To: Get X and Y coordinates for a point or a polygon centroid
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.
- Open a new view.
- Load the desired theme.
- Open a new script window.
A. Activate the Project window.
B. Click the Scripts icon.
C. Click New.
- Select Load Text File from the Script menu.
- Navigate to the ..\esri\av_gis30\arcview\samples\scripts directory.
- Select the file addxycoo.ave and click OK.
- 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.
- Switch back to the view and make the target theme active.
- Click the new button to run the script.