# Common Python geometry calculations in the Field Calculator

Discussion created by wwaters on Feb 17, 2011
Latest reply on Nov 9, 2014 by GSCUser85
Branched to a new discussion
Here it has Common VBA geometry calculations in the Field Calculator, provide as a number of code blocks. I have pasted these below and am wondering if someone can make a set of equivalent code blocks in Python, or can point me where someone has already made them?

Common VBA geometry calculations in the Field Calculator
Below are some code samples you can use to perform geometric calculations with VBA statements, rather than having the Calculate Geometry command do them for you.
To use the samples, open the Field Calculator, check Advanced, and type the VBA statement in the first text box. Then, type the variable name in the text box directly under the field name.

Area

Dim dblArea as double
Dim pArea as IArea
Set pArea = [shape]
dblArea = pArea.area

Perimeter

Dim dblPerimeter as double
Dim pCurve as ICurve
Set pCurve = [shape]
dblPerimeter = pCurve.Length

Length

Dim dblLength as double
Dim pCurve as ICurve
Set pCurve = [shape]
dblLength = pCurve.Length

X-coordinate of a point

Dim dblX As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
dblX = pPoint.X

Y-coordinate of a point

Dim dblY As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
dblY = pPoint.Y

X-coordinate of a polygon centroid

Dim dblX As Double
Dim pArea As IArea
Set pArea = [Shape]
dblX = pArea.Centroid.X

Y-coordinate of a polygon centroid

Dim dblY As Double
Dim pArea As IArea
Set pArea = [Shape]
dblY = pArea.Centroid.Y

To add the z-value of the start point of a polyline

Dim dblZ As Double
Dim pLine As IPolyline
Dim pPoint as IPoint
Set pLine = [Shape]
Set pPoint = pLine.FromPoint
dblZ= pPoint.Z