I'm not a python script writer thus the question. What's needed is a script that will do the following:
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
You can replace the following line:
arcpy<SPAN class="">.</SPAN>MakeFeatureLayer_management<SPAN class="">(</SPAN>shapefile<SPAN class="">,</SPAN> <SPAN class="">"fLayer"</SPAN><SPAN class="">,</SPAN> <SPAN class="">"LINENUM = '"</SPAN> <SPAN class="">+</SPAN> row<SPAN class="">[</SPAN><SPAN class="">0</SPAN><SPAN class="">]</SPAN><SPAN class=""> + "'")</SPAN><CODE>arcpy<SPAN class="">.</SPAN>MakeFeatureLayer_management<SPAN class="">(</SPAN>shapefile<SPAN class="">,</SPAN> <SPAN class="">"fLayer"</SPAN><SPAN class="">,</SPAN> <SPAN class="">"LINENUM = "</SPAN> <SPAN class="">+</SPAN> row<SPAN class="">[</SPAN><SPAN class="">0</SPAN><SPAN class="">]</SPAN><SPAN class="">) with </SPAN>
arcpy<SPAN class="">.</SPAN>MakeFeatureLayer_management<SPAN class="">(</SPAN>shapefile<SPAN class="">,</SPAN> <SPAN class="">"fLayer"</SPAN><SPAN class="">,</SPAN> <SPAN class="">"LINENUM = '"</SPAN> <SPAN class="">+</SPAN> row<SPAN class="">[</SPAN><SPAN class="">0</SPAN><SPAN class="">]</SPAN><SPAN class=""> + "'")</SPAN>
exp = "LineNum = '{}'".format(row[0])
arcpy.MakeFeatureLayer_management(shapefile, "fLayer", exp)
exp = "LineNum = {}".format(roww[0])
maybe?
For reference
/blogs/dan_patterson/2016/08/14/script-formatting
since you have no line numbers
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).
Try the following:
<SPAN class="keyword token">import</SPAN> arcpy arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN> shapefile <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\temp\LineBuf.shp"</SPAN> raster <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\temp\MN_DEM3second"</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>shapefile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LINENUM"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Creating Feature Layer for "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>shapefile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"fLayer"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LINENUM = "</SPAN> <SPAN class="operator token">+</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Clipping raster"</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Clip_management<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">"C:\temp\DEM_"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"fLayer"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"MAINTAIN_EXTENT"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">del</SPAN> cursor<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.