AnsweredAssumed Answered

ERROR 999998 - tabulate area tool in Python script

Question asked by mmooreWPC on Dec 13, 2017
Latest reply on Dec 20, 2017 by mmooreWPC

I have a Python script that I would like to operate as a standalone script. When I copy and paste it into the Python window in a fresh ArcMap .mxd, it operates fine. However, when I attempt to run it as a standalone script within my Python IDE, it fails during the tabulate area tool that is written like this:


     tab_area = TabulateArea(target_features,"unique_id",sdm,"Value",os.path.join(outTable,"tab_area_temp"),"30")


I am getting the ambiguous 999998 error message:


    ExecuteError: ERROR 999998: Unexpected Error.


Does anyone have any ideas as to why this might be working fine when copied and pasted into the Python window in ArcMap, but failing as a standalone script?


Full Python script is below for reference:


import arcpy, os, datetime
from arcpy import env
from import *
from itertools import groupby
from operator import itemgetter

print "start time: " +"%Y-%m-%d %H:%M:%S")

arcpy.env.overwriteOutput = True

target_features = r'C:\Users\mmoore\Documents\ArcGIS\COA.gdb\PlanningUnit_Hex10acre'
sdm_folder = r'C:\Users\mmoore\Documents\ArcGIS\SDMs.gdb'
outTable = r'C:\Users\mmoore\Documents\ArcGIS\out_tables.gdb'
arcpy.env.workspace = sdm_folder
sdms = arcpy.ListRasters()

species_tables = []

for sdm in sdms:
    print sdm + " started at: " +"%Y-%m-%d %H:%M:%S")
    sdm_path = os.path.join(sdm_folder,sdm)
    tab_area = TabulateArea(target_features,"unique_id",sdm,"Value",os.path.join(outTable,"tab_area_temp"),"30")
    sdm_table = arcpy.TransposeFields_management(tab_area,"VALUE_1 Low;VALUE_2 Medium",os.path.join(outTable,sdm),"OccProb","PERCENTAGE","unique_id")
    with arcpy.da.UpdateCursor(sdm_table,["OccProb","PERCENTAGE","ElSeason"]) as cursor:
        for row in cursor:
            row[1] = (int(row[1])/40468.383184)*100
            row[2] = sdm
            if row[0] == "VALUE_1":
                row[0] = "Low"
            elif row[0] == "VALUE_2":
                row[0] = "Medium"

    with arcpy.da.UpdateCursor(sdm_table, "PERCENTAGE") as cursor:
        for row in cursor:
            if row[0] > 10:

    case_fields = ["unique_id", "ElSeason"]
    max_field = "PERCENTAGE"
    sql_orderby = "ORDER BY {}, {} DESC".format(",".join(case_fields), max_field)

    # use groupby cursor to order by percent coverage
    with arcpy.da.UpdateCursor(sdm_table, "*", sql_clause=(None, sql_orderby)) as cursor:
        case_func = itemgetter(*(cursor.fields.index(fld) for fld in case_fields))
        for key, group in groupby(cursor, case_func):
            for extra in group:

    print sdm + " finished at: " +"%Y-%m-%d %H:%M:%S")

merge = arcpy.Merge_management(species_tables, os.path.join(outTable, "SGCN_SDMxPU"))
print "end time: " +"%Y-%m-%d %H:%M:%S")


The full error message is as follows:

Traceback (most recent call last):
  File "H:\Scripts\COA\COA\COA_species_populator", line 23, in <module>
    tab_area = TabulateArea(target_features,"unique_id",sdm,"Value",os.path.join(outTable,"tab_area_temp"),30)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\", line 6183, in TabulateArea
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\", line 6175, in Wrapper
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\geoprocessing\", line 510, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999998: Unexpected Error.
Failed to execute (TabulateArea).