Tom,
The zip file appears to be corrupt, but I've figured it out with my own data.
When I first took a look at your sample code you were adding an integer field to the raster attr table and then performing interger division ... but what you actually want to do is "true division".
Python, like C, performs "floor" division by default. No remainders are returned when using integers so for your workflow, with the code and data you were using, the field will always be calced to 0.
So, first change the field you create to something that will accept floats (I used DOUBLE).
And then you have two options:
1. Use '/' with floats.
2. Use a code block that switches python from "floor" division to "true" division.
Find attached the new script I put together using a code block.
Summary of changes:
Defined a variable, EXPRESSION, containing the code block:
EXPRESSION = '''
from __future__ import division
def realDiv(fld,val):
return fld / val
'''
Add field as DOUBLE, not LONG:
#gp.addfield (raster, "PROPORTION", "LONG", "")
gp.addfield (raster, "PROPORTION", "DOUBLE", "")
Use the code block in calculatefield:
#gp.calculatefield(raster,"PROPORTION","!COUNT! / " + str(x),"PYTHON")
gp.calculatefield(raster,"PROPORTION","realDiv(!COUNT!,x)","PYTHON_9.3",EXPRESSION)
Please let me know how it goes.
Ken