Hello,
I have a column for elevation for a point data set. I would like to create a new column to show a difference between Row(n) and Row(n+1) values. well, I assume that the easiest way is calculating in EXCEL (=abs(A1-A2)) then make a join at ArcGIS. However, I would like to the process with "Field calculator" Does anyone know how to do it?
Thanks in advance
Solved! Go to Solution.
abs([field 1] - [field 2])
Hi Robert.
Value comparison in a SINGLE column.
NOT comparing field 1 and field 2.
Learn GIS ... some python?
Could make this into a script or copy and paste into the python window or your python IDE
# ----
# (1) specify the table you want to use, with the OBJECTID field and
# the field you want to get sequential differences for
# (2) convert the table to a numpy array... there is some magic in that we
# 'view' the data as double type (see the vals = line)
# (3) perform the difference, diff, by offsetting and slicing the input values)
# (4) create an output array to put the values in
# (5) 'join' permanently the result (out) to the input using the ExtendTable func
#
# ---- example below was a quick test to calculate sequential difference in 'Xs'
flds = ['OBJECTID', 'Xs']
pth = r"C:\Your_spaceless_path\Your.gdb\Your_table"
tbl = arcpy.da.TableToNumPyArray(pth, flds)
vals = tbl['Xs'].view(np.float64)
#
diff = vals[1:] - vals[:-1] # ---- changeup the function ----
#
out = np.zeros((tbl.shape[0],), dtype=[('IDs', '<i4'), ('Seq_Diff', '<f8')])
out['IDs'] = tbl['OBJECTID']
out['Seq_Diff'][1:] = diff
arcpy.da.ExtendTable(pth, 'OBJECTID', out, 'IDs')
# ---- Seems like overkill? nope... I just stole the code from a pre-existing
# snippet, changed the filename, the field of interest and my amazing math function
Obviously study material, but give it a try sometime.
Added to Table Tools for PRO
as a field calculator sequence function
Thanks, Dan,
I really appreciate it