I am new to GIS.
I have several rasters in one file location
I am using clip tool to loop over several rasters in arcgis. When I start I am choosing workspace, which is the folder where my input files are. However after clip I want to save output into different file. I could not figure it out how to do.
Can you please show me?
Here is my code.
# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *
# Setting working directory
arcpy.env.workspace = r"D:\Research\arcgis"
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Local variables:
Tr_pro = "D:\\Tr2009\\admin\\Trpro.shp"
Tr_lyr = "D:\\Tr2009\\admin\\Trlayer"
Tr_dist = "D:\\Tr2009\\admin\\Trdist.shp"
arcpy.MakeFeatureLayer_management(Tr_dist, Tr_lyr)
arcpy.SelectLayerByAttribute_management(Tr_lyr, "NEW_SELECTION", "\"Name\" = 'Adi'")
rasterList = arcpy.ListRasters("F*")
for raster in rasterList:
arcpy.Clip_management(raster, "25.665181 35.812875 44.826408 42.104629", "M"+str(raster[1:]), Tr_lyr, "255", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
If i use this code, it saves all output into the workspace that I defined in the beginning. However I want to save it to another location such as "D:\Tr2009\admin\output
1 Answer 1
Add an output path parameter (outputPath = "D:\\Tr2009\\admin\\output\\"
) and use that for your output raster in your clip e.g.
arcpy.Clip_management(raster, "25.665181 35.812875 44.826408 42.104629", outputPath + "M"+str(raster[1:]), Tr_lyr, "255", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
Here is your code again with the above changes:
# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *
# Setting working directory
arcpy.env.workspace = r"D:\Research\arcgis"
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Local variables:
Tr_pro = "D:\\Tr2009\\admin\\Trpro.shp"
Tr_lyr = "D:\\Tr2009\\admin\\Trlayer"
Tr_dist = "D:\\Tr2009\\admin\\Trdist.shp"
outputPath = "D:\\Tr2009\\admin\\output\\"
arcpy.MakeFeatureLayer_management(Tr_dist, Tr_lyr)
arcpy.SelectLayerByAttribute_management(Tr_lyr, "NEW_SELECTION", "\"Name\" = 'Adi'")
rasterList = arcpy.ListRasters("F*")
for raster in rasterList:
arcpy.Clip_management(raster, "25.665181 35.812875 44.826408 42.104629", outputPath + "M"+str(raster[1:]), Tr_lyr, "255", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
-
Thank you so much. I knew it was a minor thing but could not figure it out from other questions.Bilalce– Bilalce2016年04月25日 17:45:21 +00:00Commented Apr 25, 2016 at 17:45