The following code runs fine minus receiving the error below, which doesn't make any sense (to me) as I have other UpdateCursors and perform UpdateRow(row) with other date values. As can be seen below, there are other instances in which I update a row using a "DATE" value, but for some reason this one is throwing an error. Thanks in advance for any help or comments!
Code that receives error:
# UpdateCursor that will write the time difference calculation to the new Total_Time fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Total_Time")for row in cursor: row[0] = timeDiff cursor.updateRow(row)Entire code:
# import arcpy moduleimport arcpy# Ask user to select the Geodatabase workspace to use for data outputuserWorkspace = arcpy.GetParameterAsText(0)# Set workspace environment based upon user's choicearcpy.env.workspace = userWorkspace# Ask user to select an Oracle dB ConnectionoracleDB = arcpy.GetParameterAsText(1)# Ask user to name the Query LayerqueryLayer = arcpy.GetParameterAsText(2)# Ask user for an SQL Query Expression to be run against the selected Oracle dBsqlQuery = arcpy.GetParameterAsText(3)# Create spatial reference variable to assign to queryLayerspatialRef = arcpy.SpatialReference("W:\Coordinate Systems\WGS 1984.prj")# Process: 'Make Query Layer' - Creates a Query Layer using the user's Oracle dB and SQL query expressionarcpy.MakeQueryLayer_management(oracleDB, "Temp_Layer", sqlQuery, "UNIQUE_ID", "POLYLINE", "1050010", spatialRef)# Process: 'Copy Features' - Copies the temporary Query Layer and stores it as a permanent feature classarcpy.CopyFeatures_management("Temp_Layer", queryLayer)# Process: 'Define Projection' - Defines the projection of queryLayer feature class outputarcpy.DefineProjection_management(queryLayer, spatialRef)# Process: 'Add Field' - Adds new column fields to queryLayerarcpy.AddField_management(queryLayer, "First_Time", "DATE") # The first LOGDT pingarcpy.AddField_management(queryLayer, "Last_Time", "DATE") # The last LOGDT pingarcpy.AddField_management(queryLayer, "Total_Time", "DATE") # Summation of the first to last ping in timearcpy.AddField_management(queryLayer, "Total_Pings", "INTEGER") # Total number of pings (rows)arcpy.AddField_management(queryLayer, "Perfect_Pings", "INTEGER") # Total number of pings possible in given timeframearcpy.AddField_management(queryLayer, "Time_to_Process", "DATE") # How long it took for each ping to process# Calculates the total number of rows for newly added column Total_PingsnumRows = int(arcpy.GetCount_management(queryLayer).getOutput(0))# UpdateCursor that will write the value of numRows to the Total_Pings columncursor = arcpy.da.UpdateCursor(queryLayer, "Total_Pings")for row in cursor: row[0] = numRows cursor.updateRow(row)# SearchCursor that will read the values of LOGDT and return the first value (earliest time)firstLogdt = [row[0] for row in arcpy.da.SearchCursor(queryLayer, "LOGDT")][0]# UpdateCursor that will write the first (earliest time) LOGDT value to the field First_Timecursor = arcpy.da.UpdateCursor(queryLayer, "First_Time")for row in cursor: row[0] = firstLogdt cursor.updateRow(row)# SearchCursor that will read the values of LOGDT and return the last value (latest time)lastLogdt = [row[0] for row in arcpy.da.SearchCursor(queryLayer, "LOGDT")][-1]# UpdateCursor that will write the last (latest time) LOGDT value to the field Last_Timecursor = arcpy.da.UpdateCursor(queryLayer, "Last_Time")for row in cursor: row[0] = lastLogdt cursor.updateRow(row)# Calculates the difference between firstLogdt and lastLogdttimeDiff = lastLogdt - firstLogdt# UpdateCursor that will write the time difference calculation to the new Total_Time fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Total_Time")for row in cursor: row[0] = timeDiff cursor.updateRow(row)# Calculates the total number of pings that would occur if no pings were droppedperfectPings = timeDiff.total_seconds() / 5 # 1 ping every 5 seconds (with good reception)# UpdateCursor that will write the total number of pings possible to the new Perfect_Pings fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Perfect_Pings")for row in cursor: row[0] = perfectPings cursor.updateRow(row)
أكثر...
Code that receives error:
# UpdateCursor that will write the time difference calculation to the new Total_Time fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Total_Time")for row in cursor: row[0] = timeDiff cursor.updateRow(row)Entire code:
# import arcpy moduleimport arcpy# Ask user to select the Geodatabase workspace to use for data outputuserWorkspace = arcpy.GetParameterAsText(0)# Set workspace environment based upon user's choicearcpy.env.workspace = userWorkspace# Ask user to select an Oracle dB ConnectionoracleDB = arcpy.GetParameterAsText(1)# Ask user to name the Query LayerqueryLayer = arcpy.GetParameterAsText(2)# Ask user for an SQL Query Expression to be run against the selected Oracle dBsqlQuery = arcpy.GetParameterAsText(3)# Create spatial reference variable to assign to queryLayerspatialRef = arcpy.SpatialReference("W:\Coordinate Systems\WGS 1984.prj")# Process: 'Make Query Layer' - Creates a Query Layer using the user's Oracle dB and SQL query expressionarcpy.MakeQueryLayer_management(oracleDB, "Temp_Layer", sqlQuery, "UNIQUE_ID", "POLYLINE", "1050010", spatialRef)# Process: 'Copy Features' - Copies the temporary Query Layer and stores it as a permanent feature classarcpy.CopyFeatures_management("Temp_Layer", queryLayer)# Process: 'Define Projection' - Defines the projection of queryLayer feature class outputarcpy.DefineProjection_management(queryLayer, spatialRef)# Process: 'Add Field' - Adds new column fields to queryLayerarcpy.AddField_management(queryLayer, "First_Time", "DATE") # The first LOGDT pingarcpy.AddField_management(queryLayer, "Last_Time", "DATE") # The last LOGDT pingarcpy.AddField_management(queryLayer, "Total_Time", "DATE") # Summation of the first to last ping in timearcpy.AddField_management(queryLayer, "Total_Pings", "INTEGER") # Total number of pings (rows)arcpy.AddField_management(queryLayer, "Perfect_Pings", "INTEGER") # Total number of pings possible in given timeframearcpy.AddField_management(queryLayer, "Time_to_Process", "DATE") # How long it took for each ping to process# Calculates the total number of rows for newly added column Total_PingsnumRows = int(arcpy.GetCount_management(queryLayer).getOutput(0))# UpdateCursor that will write the value of numRows to the Total_Pings columncursor = arcpy.da.UpdateCursor(queryLayer, "Total_Pings")for row in cursor: row[0] = numRows cursor.updateRow(row)# SearchCursor that will read the values of LOGDT and return the first value (earliest time)firstLogdt = [row[0] for row in arcpy.da.SearchCursor(queryLayer, "LOGDT")][0]# UpdateCursor that will write the first (earliest time) LOGDT value to the field First_Timecursor = arcpy.da.UpdateCursor(queryLayer, "First_Time")for row in cursor: row[0] = firstLogdt cursor.updateRow(row)# SearchCursor that will read the values of LOGDT and return the last value (latest time)lastLogdt = [row[0] for row in arcpy.da.SearchCursor(queryLayer, "LOGDT")][-1]# UpdateCursor that will write the last (latest time) LOGDT value to the field Last_Timecursor = arcpy.da.UpdateCursor(queryLayer, "Last_Time")for row in cursor: row[0] = lastLogdt cursor.updateRow(row)# Calculates the difference between firstLogdt and lastLogdttimeDiff = lastLogdt - firstLogdt# UpdateCursor that will write the time difference calculation to the new Total_Time fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Total_Time")for row in cursor: row[0] = timeDiff cursor.updateRow(row)# Calculates the total number of pings that would occur if no pings were droppedperfectPings = timeDiff.total_seconds() / 5 # 1 ping every 5 seconds (with good reception)# UpdateCursor that will write the total number of pings possible to the new Perfect_Pings fieldcursor = arcpy.da.UpdateCursor(queryLayer, "Perfect_Pings")for row in cursor: row[0] = perfectPings cursor.updateRow(row)
أكثر...