dharla2

Trying to calculate fields from paired points in a shapefile

Discussion created by dharla2 on Nov 10, 2011
Latest reply on Nov 23, 2011 by dharla2
I have pairs of points that share a common id "COMID".  I would like to calculate an empty field with an equation that uses values from both points in the pair.  I am trying to use UpdateCursor and a for loop and then accessing the next row with row.next() but I don't think this is right.  What I want to say is-  for each row: if id1 = id2 then perform this calculation with values from row1 and row 2.
Anyway here is what I have and it does not work.
upcur = gp.UpdateCursor(sin_pt)
for row in upcur:
        id1 = row.COMID
        id2 = row.next().COMID
        if id1 == id2:
            yval1 = row.NORTH
            yval2 = row.next().NORTH
            xval1 = row.EAST
            xval2 = row.next().EAST
            distval = math.sqrt(((xval1 - xval2)**2) + ((yval1-yval2)**2))
            length = row.LENGTHKM * 1000
            row.DIST = length / distval
            upcur.updateRow(row)

#No error messages but the field is still empty
#thanks

Outcomes