I get this error when attempting to automate my geoprocessing in the console:
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).
The first output raster is created correctly, but it never gets to the 2nd.
I thought my problem might be related to the in-memory files, but that is not the case. Replacing both of the in_memory\\ locations with a disk location gives exactly the same error. Maybe I need to delete something from memory at the end of the for loop, but it's not clear what.
Here is my code:
Quote:
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).
I thought my problem might be related to the in-memory files, but that is not the case. Replacing both of the in_memory\\ locations with a disk location gives exactly the same error. Maybe I need to delete something from memory at the end of the for loop, but it's not clear what.
Here is my code:
Code:
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)