gp.ExtractByMask_sa(raster, shapefile, newRaster)
import arcgisscripting, os, string gp = arcgisscripting.create() gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.SetProduct("ArcInfo") clip = "D:/hyperspectralImages/torrejon/torrejon_ALI/clip/clip.shp" #the polygon feature class rows = gp.SearchCursor(clip) row = rows.Next() while row: # here I am extracting each polygon to an individual feature class FID = row.GetValue("FID") hoja = row.GetValue("hoja") Expression = '\"FID\" = ' + str(FID) outFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//"+str(hoja)+".shp" #the single fc's will be named after the field "hoja" print "Extracting sheet number "+str(hoja) #like 1.shp, 2.shp...etc gp.Select_analysis(clip,outFeatures,Expression) row=rows.Next() print "Finished extracting individual sheets.Begining to clip..." inputFolder= "D:/hyperspectralImages/torrejon/torrejon_ALI/rasters" #the folder where all the rasters to be clipped are located gp.Workspace = inputFolder rasters = gp.ListRasters() rasters.Reset() raster = rasters.Next() clipFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//" #the folder where the polygon feature classes used for clipping are located while raster: # the loop to clip each raster by each polygon feature class for feature in os.listdir(clipFeatures): if feature.endswith(".shp"): outRaster = "D://hyperspectralImages//torrejon//torrejon_ALI//output//"+feature[0:-3]+".tif" print "Clipping "+raster+" with sheet number "+feature[0:-3] gp.clip_management(raster,"446716,298473 4425996,437405 499153,348855 4492682,68626",outRaster,feature,"255","ClippingGeometry") print "Done"
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.