Runtime error Traceback (most recent call last): File "<string>", line 9, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6195, in ZonalStatisticsAsTable statistics_type) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper result = wrapper(*args, **kwargs) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6187, in Wrapper statistics_type) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Can't build VAT for multiband or floating-point raster dataset Failed to execute (ZonalStatisticsAsTable).
zones = 'HWSDGeolIntersectCopy' landslides = r'USGS\Combined\MitchCatBinary1kmGCS' import arcpy fields = arcpy.ListFields(zones) for field in fields: fieldname = field.name newfieldname = 'Fr_' + fieldname zsum_table = arcpy.sa.ZonalStatisticsAsTable(zones, fieldname, landslides, 'in_memory\zsum_' + zones, 'DATA', 'SUM') arcpy.AddField_management(zsum_table, newfieldname,"DOUBLE") rows = arcpy.UpdateCursor(zsum_table) total_count, total_sum = 0,0 for row in rows: total_count += row.getValue("count") total_sum += row.getValue("sum") rows = arcpy.UpdateCursor(zsum_table) for row in rows: Lcb = row.getValue("sum") Scb = row.getValue("count") Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count) row.setValue(newfieldname, Fr) rows.updateRow(row) arcpy.JoinField_management(zones, fieldname, zsum_table, fieldname, newfieldname) # The following code fixes those polygons not contained in the study area, but present in the output map. # It does so by changing the Fr value to 1. 1 may not be correct, but it is a better representation of # a situation where no data exists than 0. expression = "zero2one(!"+newfieldname+"!)" codeblock = """def zero2one(Fr): if Fr == 0: return 1 else: return Fr""" arcpy.CalculateField_management(zsum_table, newfieldname, expression, "PYTHON_9.3", codeblock) arcpy.PolygonToRaster_conversion(zones, newfieldname[0:10], 'in_memory\\' + newfieldname, 'MAXIMUM_COMBINED_AREA', 'NONE', '0.00833333333333') # clean up del rows arcpy.Delete_management(zsum_table)
Solved! Go to Solution.
for field in fields: # Skip useless fields if field.type == "Geometry": continue fieldname = field.name if "ID" in fieldname: continue # Skip floats for now if field.type == "Double": continue if field.type == "Float": continue
for field in fields: # Skip useless fields if field.type == "Geometry": continue fieldname = field.name if "ID" in fieldname: continue # Skip floats for now if field.type == "Double": continue if field.type == "Float": continue