Summary
Adds information to a feature's attribute fields representing the spatial or geometric characteristics and location of each feature, such as length or area and x-, y-, z-, and m-coordinates.
A similar tool that adds multiple geometry attributes to new attribute fields is theAdd Geometry Attributes tool.
Usage
If a coordinate system is specified, the length and area calculations will be in the units of that coordinate system unless different units are selected in the Length Unit and Area Unit parameters.
If the input features have a selection, only the selected features will have values calculated in the added fields; all other features will maintain their existing value.
This tool works with point, multipoint, polyline, and polygon feature classes.
Syntax
CalculateGeometryAttributes_management (in_features, field, geometry_property, {length_unit}, {area_unit}, {coordinate_system})
Parameter | Explanation | Data Type |
in_features | The feature layer with a field that will be updated with geometry calculations. | Feature Layer |
field | The field that will be updated with geometry calculations. | Field |
geometry_property [[Target Field, Property],...] | Specifies the fields in which to calculate geometry properties and the geometry properties to calculate. The following are supported geometry properties:
| Value Table |
length_unit (Optional) | The unit used to calculate length.
| String |
area_unit (Optional) | The unit used to calculate area.
| String |
coordinate_system (Optional) | The coordinate system in which the coordinates, length, and area will be calculated. The coordinate system of the input features is used by default. | Coordinate System |
Derived Output
Name | Explanation | Data Type |
updated_features |
Code sample
CalculateGeometryAttributes example (Python window)
The following Python window script demonstrates how to use the CalculateGeometryAttributes tool.
import arcpy
arcpy.env.workspace = r"C:\data\City.gdb"
arcpy.CalculateGeometryAttributes_management("roads", [["Length_mi", "LENGTH"], ["Stops", "POINT_COUNT"]], "MILES_US")
CalculateGeometryAttributes example (stand-alone script)
Get the extent rectangle of each feature.
# Name: ExtentCreation.py
# import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:\data\City.gdb"
arcpy.env.outputCoordinateSystem = arcpy.Describe("roads").spatialReference
# Set local variables
in_features = "roads"
# Generate the extent coordinates using CalculateGeometry
arcpy.CalculateGeometryAttributes_management(in_features, [["Left", "EXTENT_MIN_X"],
["Bottom", "EXTENT_MIN_Y"],
["Right", "EXTENT_MAX_X"],
["Top", "EXTENT_MAX_Y"]])