I am trying to calculate a field for some points within a python script using arcpy functions. (This is calculating the percentage visibility from a cumulative viewshed, if that matters.)
# Process: Get Count
TotalFlightPoints = int(arcpy.GetCount_management(FlightPath_Pts).getOutput(0))
# Process: Add Field
Obsv_Vis = arcpy.AddField_management(Obsv_Vis, "PercentVis", "FLOAT")
# Process: Calculate Field (2)
Obsv_Vis = arcpy.CalculateField_management(Obsv_Vis, "PercentVis", "!RASTERVALU! / " + str(TotalFlightPoints), "PYTHON", "")
Even though I cast that field as a FLOAT when adding it, the result is consistently an integer (0 if less than 1, 1 if the point is 100% visible). I can get around this by "!RASTERVALU! * 100 / " + str(TotalFlightPoints)
, which will at least give me the percentage (without any trailing decimals). That level of accuracy may be sufficient for this application, at least for now.
But, if I use the Field Calculator within ArcMap on a "float" field (with, say, !RASTERVALU! / 121
as the equation), it gives me the result as a float. So I'm wondering why the field calculator seems to work differently in different situations, and/or what I can tweak to get what I really want.
12/2 = 6
, but12./2. = 6.0
– Jason Mar 28 at 15:22