ExtractByMask Error

1541
4
04-18-2010 05:15 PM
WentaoChe
Occasional Contributor II
Hi,

ExtractByMask does not work for the following Python:

import arcpy
arcpy.CheckOutExtension("spatial")
tif = "H:\\Test-20100419\\t.tif"
shp = "H:\\Test-20100419\\A27401_05.shp"
out_raster = "H:\\Test-20100419\\ttt.tif"
out = arcpy.sa.ExtractByMask(tif, shp)
out.save(out_raster)

Error message:

Traceback (most recent call last):
  File "H:\Test-20100419\test.py", line 6, in <module>
    out = arcpy.sa.ExtractByMask(tif, shp)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Functions.py", line 1210, in ExtractByMask
    in_mask_data)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Utils.py", line 67, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Functions.py", line 1204, in wrapper
    out_raster)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\geoprocessing\_base.py", line 438, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000879: Output raster: The length of the stack base name in H:\Test-20100419\Extract_t1 is longer than 9.
Failed to execute (ExtractByMask).

I set the output raster as a TIF not a Grid Stack, I can not understand the error message "The length of the stack base name is longer than 9." This is not the case.

There is no any problem when I use ExtractByMask Tool in ArcToolbox.

Best regards,

Wentao

KKC, Tokyo, Japan
0 Kudos
4 Replies
RyanDeBruyn
Esri Contributor
HI Wentao

There seems to be an issue with the name of the temporary raster that is created by the tool. By default you must have a file based scratch workspace set so the format is attempting to create a grid stack(limit 9 characters). 

Try to set a file geodatabase as your scratch workspace there will not be a name restriction.

arcpy.env.scratchWorkspace = "c:/data/myfilegdb.gdb"
out = arcpy.sa.ExtractByMask(tif, shp)
out.save("C:/output/final_ras")

Thank you for your input, we will work to remedy the error.

-Ryan
ESRI Spatial Analyst Team
0 Kudos
WentaoChe
Occasional Contributor II
Hi Ryan,

Thank you for your reply.

I tried to set scratch workspace and worksapce to :\Test-20100419\myfilegdb.gdb, both are failed.
Herre is the error message:

  File "H:\Test-20100419\test2.py", line 19, in <module>
    out = arcpy.sa.ExtractByMask(tif, shp)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Functions.py", line 1210, in ExtractByMask
    in_mask_data)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Utils.py", line 67, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\sa\Functions.py", line 1204, in wrapper
    out_raster)
  File "C:\ArcGIS\Desktop9.4\arcpy\arcpy\geoprocessing\_base.py", line 438, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
arcgisscripting.ExecuteError: ERROR 000875: Output raster: H:\Test-20100419\myfilegdb.gdb\Extract_tif1's workspace is an invalid output workspace.
ERROR 000581: Invalid parameters.
Failed to execute (ExtractByMask).

Wentao
0 Kudos
PeterProkein
New Contributor
This problem persists in Arc10 Build2414.
0 Kudos
MichaelRichey
New Contributor

For what its worth (a little late to the game from the original post). I'm replying since I also recently received similar error messages when running "Extract By Mask" in a Python script (ArcDesktop 10.3.1). In my particular instance I am referencing a single DEM and selecting multiple polygons to create unique rasters from each polygon. After realizing that a temporary file is created each time the "Extract By Mask" command is run, executing the save command allowed the passing of a variable with a unique name, eliminating the error messages, allowing the script to create the intended output(s). I also specified a scratch workspace.

script Example:

env.workspace = "//w63-atlas/Stormwater/Waterways/Structure Flood Severity"

bslash = "\\"
Raster = bslash+"\\w63-atlas\Stormwater\AMEC\CLAY\TOPO\DEM\claydem.gdb\claydem"

arcpy.env.scratchWorkspace = "//w63-atlas/Stormwater/Waterways/Rasterdatasets.gdb"

tile = raw_input("Enter FEMA TILE : C4, C5, C6, D4, D5, D6, E5, E6, F5, F6, G5, or G6: ")

prefix = "Export_"
suffix = "_Culv*_1.shp"
depiwant = prefix+tile+suffix

fcList  = arcpy.ListFeatureClasses(depiwant)

arcpy.AddMessage(Raster)
for i in fcList:
     Culvnum = i[14:-4]
     rasnew = gdb+"/"+tile+"rz"+Culvnum[:-2]
     outExtractByMask = ExtractByMask(Raster,i)
     arcpy.AddMessage(outExtractByMask)
     outExtractByMask.save(rasnew)
     exit

0 Kudos