I'm not a python script writer thus the question. What's needed is a script that will do the following:
Try the following:
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"C:\temp\LineBuf.shp"
raster = r"C:\temp\MN_DEM3second"
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])
print("Clipping raster")
arcpy.Clip_management(raster, "", r"C:\temp\DEM_" + str(row[0]), "", "fLayer", "MAINTAIN_EXTENT")
del cursor
Jake,
Many thanks for script but I get the following error message. Note that I changed the folder paths to the shapefile and raster inputs. The field "LineNum" is a text field if that is an issue.
>>> import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\LineBuf.shp"
raster = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\MN_DEM3second"
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])
print("Clipping raster")
arcpy.Clip_management(raster, "", r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\DEM_" + str(row[0]), "", "fLayer", "MAINTAIN_EXTENT")
del cursor
Creating Feature Layer for 0517
Runtime error Traceback (most recent call last): File "<string>", line 10, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 6520, in MakeFeatureLayer raise e ExecuteError: ERROR 000358: Invalid expression LineNum = 0517 Failed to execute (MakeFeatureLayer).
>>>
exp = "LineNum = {}".format(roww[0])
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", exp)
maybe?
For reference
/blogs/dan_patterson/2016/08/14/script-formatting
since you have no line numbers
You can replace the following line:
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", "LINENUM = " + row[0]) with
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", "LINENUM = '" + row[0] + "'")
Or Dan Patterson's approach (he was missing single quotes around the {}:exp = "LineNum = '{}'".format(row[0])
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", exp)
Thanks, Jake and Dan but now I'm getting this message:
Runtime error Traceback (most recent call last): File "<string>", line 12, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 13594, in Clip raise e ExecuteError: ERROR 000622: Failed to execute (Clip). Parameters are not valid. ERROR 000800: The value is not a member of ClippingGeometry | NONE.
>>>
Probably something easy with the ClippingGeometry arguments?
Jim
Looks like the raster extent is needed. Try the following:
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"C:\temp\LineBuf.shp"
raster = r"C:\temp\MN_DEM3second"
desc = arcpy.Describe(raster)
extent = str(desc.extent.XMin) + " " + str(desc.extent.YMin) + " " + str(desc.extent.XMax) + " " + str(desc.extent.YMax)
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] + "'")
print("Clipping raster")
arcpy.Clip_management(raster, extent, r"C:\temp\DEM_" + str(row[0]), "", "fLayer", "MAINTAIN_EXTENT")
del cursor
Getting this message now:
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 000622: Failed to execute (Clip). Parameters are not valid. ERROR 000800: The value is not a member of ClippingGeometry | NONE.
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\LineBuf.shp"
raster = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\MN_DEM3second"
desc = arcpy.Describe(raster)
extent = str(desc.extent.XMin) + " " + str(desc.extent.YMin) + " " + str(desc.extent.XMax) + " " + str(desc.extent.YMax)
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] + "'")
print("Clipping raster")
arcpy.Clip_management(raster, "", r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\DEM_" + str(row[0]), "", "fLayer", "MAINTAIN_EXTENT")
del cursor
You're missing the 'extent' variable in the arcpy.Clip_management function. You should have:
arcpy.Clip_management(raster, extent, r"S:\Gen......