Python-based batch image Cropping
When we used IDL to crop images in batches, we found that the cropped image was a rectangle, which could not be completed strictly according to the shape of the image. It is found that PYTHON is really easy to use in batch processing, saving money, and helping code be posted directly. It is also a contribution to the Forum. I don't know what other good methods do you have. Share it. When using can refer to this post http://bbs.esrichina-bj.cn/esri/thread-82776-1-1.html
Import arcgisscripting
Import OS
# Coding = gbk
Gp = arcgisscripting. create (9.3)
Gp. AddToolbox ("G:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools. tbx ")
Gp. CheckOutExtension ("Spatial ")
Ws = OS. getcwd ()
Print ws
Children = OS. listdir (ws)
Files = []
For child in children:
Ext = OS. path. splitext (child) [1]
If (ext = '. img '):
Files. append (child)
Gp. workspace = ws
For file in files:
InMask = "E:/KNN/Export_Output.shp"
S = OS. path. basename (file)
Obj_name = s [8: 15] + '. IMG'
Gp. ExtractByMask_sa (file, InMask, obj_name)
Print files
Print "OK"
I don't know how to paste it into the code format. |