# Calculating Sinuosity Using ArcGIS Field Calculator

Trying to calculate sinuosity via Field Calculator (ArcGIS v 10.2.2); VBA

Pre-Logic Script Code:

``````Dim dblLe as double
Dim dblLf as double
Dim dblS as double
Dim pCurve as Icurve
Dim pFPoint as IPoint
Dim pTPoint as IPoint
Set pCurve = [Shape]
Set pFPoint = pCurve.FromPoint
Set pTPoint = pCurve.ToPoint
dblLe = Sqr((pFPoint.X - pTPoint.X)^2 + (pFPoint.Y - pTPoint.Y)^2)
dblLf  = pCurve.Length
dblS = dblLe/dblLf
``````

Variable =

``````dblS
``````

I know ESRI has a python script put I am try to run via Field Calculator. Anyone see my error?

• Field Calculator only supports VBScript and Python, not VBA. If Esri has an example in python, you can use that with the Field Calculator. Jun 4, 2015 at 20:58
• I'll give that a try.
– Jeff
Jun 4, 2015 at 21:00
• If you have the link to the sample, could you post it? Jun 4, 2015 at 21:01

If done in Python:

Expression parameter:

``````getSinuosity(!shape!)
``````

Codeblock parameter:

``````import math
def getSinuosity(shape):
length = shape.length
d = math.sqrt((shape.firstPoint.X - shape.lastPoint.X) ** 2 +
(shape.firstPoint.Y - shape.lastPoint.Y) ** 2)
return d / length
``````

Make sure to use an expression type of `PYTHON_9.3`.

Also take a look at this tool here. I wrote this a couple of years ago as part of a demo. Under the hood, it's using CalculateField like I've described above.

• Perfect...... I was missing the"!" in "getSinuosity(!shape!)"
– Jeff
Jun 4, 2015 at 21:46
• Lately I've started to receiving the following error .... ERROR 000539: Runtime error SyntaxError: encoding declaration in Unicode string (<string>, line 0) ...... any ideas
– Jeff
Oct 8, 2015 at 18:15