def main(): import arcpy # assume data is available as point featureclass # and fc has projected coordinate system fc = "c:/folder/yourGeodatabase.gdb/yourFCname" # change this (path to featureclass GPS points) fldDistance = "DistGPSpoints" # change this (output name distance field) # add distance field if it doesn't exist if FieldExist(fc,fldDistance) == False: arcpy.AddField_management(fc, fldDistance, "DOUBLE") # Create update cursor for feature class fields = ['SHAPE@XY', fldDistance] with arcpy.da.UpdateCursor(fc, fields) as cursor: X = 0 Y = 0 cnt = 0 for row in cursor: cnt+=1 prevX = X prevY = Y X = row[0][0] Y = row[0][1] if cnt == 1: # for first point distance is 0 distance = 0 else: distance = getDist(X,Y,prevX,prevY) # Update row row[1] = distance cursor.updateRow(row) del row def getDist(X1,Y1,X2,Y2): import math return math.hypot(X2 - X1, Y2 - Y1) def FieldExist(featureclass, fieldname): import arcpy fieldList = arcpy.ListFields(featureclass, fieldname) fieldCount = len(fieldList) if (fieldCount == 1): return True else: return False if __name__ == '__main__': main()
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.