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 the Add 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.
Caution:
This tool modifies the input data. See Tools that do not create output datasets for more information and strategies to avoid undesired data changes.
Syntax
CalculateGeometryAttributes(in_features, geometry_property, {length_unit}, {area_unit}, {coordinate_system}, {coordinate_format})
Parameter | Explanation | Data Type |
in_features | The feature layer with a field that will be updated with geometry calculations. | Feature Layer |
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. For coordinate-based geometry properties, the coordinate system will only be applied when the coordinate format is the same as input; otherwise, the geographic coordinate system WGS_1984 will be used. | Coordinate System |
coordinate_format (Optional) | The coordinate format in which the x- and y-coordinates will be calculated. The coordinate format matching the input features' spatial reference units is used by default. Several coordinate formats, including Degrees Minutes Seconds, Degrees Decimal Minutes, and others, require the calculation to be performed in a text field.
| String |
Derived Output
Name | Explanation | Data Type |
updated_features | The updated input features. | Feature Layer |
Code sample
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")
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"]])
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes