Python API Work with multiple Bands - 52North/IlwisCore GitHub Wiki
Not all of your RasterCoverages will consist of only one band of data. IlwisObjects of course also supports the work with multiple bands.
Therefore it works with indexes, which are assigned unique to every band. By default the bands will be labelled iwth interger numbers starting at 0. You can get a list of all available indexes by using the method .indexValues() on your coverage.
#loading RasterCoverage with 12 bands (one for every month)
rc = RasterCoverage("average_monthly_temperature.mpl")
# print all the available indexes, in this case 0,...,11
print(rc.indexValues())
Index Domain
IlwisObjects also offers you the possibility to use other values than integer numbers as indexes. The method .indexDomain(), which is connected to the RasterCoverage, lets you set a new domain for indexes and so define which values will be valid. You can find more about domains in this part of the wiki.
However, it is not advised to change the index domain of an existing coverage, as this will mess up the existing indexes. That is why, if you want a coverage with a special index domain, you should always create a new RasterCoverage and fill it with bands.
Access single Bands
If you just want to analyze a single band of a multiband raster you can simply call the method .band() on it and pass it the index of the band you want access. It will then return a PixelIterator, whose box is set exactly to the pixels of this band and whose position is right at the start of the band. You can read more on PixelIterators in this part of the wiki.
#loading RasterCoverage with 12 bands (one for every month)
rc = RasterCoverage("average_monthly_temperature.mpl")
#accessing the data for march, index number 2
march = rc.band(2)
Add new bands
Adding new bands is almost as simple as accessing bands, all you need is the method .addBand(). Next you need to know which index the new band will have. It should be according to the once that are already in the raster and thus be in sync with the index domain that is set. If you create a completely new raster you can of course choose your own index domain and indexes.
Besides the index you also need a PixelIterator that you can pass to the addBand() function. It should include all the data you want to add and be set to the beginning of its box. If the iterator is already at the end it won't be able to add the data.
Example for adding to an existing coverage:
#loading RasterCoverage with 12 bands (one for every month)
rc = RasterCoverage("average_monthly_temperature.mpl")
#get the band of may
may = rc.band(4)
#make a new RasterCoverage with the data from april
rcapril = RasterCoverage("average_monthly_temperature_april_1.mpr")
# add the may data as second band to the april coverage
rcapril.addBand(1, may)
Example for making a new coverage with time domain:
#loading RasterCoverage with 12 bands (one for every month)
rc = RasterCoverage("average_monthly_temperature.mpl")
#get the band of may
may = rc.band(4)
#make a new time interval and time domain
interval = TimeInterval(date(2012, 1, 1), date(2012, 12, 31))
timeDom = TimeDomain(interval)
# create a new and empty RasterCoverage
newRc = RasterCoverage()
# set the index domain of the coverage to the timedomain
newRc.indexDomain(timeDom)
# add a new Band with date in may and the data from may
newRc.addBand(date(2012, 5, 9), may)