Failed to execute (ExtractByMask)

1514
2
03-12-2012 04:38 PM
haiyanwei
New Contributor
Dear Forum,

I found a loop example here from the forum and modified for my case. Thanks for the previous Q/As.
what I am trying to do is:
1. read a list of ascii files
2. convert them to raster
3. clip raster file by a boundary mask
4. convert the clipped raster to polygon

I got an error message for 'extractbymask':
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input raster or feature mask data: is not the type of Composite Geodataset, or does not exist.
Failed to execute (ExtractByMask).

here is the code:
# ---------------------------------------------------------------------------
# convertions_loop.py
# Created on: Mon Mar 12 2012 04:31:41 PM
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Check out any necessary licenses
gp.CheckOutExtension("spatial")

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")


# Set local variables
InAsciiFile = None
inDir = r"C://a//asc_annual_PDSI"
OutRaster = "C://a//raster_annual"
SRER_bound="C://Spatial//shape_files//bounds.shp"
OutClip="C://a//raster_annual_clip"
OutPolygon="C://a//polygon_annual"

for InAsciiFile in os.listdir(inDir):
    if InAsciiFile.rsplit(".")[-1] == "asc":
        print InAsciiFile
# Process: ASCIIToRaster_conversion
        outR= os.path.join(OutRaster,InAsciiFile.rsplit(".")[0])
        gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), outR, "INTEGER")

# Process: Extract by Mask...
        outC=os.path.join(OutClip,InAsciiFile.rsplit(".")[0])
        gp.ExtractByMask_sa(outR, SRER_bound, outC)

# Process: Raster to Polygon...
        outP=os.path.join(OutPolygon,InAsciiFile.rsplit(".")[0])                               
        gp.RasterToPolygon_conversion(outC,outP, "NO_SIMPLIFY", "VALUE")
-----------------------------------------
I tried to use:
SRER_bound="C://Spatial//shape_files//bounds"
but got the same error

Could anyone please help? Thanks.
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
It may have difficulty reading your path formats for some tools.

Valid Python paths should be
r"C:\GISpath\somefile.ext"
"C:/GISpath/somefile.ext"
"C:\\GISpath\\somefile.ext"

Also I would suggest printing the values of your variables just before the tool to make sure there isn't something going wrong there.
0 Kudos
haiyanwei
New Contributor
Thank you mzcoyle
It is working now. It should be:
SRER_bound="C://Spatial//shape_files//bounds//bounds.shp"

I got another error at the third step"Raster to Polygon...", then I changed the path as you suggested, it worked. Thanks!!
0 Kudos