Hi
I wish to calculate the distance between consecutive points in a feature class.
I tried using the following code in the "Pre-Logic VBA Script Code" box in the Field Calculator dialog -
static x0 as double, y0 as double ' Previous location
dim pPoint as IPoint
set pPoint = [Shape]
x = pPoint.X
y = pPoint.Y
d = sqr((x - x0)^2 + (y - y0)^2) ' Distance
x0 = x
y0 = y
but it doesn't work. Does anyone have any suggestions? Thanks for any help anyone can give me.
I wish to calculate the distance between consecutive points in a feature class.
I tried using the following code in the "Pre-Logic VBA Script Code" box in the Field Calculator dialog -
static x0 as double, y0 as double ' Previous location
dim pPoint as IPoint
set pPoint = [Shape]
x = pPoint.X
y = pPoint.Y
d = sqr((x - x0)^2 + (y - y0)^2) ' Distance
x0 = x
y0 = y
but it doesn't work. Does anyone have any suggestions? Thanks for any help anyone can give me.
VB Script at 10.0 or later cannot use the DIM statement to create Point variables anymore (or any other variable type other than Variant). You have to use Python for all geometry field calculations from now on.
Here is my attempt based on an adaptation of the autoincrement calculation.
Parser: Python
Use Codeblock: checked
Pre-Logic Script Codeblock:
Expression: distance(!shape.Centroid.X!, !shape.Centroid.Y!)
I am assuming the first point should give a distance of 0, so I set an invalid coordinate that I know will not be in your data and replace that impossible value with the first point value. If 0,0 is a possible coordinate change the initial x0 and y0 values outside the def to a known invalid point location and change the if condition to match it.