I'm not a python script writer thus the question. What's needed is a script that will do the following:
It's a feature class in the File Geodatabase (Data.gdb). I avoid shapefiles at all costs.
Thanks for the sample data. Here's the error message and script using the sample data. I created a mosaic dataset under Data.gdb for the clipped rasters. Not sure if that is OK.
Creating Feature Layer for 1
Clipping raster
Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 13594, in Clip raise e ExecuteError: ERROR 000732: Input Raster: Dataset C:\temp\clips\SampleData\Data.gdb\DEM.tif does not exist or is not supported
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"C:\temp\clips\SampleData\Data.gdb\Linebuf_geo"
raster = r"C:\temp\clips\SampleData\Data.gdb\DEM.tif"
with arcpy.da.SearchCursor(shapefile, "LineNum") as cursor:
for row in cursor:
print("Creating Feature Layer for " + str(row[0]))
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", "LineNum = '" + row[0] + "'")
desc = arcpy.Describe("fLayer")
extent = str(desc.extent.XMin) + " " + str(desc.extent.YMin) + " " + str(desc.extent.XMax) + " " + str(desc.extent.YMax)
print("Clipping raster")
arcpy.Clip_management(raster, extent, r"C:\temp\clips\SampleData\Data.gdb\LineNum_Clips\DEM_" + str(row[0]), "fLayer", "", "ClippingGeometry", "MAINTAIN_EXTENT")
del cursor
You will not want to create a mosaic dataset to get this code to work. Change the following:
raster = r"C:\temp\clips\SampleData\Data.gdb\DEM.tif" to:
raster = r"C:\temp\clips\SampleData\DEM.tif"
Thanks for all your help, Jake!