0

I have three scripts running simultaneously that processes raster data in several directories. The problem I am encountering is that ArcGIS is creating a temporary grid file called 'Extract_recl1' when the Extract by Mask (Spatial Analyst) tool is called. The temporary file is created in a directory where it is looking for raster data. Seeing that I have several scripts running simultaneously, there is occasionally conflict where one script trys to run Extract By Mask and encounters 'Extract_recl1', which was created by Extract by Mask running in a different script. This is the error I receive:

ExecuteError: ERROR 010429: Error in GRID IO: CellLyrCreateInternal: Directory f:\mydirectory\reclass_new_classes\extract_recl1  already exists.
ERROR 010302: Unable to create the output raster: F:\mydirectory\reclass_new_classes\Extract_recl1
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByMask).

I have tried to handle this situation by saving the raster object with a unique name to a temp directory and deleting the file upon completion:

# Extract by mask
reclass_clp = ExtractByMask(reclass, mask_raster_temp)
reclass_clp_temp = random_name_generator(temp_ws, "reclass_clp_temp", ".tif") # This is a function that generates a unique output name
reclass_clp.save(reclass_clp_temp)

# Do some processing...

arcpy.Delete_management(reclass_clp_temp)

I have also set the overwriteOutput environment to True.

arcpy.env.overwriteOutput = True

However, neither of these seem to have any effect. What is the best way to handle temporary files created by Extract By Mask (Spatial Analyst)?

In other words, is there a way to force Extract by Mask to generate a unique name for the temp grid 'Extract_recl1'?

  • I've never seen these left over after the script runs to completion (esp. if you have delete running on them). Are you sure the script isn't ending prematurely? I just noticed that you are saving the same output you are trying to delete. Is that really intended? – jbchurchill Dec 22 '15 at 15:16
  • @jbchurchill These temp grids are generated and deleted automatically at the completion of each iteration. The conflict occurs when another script accessess raster data from the same directory and produces this'Extract_recl1' file at the same time. That is to say, two scripts are creating this temp file simultaneously and there is no way to control the output location or the name. – Aaron Dec 22 '15 at 15:57
  • The error help says its a problem with the .hdr file. support.esri.com/fr/knowledgebase/techarticles/detail/36717 – Emil Brundage Dec 22 '15 at 16:13
  • @Luke. Not abandoned, just off the radar. – Aaron Aug 3 '16 at 3:58
2

The Extract By Mask tool honours the Scratch Workspace environment. Try setting a different arcpy.env.scratchWorkspace for each script run with the python tempfile.mkdtemp function.

import tempfile, shutil
import arcpy
from arcpy.sa import *

tmpdir = tempfile.mkdtemp()
arcpy.env.scratchWorkspace = tmpdir

reclass_clp = ExtractByMask(reclass, mask_raster_temp)
reclass_clp.save(reclass_clp_final)

shutil.rmtree(tmpdir)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.