 HOW TO

# Calculate XY coordinates using Python

## Summary

The instructions provided describe how to calculate XY coordinates using Python.

There are a number of ways to calculate XY coordinates using Python and ArcGIS tools. Two simple Python methods include using the Add XY Coordinates tool syntax or the Calculate Field tool syntax in combination with the Python Extent class within a script.

## Procedure

Both these options can be used from within the tool, the Python window, or a Python script. Below are Python script versions.

The !shape.extent.XMax! and !shape.extentYMax! options can also be used in the Field Calculator when the parser is set to Python.

More complicated extractions of XY coordinates from points can be found in the ArcPy - Points document in the Related Information section.

• The Add XY Coordinates tool creates new fields for Point_X and POINT_Y, calculates their values, and appends POINT_Z, and POINT_M if the input features are Z and M enabled.

The following is an example of calculating the XY coordinates after projecting the feature class:

```# Import arcpy module
import arcpy

# Local variables:
arcpy.env.workspace = r"C:\Test.gdb"
Point = "Point"
Point_Project = "ProjectPoint"

# Process: Project

#Calculate the XY Coordinates
• The next workflow uses the Calculate Field syntax to access the Extent class properties. There are a number of properties that can be calculated, including the XMax and YMax values.

Below is a sample:

```import arcpy
fc = r"C:\New File Geodatabase.gdb\Point"
arcpy.CalculateField_management("Point", "X", "!shape.extent.XMax!","PYTHON_9.3")
arcpy.CalculateField_management("Point", "Y", "!shape.extent.YMax!","PYTHON_9.3")```
```Note:
This functionality is also accessible in ArcGIS 9.3 and 9.3.1 using arcgisscripting. Refer to the Related Information section for more information.```

Article ID:000011473

Software:
• ArcMap

Get help from ArcGIS experts

Contact technical support