I have 2 layers, one with land plots and one with hazard zones. I want to iterate through the layer with land plots and for every plot I want to add 2 (or 3, depending on some variables) fields. Then I calculate the data for these fields, based on the attribute values of the overlapping hazard zone, and fill it in, in the new fields. I'm trying to do this by using the searchcursor to iterate through the plots and get their geometry (I need the geometry to decide if they overlap, touch, intersect etc. with the hazard zone, which affects the calculated data for the new fields).
Next to all this I try to create an updatecursor and loop through both cursors at the same time using zip(), to update the newly created empty fields immidiately after calculating their proper value.
I'm trying to do this in 1 for loop to save time by only iterating the plots once. But the UpdateCursor doesn't work properly. The 2 new fields are Null for all plots except the last plot, that one has the proper values.
Any clues to what is happening here?
I have printed the variables which should be added and they are not Null.
Start of the loop:
fields_og = arcpy.ListFields(outLayer) fields = ['SHAPE@'] for field in fields_og: fields.append(field.name) with arcpy.da.SearchCursor(outLayer, fields) as features: if atype == 'SHORT': arcpy.AddField_management(outLayer, attrn, atype, 10, 0) elif atype == 'DOUBLE': arcpy.AddField_management(outLayer, attrn, atype, 10, 2) else: arcpy.AddField_management(outLayer, attrn, atype) attrn_s = attrn + "_s" minmax_s = attrn + "_mm" arcpy.AddField_management(outLayer, attrn_s, 'TEXT') out_fields = [attrn, attrn_s] minmax = False if len(a_minmaxfield) > 0: arcpy.AddField_management(outLayer, minmax_s, 'TEXT') minmax = True out_fields.append(minmax_s) with arcpy.da.UpdateCursor(outLayer, out_fields) as cursor: for feature, row in zip(features, cursor):
After some calculations etc. I want to update like this:
if minmax: attrs.append(c) if minmax: row[-3] = val2add row[-2] = b row[-1] = c else: row[-2] = val2add row[-1] = b cursor.updateRow(row)