[GIS] How to clip raster image by the extent of each row in a shapefile with ArcGIS 9.3

arcgis-9.3pythonraster

I'm using Python to clip a raster image by each row in a shapefile with ArcGIS 9.3. I am hoping to end up with one raster image for each polygon row, clipped to the extent of the polygon row. However, my current script clips the raster to the entire shapefile, instead of setting the extent by each polygon row. My script is as follows:

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

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Designate a workspace
gp.workspace = "L:\Clip"

# Assign variables...
clipto = "test.shp"

# grids to clip to
clipit = "vfcm.tif" # features to be clipped

# Cursor time
rows = gp.SearchCursor(clipto)
row = rows.Next()

# clip management
while row:
    n = str(row.VAHU6) # assign a variable for the processing message based on a field
print "clipping to: " +n # tells what grid was clipped

# Clip_management <in_raster> <rectangle> <out_raster> {in_template_dataset}   {nodata_value} {NONE | ClippingGeometry}
outputname = str(row.VAHU6) + "_c"
desc = gp.Describe(clipto)
extent = str(desc.Extent)
gp.Clip_management(clipit, extent, outputname, clipto, "", ClippingGeometry) #update str if necessary
print str(row.VAHU6)
row=rows.next()

# reset the array...
del rows
del gp

Any ideas how to fix it?

Thanks!

Best Answer

You need the shape field of the row to clarify what geometry you're clipping by. So somewhere near your while loop (either inside or just before), specify the geometry like so:

clipgeo = row.Shape

And then use the object (in this case, clipgeo) as your feature to clip by instead of the entire shapefile.

A similar problem can be seen here: How to batch clip to single-part shapefile using ArcGIS 9.3 and Python 2.5?