0

I have a query regarding the best way to process the multispectral data I requested to be collected for my MSc study site.

The data I am working with has been saved as single band tiffs, rather than as multiband ones. They are named as follows.

1454327096.tif = Green band 1454327096_1.tif = Red band 1454327096_2.tif = Red_edge band 1454327096_3.tif = NIR band

I have about 1084 of these images so I would like to find some way of automating the process of compositing the bands.

My thought was to use an iterator in modelbuilder in ArcGIS. However I have no idea how to get the iterator to group files together and only composite the ones where the file names are the same.

4
  • Please ask only one question per Question.
    – Vince
    Commented Feb 3, 2016 at 15:11
  • Sorry about that. Fixed it. :) Commented Feb 3, 2016 at 15:14
  • Just to clarify you say you have 1084 images and each image is made up of 3 separate bands, so you have 3,252 files altogether? How are they organized? Are they dumped into 1 folder or organized in some way?
    – Hornbydd
    Commented Feb 3, 2016 at 23:18
  • Hi, Sorry I don't think I explained it very well. Each Image is a single band and I would like to composite them into multiband tiffs. so I would like to go from having 1084 single band images down to 271 4 band images. They are all dumped into one image folder and are organised according to the file name, where the underscore value denotes which band of the final composite image each tiff belongs to. Commented Feb 5, 2016 at 6:53

1 Answer 1

1

If they're all in one folder, you can probably use a combination os.walk or os.listdir and fnmatch (wildcard) in a python script such as below.

rootDir = "folder path to files"
outDir = "output directory
outName = "Output File Name"
search = "wildcard, whatever is unique to the file name"

tiffLst = [] # get a list of tiffs in the folder
    for root, dir, files in os.walk(rootDir)
        for filename in fnmatch.filder(files, search):
            tiffLst.append(os.path.join(root, filename))

if tiffLst:
    outTiff = os.path.join(outDir) + outName)

Here is where I would get stuck, not entirely sure which function to use in order to merge them together, but this will at least be a good start to walking the directory tree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.