so only saved rasters in a file geodatabase seem to work - IMGs and GRIDs and temporary grids cause errors in decimal seconds.
The problem I have is this. For some relatively long (geoprocessing wise) period of time after I've finished reading from or writing to a raster, the raster remains locked, and cannot be overwritten nor deleted. Currently, I'm working around this problem by writing each intermediate raster to a unique filename. This leaves me with a massive collection of unneeded intermediate files cluttering up my geodatabase.
MyRast = "\\\\wc98466\\D\\baks\\temp.gdb\\MyRaster" or sCur = arcpy.SearchCursor( "\\\\wc98466\\D\\baks\\temp.gdb\\MyRaster")
MyRast = "\\\\wc98466\\D\\baks\\temp.gdb\\MyRaster" or sCur = arcpy.SearchCursor( "\\\\wc98466\\D\\baks\\temp.gdb\\MyRaster") del MyRast del sCur
arcpy.PolygonToRaster_conversion(bldglayer, "bldgtype", 'workingFGDB.gdb\\bldgtile' + str(i) + '_' + str(j), "#")
bldgnull = sa.IsNull('workingFGDB.gdb\\bldgtile')
bldgnull.save('workingFGDB.gdb\\bldgtilenull')
nobldgtile = sa.Con(lulcnullname, 0, geolulcname, "VALUE > 0")
nobldgtile.save('workingFGDB.gdb\\nobldgtile')
lulctile = sa.Con('workingFGDB.gdb\\bldgtilenull', 'workingFGDB.gdb\\nobldgtile', 'workingFGDB.gdb\\bldgtile', "VALUE > 0")
lulctile.save(lulctilename)
For reference, this is taking a set of building classes from a building outline polygon file and adding them to a land-use/land-cover dataset.
from arcpy.sa import *
from arcpy.env import env
env.overwriteOutput = 1
# for best performance of map algebra, scratch and current should be the same
env.workspace = arcpy.env.scratchWorkspace = workingFGDB.gdb
lulc = Raster(lulcName) # convert to raster object for use in map algebra
...
bldgtileName = "bldg{0}_{1}".format(i,j)
lulctileName = "lulc{0}_{1}".format(i,j)
arcpy.PolygonToRaster_conversion(bldglayer, "BLDGTYPE", bldgtileName)
bldgtile = Raster(bldgtileName) # convert to raster object (note, this is a permanent raster)
nobldgtile = Con(IsNull(lulc), 0, lulc) # convert any null LULC cells to zero
# replace null cells in bldgtile with lulc cells
lulctile = Con(IsNull(bldgtile), nobldgtile, bldgtile)
lulctile.save(lulctileName) # this is the only one you want to save
# arcpy.Delete_management(bldgtile) # uncomment to delete
Wrapping my code in a function has solved this issue for me. As in:
def mf_function():
arcpy.PolygonToRaster_conversion(bldglayer, "bldgtype", 'workingFGDB.gdb\\bldgtile' + str(i) + '_' + str(j), "#")
bldgnull = sa.IsNull('workingFGDB.gdb\\bldgtile')
bldgnull.save('workingFGDB.gdb\\bldgtilenull')
nobldgtile = sa.Con(lulcnullname, 0, geolulcname, "VALUE > 0")
nobldgtile.save('workingFGDB.gdb\\nobldgtile')
lulctile = sa.Con('workingFGDB.gdb\\bldgtilenull', 'workingFGDB.gdb\\nobldgtile', 'workingFGDB.gdb\\bldgtile', "VALUE > 0")
lulctile.save(lulctilename)