AnsweredAssumed Answered

Any tips on making this process faster?

Question asked by zaloudek on Nov 6, 2012
Latest reply on Nov 28, 2012 by rzufelt
Here's what I'm doing - I have a polygon feature class of census blocks with populations.  I have split these census blocks based on watershed boundaries (side, note, many of the blocks fall completely within a watershed and were not split).  Now... each piece of each block that was split up still has the total population for that block attributed to it.  I'm trying to figure out an estimate of the population for each piece of each block.  For each piece of each block, I'm calculating the percent of a block's total area that piece is, and finally applying that percent-of-area to the block's total population.

I am running this for an entire state.  By my estimate, if the script takes 16 seconds to calculate each census block, it will take nearly 84 days to run...  That's no good.

I know there are a lot of cursors running, but I can't think of a better way to do this off the top of my head.  The cursor(s) should be looking at a table view, which normally has only 1 - 3 records.

'blockids' is a list with each unique BLOCKID. "finalblocks" is the variable standing for my census blocks feature class.

blockcounter = 1 for blockid in blockids:     # Make Table View of all polygons with this blockid     block_view = 'block_view' + blockid     wclause = '"BLOCKID10" = \'' + blockid + "'"     arcpy.MakeTableView_management (finalblocks, block_view, wclause)     bcount = arcpy.GetCount_management(block_view)     print str(bcount) + ' block pieces for ' + blockid + '... ' + str(blockcounter) + ' of ' + str(len(blockids))     rows = arcpy.UpdateCursor(block_view)     for row in rows:         blockpop = str(row.POP10)     if blockpop <> '0':         if str(bcount) <> '1':             # If this block ID has multiple pieces and total population is not 0             totalarea = 0.0             totalpop = 0.0             for row in rows:                 totalarea += row.Shape_Area             for row in rows:                 thisarea = row.Shape_Area                 pctarea = thisarea / totalarea                 totalpop = row.POP10                 thispop = totalpop * pctarea                 row.POP10_est = thispop                 rows.updateRow(row)         else:             # If there is only one polygon for this block ID             for row in rows:                 row.POP10_est = row.POP10                 rows.updateRow(row)     else:         # If the total population of this block is 0 anyway         for row in rows:             row.POP10_est = 0             rows.updateRow(row)     del rows, row     blockcounter += 1



Thank you in advance for any help!

Outcomes