I hope my question is not redundant.
I wrote a script to Update a table using two imbricate cursors. The goal was 1) to read a records, update some of its values 2) Make a selection based on this record (e.g. closest neighbors) 3) Update the neighbors
I have first tried using two imbricate update cursors like the following:
rows = gp.UpdateCursor(Infile)
row = rows.Next()
while row:
# Read InFile attribute
val = row.GetValue(Attribute)
# Update some attributes
val = row.SetValue(Field, function(val))
# Select Neighbors
gp. gp.GANeighborhoodSelection(Infile, Layer, Condition related to val)
//.....//
# Update Neighbors
urows = gp.UpdateCursor(Infile)
urow = urows.Next()
while urow:
# Update some attributes
val = urow.SetValue(Field, function(val))
urows.UpdateRow(urow)
urow = urows.Next()
del urow, urows
//.....//
row.UpdateRow(row)
row = rows.Next()
//.....//
Using such a code, the second update cursor was calculating correctly (i printed some intermediate results) but the calculation was not applied to the table (ie. not physical updation).
I modified the code by replacing the second update cursor by a Select by attributes followed by a calculate field. Again, the calculations were not applied to the table. I think there is a lock problem somewhere but I did not found how to solve the problem.
Finally, I replaced my first UpdateCursor by a SearchCursor and then used an UpdateCursor based on a condition in order to reduce the number of record processed. The code look like this:
rows = gp.SearchCursor(Infile)
row = rows.Next()
while row:
# Read InFile attribute
val = row.GetValue(Attribute)
# Update some attributes
val = row.SetValue(Field, function(val))
# Select Neighbors
gp. gp.GANeighborhoodSelection(Infile, Layer, Condition related to val)
//.....//
# Update Neighbors
urows = gp.UpdateCursor(Infile, Condition based on val)
urow = urows.Next()
while urow:
# Update some attributes
val = urow.SetValue(Field, function(val))
urows.UpdateRow(urow)
urow = urows.Next()
del urow, urows
//.....//
row.UpdateRow(row)
row = rows.Next()
//.....//
Using such a structure, all is working fine. However, calculation is longer (around 5 sec. for 1000 records).
Do you have any idea 1) why using 2 imbricate UpdateCursor is not working and 2) how to use select by attributes and calculate field within a cursor to fasten the calculation?
Thanks a lot
Cedric

