2

I am attempting to create a loop to recognize the entry/exit point of a pipe to/from a structure by associating it with a North, South, East, or West direction and then populate the corresponding depth. I presently cannot get the update cursor to work and receiving the error:

Runtime error Traceback (most recent call last): File "", line 144, in AttributeError: 'float' object has no attribute 'updateRow'

Code is listed below: Image of Tables below that.

import arcpy as ARCPY
from arcpy import env as ENV

Functions

def DepthSelection(inputDepth ,  depthDirection):
#From_fieldsStr_DEPTH = ["DEPTH" , "DEPTH_DIRECTION" , "DEPTH_2" , "DEPTH_2_DIRECTION" ,"DEPTH_3" , "DEPTH_3_DIRECTION" ,"DEPTH_4" , "DEPTH_4_DIRECTION"]
#DEPTH DIRECTION: Assocated Direction of Pipe With Specific Depth  
if depthDirection == "NORTH":
    associatedDepth = inputDepth  
    #print "associatedDepth ==" , associatedDepth ,"  depthDirection == NORTH"
elif depthDirection == "SOUTH":
    associatedDepth = inputDepth  
    #print "associatedDepth ==" , associatedDepth ,"  depthDirection == SOUTH"
elif depthDirection == "EAST":
    associatedDepth = inputDepth  
    #print "associatedDepth ==" , associatedDepth ,"  depthDirection == EAST"
elif depthDirection == "WEST":
    associatedDepth = inputDepth  
    #print "associatedDepth ==" , associatedDepth ,"  depthDirection == WEST"

return associatedDepth, depthDirection

Environment

workspaceTEST = r"C:\Users\Jim\Desktop\TESTSTRM_SWR.gdb"
ENV.workspace = workspaceTEST

Variables

str15096 = workspaceTEST + "\STRUCTURES_15096"

pipes15096 = workspaceTEST + "\PIPES_15096"

From_fieldsStr_DEPTH = ["ID"  , "DEPTH" , "DEPTH_DIRECTION" , "DEPTH_2" , "DEPTH_2_DIRECTION" ,"DEPTH_3" , "DEPTH_3_DIRECTION" ,"DEPTH_4" , "DEPTH_4_DIRECTION"]

From_fieldsPipes_DEPTH = ["FROM_POINT"  , "FROM_DEPTH" , "FROM_DEPTH_DIRECTION"]

print "INITIAL PRINT TEST UPDATE: FROM_POINT in PIPES_15096"

DEPTH

depthSearchCursor = ARCPY.da.SearchCursor(str15096, From_fieldsStr_DEPTH)
depthDict = {fromDepthRow[0]:(fromDepthRow[1:]) for fromDepthRow in depthSearchCursor}
depthFromDict = depthDict

with ARCPY.da.UpdateCursor(pipes15096, From_fieldsPipes_DEPTH) as fromUpdateCursor_4Depth:
    for updateFromRow in fromUpdateCursor_4Depth:
        depthKeyMaster = updateFromRow[0]
        print "DEPTH KEY MASTER = " , depthKeyMaster
        if depthKeyMaster in depthFromDict:
            print "DEPTH DESCRIPTION FROM DICTIONARY" , depthFromDict[depthKeyMaster]
            depthDirection1 = depthFromDict[depthKeyMaster][1]
            depthDirection2 = depthFromDict[depthKeyMaster][3]
            depthDirection3 = depthFromDict[depthKeyMaster][5]
            depthDirection4 = depthFromDict[depthKeyMaster][7]
            depth1 = depthFromDict[depthKeyMaster][0]
            depth2 = depthFromDict[depthKeyMaster][2]
            depth3 = depthFromDict[depthKeyMaster][4]
            depth4 = depthFromDict[depthKeyMaster][6]

            #Function Utilization
            associatedDepth1 , depthDirection1 = DepthSelection(depth1 , depthDirection1)
            associatedDepth2 , depthDirection2 = DepthSelection(depth2 , depthDirection2)
            associatedDepth3 , depthDirection3 = DepthSelection(depth3 , depthDirection3)
            associatedDepth4 , depthDirection4 = DepthSelection(depth4 , depthDirection4)            


            print "TESTING THE DEPTH LOOP"                
            print "updateFromRow[2]     ", updateFromRow[2]
            print "associatedDepth2 " , associatedDepth2
            print "associatedDepth3 " , associatedDepth3
            print "associatedDepth4 " , associatedDepth4
            print "associatedDepth1 " , associatedDepth1
            if depthDirection2 == updateFromRow[2]:
                fromUpdateCursor_4Depth[1].updateRow(associatedDepth2)
                print "UPDATE" , associatedDepth2
            elif depthDirection3 == updateFromRow[2]:
                fromUpdateCursor_4Depth[1].updateRow(associatedDepth3)
                print "UPDATE" , associatedDepth3
            elif depthDirection4 == updateFromRow[2]:
                fromUpdateCursor_4Depth[1].updateRow(associatedDepth4)
                print "UPDATE" , associatedDepth4
            else: 
                fromUpdateCursor_4Depth[1].updateRow(associatedDepth1)
                print "UPDATE" , associatedDepth1

Structure Table and Pipe Table

7

You have misunderstood how the updateRow method works. It is a method of the cursor as a whole and takes a row object as its argument:

fromUpdateCursor_4Depth.updateRow(updateFromRow)

You have to assign all of your update variables to the row object to write them to that row. I am not sure how your update fields match up with the variables, but they would look something like:

updateFromRow[1] = associatedDepth2

Note: You should assign all field value changes to the row first and only run updateRow once at the end of the for loop for that row.

  • You're correct sir. I just read through a hand full of update cursor examples and realized that I never reclassified the value of the specific field location: if depthDirection2 == updateFromRow[2]: updateFromRow[1]= associatedDepth2 fromUpdateCursor_4Depth.updateRow(updateFromRow) print "UPDATE" , updateFromRow if depthDirection3 == updateFromRow[2]: updateFromRow[1]= associatedDepth3 fromUpdateCursor_4Depth.updateRow(updateFromRow) print "UPDATE" , updateFromRow – Beau May 2 '16 at 20:29
0
        if depthDirection2 == updateFromRow[2]:
            updateFromRow[1]= associatedDepth2
            fromUpdateCursor_4Depth.updateRow(updateFromRow)
            print "UPDATE" , updateFromRow
        if depthDirection3 == updateFromRow[2]:
            updateFromRow[1]= associatedDepth3
            fromUpdateCursor_4Depth.updateRow(updateFromRow)
            print "UPDATE" , updateFromRow
        if depthDirection4 == updateFromRow[2]:
            updateFromRow[1]= associatedDepth4
            fromUpdateCursor_4Depth.updateRow(updateFromRow)
            print "UPDATE" , updateFromRow
        if depthDirection4 == updateFromRow[2]:  
            updateFromRow[1]= associatedDepth2
            fromUpdateCursor_4Depth.updateRow(updateFromRow)
            print "UPDATE" , updateFromRow
            print "update_DEPTH_Row1:  ", updateFromRow    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.