I am processing 190s HDF files from a Folder (J:\RapidEyr_Atcor\HDF). Here is the example of file name:
Each HDF file contains 13 bands. But I want to extract the first 5 bands from each of HDF file and save as TIFF files in a folder created with [16:46] characters of corresponding HDF file.
Folder and files arrangement as like as below:
I think, first I have to create a output folder and name it with [16:46] characters of one HDF file, then apply arcpy.ExtractSubDataset for selecting the first five bands (0:4) from the corresponding HDF file. And I have to run this process in a loop for all HDF files.
If anyone help me to modify following codes to process all HDF files with batch mode.
- import arcpy
- arcpy.env.workspace = r"J:\RapidEyr_Atcor\HDF"
- rasterListA = arcpy.ListRasters()
- for raster in rasterListA:
- 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")
- print "Extract Subdataset example failed."
- print arcpy.GetMessages()
could you format your code using one of the methods here Code Formatting... the basics++
your indentation is either incorrect or it didn't get carried over during the copy-paste
try: blah blah for bl in blah: blah blah except blah blah
True...but your code won't work since it isn't formatted properly because of indentation issues, which, if run should have generated error messages, and if they did, they would be useful to see. Once, that is fixed, then it is a matter of dissecting the code. tifoutA that should be indented as well, and I presume it is printing out a name but you are using a slice of the input name. Through a print statement in after you have the name to make sure the name is correct. So if you can provide documentation via print statements and error messages that would be great.
I am able to extract bands from HDF, but I have to run three python scripts: (1) First one create folders based on the name of HDF files and import HDF files in respective folders (2) Then 2nd Script extract first 5 bands in folder and (3) 3rd one create a multi-tif file. This there anyway combine three scripts to make one?
I am going post all codes in another threads, Thanks again
Hi Zia, since you put all the info in a different thread and are getting responses, you may want to delete this one so it doesn't remain an unanswered thread. You won't be able to delete it from within your geonet inbox, but should be able to if you open it up Ina new tab (click on the title if going thru the inbox). Thanks.