AnsweredAssumed Answered

While inside of For - question.

Question asked by armein01 on Oct 16, 2013
Latest reply on Oct 18, 2013 by armein01
I am afraid to run my loop because I dont know how to exit if it hangs.
I dont believe I need the next function because the for is iterated already.
Also not sure if Ive used identation and return correctly.
Please help with any comments or additions I should make.
Thanks,
Alicia
 #Set environment and declare varibles # arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:/CustomTools/DeerSurveyRoutes/rtsScratch.gdb" arcpy.env.cellSize = rasPath  coPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/County" rasPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass" opnFrstdRas = arcpy.Raster("C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass") rasCellSz = (opnFrstdRas.meanCellHeight + opnFrstdRas.meanCellWidth) / 2 rtsPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/SmplRts2012Edited4CountyAnalysis" #Tabulate Forested/Open for county # arcpy.CheckOutExtension("Spatial") arcpy.env.snapRaster = rasPath znFld = "CoZoneName" clsFld = "Value" outTble = "CoTbleOpenFrst"  arcpy.sa.TabulateArea(coPath,znFld,opnFrstdRas,clsFld,outTble,rasCellSz)  #Create Cursor to iterate through rts and dictionary to hold county forested/open value # updtCur = arcpy.UpdateCursor(rtsPath)  coOFDict = dict([((r.COZONENAME, f.name),r.getValue(f.name)) for f in arcpy.ListFields(outTble) for r in arcpy.SearchCursor(outTble)]) del f, r  #Loop to find buffer distance of each route that will contain the same forested percent as the county  return BuffDist # for row in updtCur:     buffDist = 402   #This will be meters as all my inputs are projected to UTM     frstPrcnt = 0     frstd = coOFDict[(row.getValue(znFld),'VALUE_2')]     opn = coOFDict[(row.getValue(znFld),'VALUE_1')]     nHbt = coOFDict[(row.getValue(znFld),'VALUE_0')]     lpChkVal = frstd / (frstd + opn + nHbt)     minLpChkVal = lpChkVal - (lpChkVal * .05)     maxLpChkVal = lpChkVal + (lpChkVal * .05)     newBuffVal = buffDist     x = 0      while frstdPrcnt < minLpChkVal or frstdPrcnt > maxLpChkVal:         thisFID = row.getValue('FID')         arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", "[FID]" = "thisFID")         arcpy.Buffer_analysis("selectedLine","lineBuffer",buffDist,"FULL","FLAT",,"RouteID")         arcpy.sa.TabulateArea("lineBuffer","RouteID",rasPath,clsFld,"BufferOFTble",rasCellSz)         rtOFDict = dict([((r.ROUTEID, f.name),r.getValue(f.name)) for f in arcpy.ListFields("BufferOFTble") for r in arcpy.SearchCursor("BufferOFTable")])         del f, r          rtFrstd = rtOFDict[(row.getValue('RouteID'),'VALUE_2')]         rtOpn = rtOFDict[(row.getValue('RouteID'),'VALUE_1')]         rtNHbt = rtOFDict[(row.getValue('RouteID'),'VALUE_0')]         frstPrcnt = rtFrstd / (rtFrstd + rtOpn + rtNHbt)         newBuffVal = buffDist         x += 1         buffDist = buffDist + (x * 5 * rasCellSz)     return newBuffVal     row.setValue('BuffDist',newBuffVal)     updtCur.updateRow(row) del row, updtCur                

Outcomes