Hi,
In my previous post, the problem I mentioned I have solved it using following three python scripts. Is there anyway to combine theses three scripts to make one?
Zia
# -----------------------------------------------
# Script_01: Create folders with file name
# Zia Ahmed
# ------------------------------------------------
try:
import glob, os, shutil
folder = r"J:\RapidEyr_Atcor\test\HDF"
for file_path in glob.glob(os.path.join(folder, '*.*')):
new_dir = file_path.rsplit('.', 1)[0]
os.mkdir(os.path.join(folder, new_dir))
shutil.move(file_path, os.path.join(new_dir, os.path.basename(file_path)))
except:
print "Folder creation failed."
print arcpy.GetMessages()# ---------------------------------------------------------------------------
# Script_02: Import HDF file as TIFF
# Description: Extract HDF to geotiff
# Zia Ahmed
# ---------------------------------------------------------------------------
try:
import arcpy
arcpy.env.workspace = r"J:\RapidEyr_Atcor\test\HDF"
# list all folders in a directory
folders = arcpy.ListWorkspaces()
for folder in folders:
arcpy.env.workspace = folder
rasterListA = arcpy.ListRasters()
for raster in rasterListA:
tifOutA=""+raster[15:46]
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B1"+".tif", "0")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B2"+".tif", "1")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B3"+".tif", "2")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B4"+".tif", "3")
arcpy.ExtractSubDataset_management(raster,tifOutA+"_B5"+".tif", "4")
except:
print "Extract Subdataset failed."
print arcpy.GetMessages()
#--------------------------------------------------
# Scrit_03: Batch processing - Stack RapidEyes bands
# Written by Zia Ahmed, CIMMYT, Bangladeash
#--------------------------------------------------
try:
import arcpy, os
# Define working folder
arcpy.env.workspace = r'J:\RapidEyr_Atcor\test\HDF'
# list all folders in a directory
folders = arcpy.ListWorkspaces()
for folder in folders:
arcpy.env.workspace = folder
# Create a raster list
rasters = arcpy.ListRasters("*.tif")
# output file name
name = os.path.join(rasters[1].split("_")[1] +"_multi"+ ".tif")
arcpy.CompositeBands_management(rasters, name)
except:
print "Multiband failed."
print arcpy.GetMessages()