1

I am using ArcGIS Desktop 10.4.

I am trying to iterate a process through a Feature Class to calculate individual (and unique) values in a particular field. I can calculate the field just fine, but it ends up recalculating the new unique value for all of the features in the feature class instead of each individual row. I cannot convert to feature layer or layer file because I need to add the data to the current Feature Classes without adding more Feature Class to that geodatabase. (I am already iterating it through 231 Feature Classes and do not need more...) I have tried Search Cursor already, and could not find any other code because arcpy.IterateFeatureSelection() is meant for model builder and not python. I was expecting my update cursor in "fc_update in fc_updates" would provide that service, but it did not. Otherwise it prints and defines the data exactly how I intent to use it.

I left out the rest of my code as it is not pertinent to the part that needs to select the data.

My code is below:

fc_updates = gp.UpdateCursor(fc)

for fc in fcs:
    if fc.startswith("GP_"):
        print "Start Feature Class at: " + str(datetime.datetime.now().time().strftime('%H:%M:%S'))
        print "Feature Class: " + fc
        #arcpy.AddField_management(fc, field_name,"Short")

        for fc_update in fc_updates:
            obj_id = str(fc_update.OBJECTID)
            flt_desig = str(fc_update.flt_line)
            imag_start = str(fc_update.Start_Imag)
            imag_end = str(fc_update.End_Imag)
            n = n + 1
            print "-"*30
            print "Attribute Information . . ."
            print "image start = " + str(imag_start)
            print "image end = " + str(imag_end)
            imag_entry = (str(imag_start) + "," + str(imag_end)).split(",")
            print "image entry = " + str(imag_entry)
            start = int(imag_entry[0])
            end = int(imag_entry[1])
            express1 = start-n
            express2 = start+n
            print (str(flt_desig), str(imag_start), str(imag_end))
            print "-"*30
  • I would use a SearchCursor first and save the calculations,objectid,etc in a dictionary, then use a separate UpdateCursor to apply the calculations. – klewis Aug 25 '17 at 14:49
  • @klewis - I am trying your method at the moment. – Smithw1 Aug 25 '17 at 18:16
  • Using Update Cursor looks like the way to go, but it keeps getting hung up when I use arcpy.da.UpdateCursor(). I get the "terminated by the remote host" error. I tried to use arcpy.UpdateCursor() and gp.UpdateCursor(), but when it gets to the UpdateRow part it does not work. fc_scs = gp.UpdateCursor(fc) with arcpy.UpdateCursor(fc) as fc_sc: fc_scs = arcpy.da.UpdateCursor(fc, ['OBJECTID', field_name) This last one gets hung up and crashes every time. – Smithw1 Aug 29 '17 at 14:31
  • You can add your new code to the window above. – klewis Aug 29 '17 at 14:37

Your Answer

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

Browse other questions tagged or ask your own question.