mtdave

ERROR: "The table was not found. [VAT_CostDis_src_1]" ? X-Posted SA

Discussion created by mtdave on Feb 22, 2013
Latest reply on Sep 25, 2013 by kingmi
I have written a Python GeoProcessing task for running Cost Distance and Cost Path analysis. It runs sometimes and errors other times. This is the error that it normally returns when trying to run the arcpy.sa.CostDistance() method:

ERROR 999999: Error executing function.
The table was not found. [VAT_CostDis_src_1]
The table name is invalid.
No spatial reference exists.
The operation was attempted on an empty geometry.
ERROR 010029: Unable to create the raster E:\WorkingFiles\ProjectFolders\LRT\Development\Test10\Scratch_hvil26w5.gdb\45a2i1023_b. Cost Distance mapping Failed
ERROR 010067: Error in executing grid expression.


Both the source point raster and the cost raster have a VAT. I rebuild the VATs in the script prior to running the tool.

Any idea why this is occurring? It is weird that it is intermittent. It seems like it will run once and then not a second time, if that is a clue.

Thanks, Dave

Here is the meat of the script:
        #get the Source Points feature class
        pntfc = gdb + "\\WAYPOINTS"
        if not arcpy.Exists(pntfc):
            raise Exception("Did not find the SOURCE Points feature class")

        #Get the source grid
        suitgrid = getSuitGrid(gdb, suitid)
        if suitgrid["code"] == "None":
            raise Exception("Did not find the Suitability Grid name")

        #get the Suitability grid
        srcsg = gdb + "\\" + suitgrid["code"]
        if not arcpy.Exists(srcsg):
            raise Exception("Did not find the Suitability grid")

        #query the source Ids and make a layer
        arcpy.AddMessage("Query Waypoints")
        srcqry = "PNTID = " + str(srcid)
        pntlaynm = "waypnts"
        if arcpy.Exists(pntlaynm):
            arcpy.Delete_management(pntlaynm)
        arcpy.MakeFeatureLayer_management(pntfc, pntlaynm)
        arcpy.SelectLayerByAttribute_management(pntlaynm, "NEW_SELECTION", srcqry)
        costCnt = int(arcpy.GetCount_management(pntlaynm).getOutput(0))
        if costCnt < 1:
            raise Exception("No Source points found for those Ids")

        #copy to scratch
        srcfc = scrws + "\\src_pnt"
        arcpy.CopyFeatures_management(pntlaynm, srcfc)
        arcpy.AddField_management(srcfc, "VAL", "LONG")
        arcpy.CalculateField_management(srcfc, "VAL", 0, "PYTHON_9.3")

        #select and copy out destination
        destqry = "PNTID = " + str(destid)
        arcpy.SelectLayerByAttribute_management(pntlaynm, "NEW_SELECTION", destqry)

        #copy to scratch
        destfc = scrws + "\\dest_pnt"
        arcpy.CopyFeatures_management(pntlaynm, destfc)
        arcpy.AddField_management(destfc, "VAL", "LONG")
        arcpy.CalculateField_management(destfc, "VAL", 0, "PYTHON_9.3")
        writeToLog("Copied Destination Point: " + destfc)

        #set the raster geoprocessing environment
        outsr = arcpy.SpatialReference(suitgrid["srfc"])
        env.outputCoordinateSystem = outsr
        env.extent = arcpy.Extent(suitgrid["xmin"], suitgrid["ymin"], suitgrid["xmax"], suitgrid["ymax"])
        env.cellSize = suitgrid["res"]

        #Convert src point to raster
        srcras = scrws + "\\src_ras"
        arcpy.PointToRaster_conversion(srcfc, "VAL", srcras, "", "", suitgrid["res"])
        arcpy.BuildRasterAttributeTable_management(srcras, "NONE")

        #Convert dest point to raster
        destras = scrws + "\\dest_ras"
        arcpy.PointToRaster_conversion(destfc, "VAL", destras, "", "", suitgrid["res"])
        arcpy.BuildRasterAttributeTable_management(destras, "NONE")

        #Delete the point layer if it still exists
        if arcpy.Exists(pntlaynm):
            arcpy.Delete_management(pntlaynm)

        #Rebuild the raster Vat on the suitability grid
        #arcpy.AddMessage("Rebuild the Suitability Grid VAT")
        #arcpy.BuildRasterAttributeTable_management(srcsg, "NONE")

        #run the Cost Distance tool for the source point
        arcpy.AddMessage("Run Cost Distance")
        srcsgdist = scrws + "\\" + costgrd["COSTCODE"] + "_c"
        srcsgback = scrws + "\\" + costgrd["COSTCODE"] + "_b"
        outcost = CostDistance(srcras, srcsg, "", srcsgback)
        outcost.save(srcsgdist)


Crashes on the CostDistance method.

Outcomes