Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Update Cursor with Date Issue [closed]

$
0
0

My dates (maxDate, minDate, avgDate) all print out with the correct datetime format, but I am unsure if the problem is how the loop is written to update the cursor.

Error:

line 102, in updateRow
return convertArcObjectToPythonObject(self._arc_object.UpdateRow(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.

Code:

arcpy.env.workspace =  r"C:ForChriswetMatchsSBA_wetlandTR_intSBA.gdb"
fcs = arcpy.ListFeatureClasses()
years = []
yearsJD = []
for fc in fcs:
    arcpy.AddField_management(fc, "Max_Year", "Date")
    arcpy.AddField_management(fc, "Min_Year", "Date")
    arcpy.AddField_management(fc, "Avg_Year", "Date")

    cursor = arcpy.SearchCursor(fc)
    for row in cursor:
        fDate = row.getValue("Final_Date")
        a = (14 - fDate.month)//12 ## Julian date calc
        y = fDate.year + 4800 - a
        m = fDate.month + 12*a - 3
        JD = fDate.day + ((153*m + 2)//5) + 365*y + y//4 - y//100 + y//400 - 32045
        yearsJD.append(JD)
        years.append(fDate) 
    averageJD = sum(yearsJD) / len(yearsJD) ## calculates average julian date
    az = averageJD + 32044 ## convert julian date to calendar date
    b = (4*az + 3)//146097
    c = az - (146097*b)//4
    d = (4*c + 3)//1461
    e = c - (1461*d)//4
    n = (5*e + 2)//153    
    aday = e + 1 - (153*n + 2)//5
    amonth = n + 3 - 12*(n//10)
    ayear = 100*b + d - 4800 + n/10
    avgDate = datetime.datetime(ayear, amonth, aday)
    minDate = numpy.min(years)
    maxDate = numpy.max(years)

    cursor2 = arcpy.UpdateCursor(fc)
    for row2 in cursor2:
        row2.setValue("Max_Year", maxDate)
        row2.setValue("Min_Year", minDate)
        row2.setValue("Avg_Year", avgDate)
        cursor.updateRow(row2)
    del years[0:len(years)] ### Empties List
    del yearsJD[0:len(yearsJD)]

Viewing all articles
Browse latest Browse all 767

Trending Articles