1

I am having trouble using Fill in arcpy as part of a tool. It works fine as a script, but when I create a tool, it fails. To localize the problem I modified the Help stand-alone script associated with Fill. I also tried creating a blank raster outFill before the Fill command, but with similar results.

# Name: Fill_Ex_02.py
# Description: Fills sinks in a surface raster.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

inSurfaceRaster = arcpy.GetParameterAsText(0)

# Set local variables
zLimit = 3.28

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute FlowDirection
outFill = Fill(inSurfaceRaster, zLimit)

# Save the output 
outFill.save("C:/sapyexamples/output/TestFilled.tif")
~~~~~~~~~~

The error message is:
Traceback (most recent call last):
  File "C:\Users\William\Desktop\Pit_test\Tools\Test_outfill_tbx.py", line 22, in <module>
    outFill = Fill(inSurfaceRaster, zLimit)
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Functions.py", line 2271, in Fill
    z_limit)
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Utils.py", line 53, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\sa\Functions.py", line 2267, in Wrapper
    z_limit)
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999999: Error executing function.
("esriDataSourcesRaster.RasterWorkspace") Failed to create raster dataset
ERROR 010302: Unable to create the output raster: c:\windows\system32\t_t428.tif
ERROR 010067: Error in executing grid expression.
Failed to execute (Fill).

Failed to execute (TestOutfill).
Failed at Wed Sep 11 17:18:08 2019 (Elapsed Time: 0.49 seconds)
  • 2
    have you tried using a scratch workspace. Writing to your system32 may be an issue. arcpy.env.scratchWorkspace = "C:/sapyexamples/data" – D_C Sep 11 at 22:04
  • 1
    Yikes! Why are you writing to `c:\windows\system32` ? That's not a directory you should ever touch directly! – Son of a Beach Sep 11 at 23:07
  • 1
    I have noticed that the default directory for a python instance is c:\windows\system32, so unless told otherwise with env workspace and scratch workspace the temporary GRIDs generated end up there. I would recommend setting arcpy.env.scratchWorkspace = os.environ.get('TEMP') as you can be sure this folder exists and has write permissions. Note that GRID workspace can become broken in which case delete everything in the %temp% folder and subfolders which should be safe to do at any time; files in use will refuse to delete so it shouldn't affect update temp files. – Michael Stimson Sep 11 at 23:35
2

Turns out the file already existed, so I cured it by allowing overwrites (alternatively, by deleting the file before beginning).

  • Yes, the error messages can be quite cryptic, it would have been easier if the error had of been 'failed to overwrite'. As Son of a Beach pointed out try to avoid writing to anything that starts with c:\\windows as the UAC will probably disallow your writing - that you could do this once shows you're local admin which means you're trusted not to break the OS with careless actions like accidentally overwriting a required file. I would recommend writing to os.environ.get('USERPROFILE') if you must write to C drive. – Michael Stimson Sep 11 at 23:29

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.