3

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?

3
  • 2
    Field Calculator only supports VBScript and Python, not VBA. If Esri has an example in python, you can use that with the Field Calculator.
    – evv_gis
    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?
    – evv_gis
    Jun 4, 2015 at 21:01

1 Answer 1

5

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.

2
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.