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

4250
6
02-22-2013 09:31 AM
DaveHighness
Occasional Contributor II
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.
Tags (2)
0 Kudos
6 Replies
curtvprice
MVP Esteemed Contributor
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


I'm trying to think why the raster attribute table would intermittently come up missing. If one of the inputs is all NoData, it will not have an attribute table even if you run BuildAttributeTable. You could get a NoData source grid if for example you extent cuts off your input points. You should probably check the existence of the attribute table if situation is going to happen just based on your input data.
0 Kudos
DaveHighness
Occasional Contributor II
You should probably check the existence of the attribute table if situation is going to happen just based on your input data.


I'm not sure I know how to check for the existence of a VAT. Looks like under the Describe class and Raster Band there is a tableType property. Any other ideas. I can see that the source point raster is created correctly in the scratch workspace after the fact.

What I've been wondering is if my source point raster is fully created and VAT built prior to the CostDistance running. I am also creating the source point raster with that same extents and resolution, spatial reference as the cost grid. Is that necessary?

I was getting errors when I tried using the the point feature class as the source point also.

Thanks, Dave
0 Kudos
curtvprice
MVP Esteemed Contributor
I'm not sure I know how to check for the existence of a VAT.


A raster can have a RAT but be all NoData. Here's how I suggest checking:


if Raster(srcras).minimum == None:
    raise Exception, "Raster is all NoData!"



What I've been wondering is if my source point raster is fully created and VAT built prior to the CostDistance running. I am also creating the source point raster with that same extents and resolution, spatial reference as the cost grid. Is that necessary?


You must set the snapRaster and cellSize so the source grid will line up with your cost grid. This is true whether you are making a source grid or providing points to the tool.

I'd look at those scratch grids to try to verify that your source grid is ok when it fails.
0 Kudos
DaveHighness
Occasional Contributor II
Darn! I added the checks for raster values for the source and destination rasters and the cost raster and I added the cost raster as the arcpy.env.snapRaster and it gives the same error. Then I reverted back to using the source point feature class and it still errors with the same error message. Then I tried copying the cost raster to the scratch fgdb so it would be in the same fgdb as the source points and it still errors. What is causing this error?

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_9423c709.gdb\61xy1i64e_b. Cost Distance mapping Failed
ERROR 010067: Error in executing grid expression.
Failed to execute (CostDistance).


It I take these same inputs and run it through the Cost Distance tool manually it runs correctly without error.

Arg!
0 Kudos
DaveHighness
Occasional Contributor II
Well, it just ran cleanly 2 times in a row and then on the 3rd it errored with the now famous error. Thought maybe I had it. I guess it's time for a beer...
0 Kudos
mikeking1
New Contributor II
I came across this thread while searching for a solution to my own version of this issue - I think they could be the same problem. 

I suspect that its actually a locking issue and nothing to do with the actual VAT itself.  In my own script (which creates a smoothed categorized polygon from input classified raster).  I'm getting this error intermittently on the same raster.  Its most prevelent when running the script - almost entirely absent when stepping through in the debugger.

Its very difficult to trap what is actually happening but I think its arcgis not letting go of the table before arcpy tries to access it again.  In my process its the reclass function which throws this error.  I reclass a float raster to get the categories for the polygon, but in running multiple sequential reclasses on the same raster seems to be generating this error.  I've found that running the same script on a computer still running ArcGIS 10.0 SP5 without the latest windows update - none of the errors are thrown.

So from looking at your script I suspect that what is actually causing the error is the build of the VAT in the block preceding the one that throws the error.

I haven't had time to test this theory properly in my own application but hopefully that gives you another line to work on.

Good Luck

Mike
0 Kudos