I am building an arcpy script, where I would like to create a for loop, that for each raster, it clips it from a shapefile, and creates a new output, with name based on the file itself. The code:
import arcpy
arcpy.env.workspace= r"C:\Angela\LC"
#import the raster files for land cover
#Local variables:
n1992_USA = "C:\\Angela\\OK\\nlcd_1992_30meter_whole (1)\\nlcd_1992_30meter_whole.img"
n2001_USA = "C:\\Angela\\OK\\nlcd_2001_landcover_2011_edition_2014_10_10\\nlcd_2001_landcover_2011_edition_2014_10_10\\nlcd_2001_landcover_2011_edition_2014_10_10.img"
n2006_USA = "C:\\Angela\\OK\\nlcd_2006_landcover_2011_edition_2014_10_10\\nlcd_2006_landcover_2011_edition_2014_10_10\\nlcd_2006_landcover_2011_edition_2014_10_10.img"
n2011_USA = "C:\\Angela\\OK\\nlcd_2011_landcover_2011_edition_2014_10_10\\nlcd_2011_landcover_2011_edition_2014_10_10\\nlcd_2011_landcover_2011_edition_2014_10_10.img"
#import rasters
arcpy.MakeRasterLayer_management(n1992_USA, "1992t", "", "-2361915 267885 2266005 3177735", "")
arcpy.MakeRasterLayer_management(n2001_USA, "2001t", "", "-2361915 267885 2266005 3177735", "")
arcpy.MakeRasterLayer_management(n2006_USA, "2006t", "", "-2361915 267885 2266005 3177735", "")
arcpy.MakeRasterLayer_management(n2011_USA, "2011t", "", "-2361915 267885 2266005 3177735", "")
#import admin boundaries
admin_boundaries_usa = "C:\\Angela\\tmp\\cb_2013_us_county_5m.shp"
arcpy.MakeFeatureLayer_management(admin_boundaries_usa, "admin_boundaries_usa", "",
"", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;STATEFP STATEFP VISIBLE NONE;COUNTYFP COUNTYFP VISIBLE NONE;COUNTYNS COUNTYNS VISIBLE NONE;AFFGEOID AFFGEOID VISIBLE NONE;GEOID GEOID VISIBLE NONE;NAME NAME VISIBLE NONE;LSAD LSAD VISIBLE NONE;ALAND ALAND VISIBLE NONE;AWATER AWATER VISIBLE NONE")
#crop the latter to texas
# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management("admin_boundaries_usa", "NEW_SELECTION", "\"STATEFP\" = '48'")
# Process: Copy Features
arcpy.CopyFeatures_management("admin_boundaries_usa", "tx_shp", "", "0", "0", "0")
arcpy.SelectLayerByAttribute_management("admin_boundaries_usa", "CLEAR_SELECTION")
#dissolve to have the whole state
arcpy.Dissolve_management("tx_shp", "tx_shp_Dissolve", "STATEFP", "", "MULTI_PART", "DISSOLVE_LINES")
#make loop for all rasters to be clipped w/ shapefile
rasterlist=[n1992_USA, n2001_USA, n2006_USA, n2011_USA]
OUTFOLDER = "C:\\Angela\\LC"
Everything works fine, until when I input the loop in ArcGIS:
for inraster in rasterlist:
print inraster
tx_name = os.path.join(OUTFOLDER, str(inraster))
arcpy.Clip_management(inraster, "-1075276.88510708 309884.007197296 251355.2459483 1547680.1003418", tx_name, "tx_shp_Dissolve", "255", "NONE", "NO_MAINTAIN_EXTENT")
and it retrieves the following:
Runtime error Traceback (most recent call last): File "<string>", line 4, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 13771, in Clip raise e ExecuteError: ERROR 000670: output Output Raster Dataset is same as input Input Raster
I know I must have a rookie mistake on the loop part, but I can't see what else I could do to make it work.
line 4
in your error message. The advice on providing code snippets may be worth reviewing sometime, if you have not already.