In Getting Properties of Next Record Using Calculate Field Tool in ModelBuilder? the OP asks for suggestion on calculation of distances between pairs of points in a feature class.
I thought of alternative solution using field calculator with a very basic logic:
- for first record memorise point geometry from Shape field into global variable pG and return negative distance
- for other records calculate distance between current Shape and one in memory, assign pG = current Shape, return distance.
Expression:
i=0
def FirstOrOthers(shp):
global pG,i
if i==0: i, dist, pG = 1, -1, shp
else: dist, pG=shp.distanceTo(pG),shp
return dist
#------
FirstOrOthers( !Shape! )
Output shown in field DISTANCE:
When I changed expression slightly, to memorise first point of point geometry:
i=0
def FirstOrOthers(shp):
global pG,i
if i==0: i, dist, pG = 1, -1, shp.firstPoint
else: dist, pG=shp.distanceTo(pG),shp.firstPoint
return dist
#------
FirstOrOthers( !Shape! )
It worked as expected:
It means that field calculator refuse to compute distance between 2 point geometries, but does it for point geometry and a point. This is risky, because point does not have spatial reference defined. This is why in scripts I always use 2 point geometries to compute distance between 2 points.
Any thoughts on that odd behaviour of field calculator?
I tested using ArcGIS Desktop 10.3.