How i can split multi-band raster to separate rasters ?

11053
6
Jump to solution
09-01-2014 02:06 AM
DimitrisPoursanidis
New Contributor III

Hello,

 

Stragling to solve this "easy" task, i have use more than 8 different softwares to solve it (it was solved by using Matlab). Any idea, suggestion on how can this be done via ArcGIS ?

1 Solution

Accepted Solutions
FilipKrál
Occasional Contributor III

Hi Dimitris,

I remember I struggled with this too, but I cannot recall if there is any tool for that. The code below is roughly what I would try. I don't have ArcGIS at hand at the moment to test it, but hopefully any glitches are only minor.

The key is that you can refer to individual bands within a raster dataset by their correct path, just like you can drill down to them in the Catalog directory tree. Usually, bands are called Band_1, Band_2, and so on. The problem is that sometimes they have different names (Layer_1, etc.) The code below deals with this by looping through whatever children the raster has and getting the correct name.

Results (individual raster bands) are stored as individual rasters in the output directory.

import arcpy, os

in_raster = r'c:\path\to\raster.tif' # input multiband raster

out_folder = r'c:\path\to\output\folder' # preferably an empty folder

desc = arcpy.Describe(in_raster)

for band in desc.children:

    bandName = band.name

    band_path = os.path.join(in_raster, bandName)

    dest_path = os.path.join(out_folder, bandName + '.tif')

    arcpy.CopyRaster_management(band_path, dest_path, "", "", "", "NONE", "NONE", "") # change parameters here

I have a feeling there might be a more elegant solution, but if you cannot find it, give this a go. Make sure you change the parameters at row 2,3, and 11, then just paste it into Python window and hit enter. And then enter again.

The code is inspired by 41145 - Add individual raster bands from a multiband raster... and Extract one band from 3 band raster  

Let us know if this works for you, I'd really want to know.

Filip.

View solution in original post

6 Replies
NtriankosIoannis
New Contributor II

hi,

take a look

Kind Regards,

John

0 Kudos
DimitrisPoursanidis
New Contributor III

Thanks but this needs lots of manual work when i have to work with MODIS multiband datasets.

I need just the opposite of the "Compose bands" aka "Decompose Bands".

I find it just only in the Orfeo Toolbox via Monteverdi.

0 Kudos
RiyasDeen
Occasional Contributor III

Hi Dimitris,

you need Extract Subdataset.

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

0 Kudos
DimitrisPoursanidis
New Contributor III
  • Subdataset file formats can be either Hierarchical Data Format (HDF) or National Imagery Transmission Format (NITF) files

So no lack with GEOTIFF.

No other format will work (and i test it).

0 Kudos
FilipKrál
Occasional Contributor III

Hi Dimitris,

I remember I struggled with this too, but I cannot recall if there is any tool for that. The code below is roughly what I would try. I don't have ArcGIS at hand at the moment to test it, but hopefully any glitches are only minor.

The key is that you can refer to individual bands within a raster dataset by their correct path, just like you can drill down to them in the Catalog directory tree. Usually, bands are called Band_1, Band_2, and so on. The problem is that sometimes they have different names (Layer_1, etc.) The code below deals with this by looping through whatever children the raster has and getting the correct name.

Results (individual raster bands) are stored as individual rasters in the output directory.

import arcpy, os

in_raster = r'c:\path\to\raster.tif' # input multiband raster

out_folder = r'c:\path\to\output\folder' # preferably an empty folder

desc = arcpy.Describe(in_raster)

for band in desc.children:

    bandName = band.name

    band_path = os.path.join(in_raster, bandName)

    dest_path = os.path.join(out_folder, bandName + '.tif')

    arcpy.CopyRaster_management(band_path, dest_path, "", "", "", "NONE", "NONE", "") # change parameters here

I have a feeling there might be a more elegant solution, but if you cannot find it, give this a go. Make sure you change the parameters at row 2,3, and 11, then just paste it into Python window and hit enter. And then enter again.

The code is inspired by 41145 - Add individual raster bands from a multiband raster... and Extract one band from 3 band raster  

Let us know if this works for you, I'd really want to know.

Filip.

DimitrisPoursanidis
New Contributor III

And yes, it work Filip.

Now i will try to put it in a toolbox.

So simple functions and yet are not included in the default tools (not only in arc but also in envi, erdas). Only QGIS via SEXTANTE and link to Orfeo Toolbox have such capability.

0 Kudos