I'm not a python script writer thus the question. What's needed is a script that will do the following:
OK thanks but still getting an error (for some reason I can't post in Python format):
>>> 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, extent, 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
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 000622: Failed to execute (Clip). Parameters are not valid. ERROR 000800: The value is not a member of ClippingGeometry | NONE.
>>>
I believe I had some parameters incorrect, and we should be getting the extent of the shapefile, not the raster. Try:
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\DEM_" + str(row[0]), "fLayer", "", "ClippingGeometry", "MAINTAIN_EXTENT")
del cursor
Re-running right now and no issues so far. I'll keep you posted.
Many thanks, Jake and Dan!
Hi Jake,
I just wanted to thank you again for the script. However, I am still waiting for the first raster to be clipped and was wondering if you had any idea on why it might be taking so long. When I do the processing interactively (on just one query) the clip takes less than a couple minutes to process.
Any ideas?
Thanks,
Jim Fritz, GISP
Xcel Energy | Responsible By Nature
Sr. Geospatial Analyst
414 Nicollet Mall, 6th Floor, Minneapolis, MN 55401
P: 612.330.6956 C: 781.588.5829 F: 612.330.6590
E: james.w.fritz@xcelenergy.com<mailto:james.w.fritz@xcelenergy.com>
This could be a projection issue, bad me. I'm going to project the polygon layer to geographic to match the DEM. I'll try running the script again after the fix.
After running the script over the weekend no clipped rasters were created. The script showed each polygon being created (selected?) and a clip created. Unfortunately, when I checked the grid folder there were none there.
Any ideas??
Thanks,
Jim
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\STLM_NSP.gdb\LineBuf_geo"
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] + "'")
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"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\clips\DEM_" + str(row[0]), "fLayer", "", "ClippingGeometry", "MAINTAIN_EXTENT")
del cursor123456789101112131415
Try changing the output type to a TIF to see if that changes anything:
import arcpy
arcpy.env.overwriteOutput = 1
shapefile = r"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\STLM_NSP.gdb\LineBuf_geo"
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] + "'")
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"S:\General-Offices-GO-Trans\SLR-Mapping\GIS_Projects_2018\Smart_T_Line_Model\geodata\clips\DEM_" + str(row[0]) + ".tif", "fLayer", "", "ClippingGeometry", "MAINTAIN_EXTENT")
del cursor
Hi Jake,
I tried re-running with outputs to tif format. Unfortunately, the script seems to run fine but no tif files are appearing in the “clips” subfolder.
Kind of strange.
Here’s what a file should look like spatially, created interactively.
Thanks for helping out.
Jim Fritz, GISP
Xcel Energy | Responsible By Nature
Sr. Geospatial Analyst
414 Nicollet Mall, 6th Floor, Minneapolis, MN 55401
P: 612.330.6956 C: 781.588.5829 F: 612.330.6590
E: james.w.fritz@xcelenergy.com<mailto:james.w.fritz@xcelenergy.com>
Hi Jake,
The zip file did not have a clipping polygon shapefile. Did you intend to send that?
Thanks,
Jim