Clipping a GRID file (input raster) to a Shapefile (Clip Extent)

936
3
05-09-2011 02:37 PM
AdelaideBaker
New Contributor
Hi,

I am using ArcGIS 10.0 and am trying to clip GRID files to a shapefile boundary. I can do this easily in ArcMap using Data Management Tools > Raster > Raster Processing > Clip. However when it comes to python I get an error about my inFolder. Because GRID files don't have a .shp, .tif etc. at the end do I have to add something else to my script? Thanks!

import arcpy

inFolder = "C:/Documents and Settings/someone/Desktop/Data/tmin_01"
resultsFolder = "C:/Documents and Settings/someone/Desktop/Data/output"
clipFeature = "C:/Documents and Settings/ajbaker/Desktop/PRISM_Trial/Boundary/Hydrographic_GB_boundary.shp"

arcpy.Clip_management("inFolder", "#", "clipFeature","resultsFolder", "0", "ClippingGeometry")
Tags (2)
0 Kudos
3 Replies
DarrenWiens2
MVP Honored Contributor
inFolder is a variable that contains a string, so you don't put it in quotes (the way it is now, it's literally looking for a file with the path "inFolder"). Same with the other variables you pass as parameters. If you were directly entering the string in the clip command, you would enclose it in quotes.
0 Kudos
AdelaideBaker
New Contributor
Thanks. Problem solved!
0 Kudos
AdelaideBaker
New Contributor
I am very new at all of this and have another problem. How do I clip multiple GRID files. Also how might I be able to overwrite the input file? Here is my script so far:

import arcpy

arcpy.env.overwriteOutput = True

inFolder = "C:/Documents and Settings/user/Desktop/Data/tmin_1900_01"
resultsFolder = "C:/Documents and Settings/user/Desktop/Data/tmin_1900_01"
clipFeature = "S:/Projects/Wetlands/Title/Maps/Data layers/GB_boundary.shp"
arcpy.workspace = resultsFolder

#Process: Clip...
for input_feature in inFolder:
    for clip_feature in clipFeature:
        outfile = arcpy.CreateUniqueName(resultsFolder, inFolder)   

#Usage: Clip_management in_raster rectangle out_raster {in_template_dataset} {nodata_value} {NONE | ClippingGeometry}
arcpy.Clip_management(inFolder, "#", outfile, clipFeature, "0", "ClippingGeometry")

print "Clip_management worked!"

print arcpy.GetMessages()
0 Kudos