[Gdal-dev] Merging bands (was: pct2rgb.py)
Mario Beauchamp
starged at videotron.ca
Thu Oct 14 19:47:08 EDT 2004
Hi,
On Thu, 14 Oct 2004 14:26:43 -0400, Gillian Walter <gillian.walter at atlantis-scientific.com> wrote:
>Does openev 1.82 include the latest compose.py tool? If it does, I think the
>compose and export tools could also be used to do the merge (load the three
>images up in openev, launch the compose tool, set the three output bands, display
>the result, then run the export tool- it should be able to export the vrt lines
>created by the compose tool). This is more steps than gdal_merge, but avoids the
>command line for those who prefer gui's.
May I suggest a method I added to gvviewwindow.py to merge bands without using the compose tool?
It goes like this:
def open_rgb_gdal_dataset(self, datasets):
import vrtutils
self.make_active()
vrt_opts = vrtutils.VRTCreationOptions(3)
vrt_tree = vrtutils.serializeCombinedDatasets(datasets,vrt_opts)
ds = gdal.OpenShared(gdal.SerializeXMLTree(vrt_tree))
rgbDS = gview.manager.add_dataset(ds)
rgbDS.SetDescription('VRTDataset')
red_raster = gview.manager.get_dataset_raster(rgbDS,1)
green_raster = gview.manager.get_dataset_raster(rgbDS,2)
blue_raster = gview.manager.get_dataset_raster(rgbDS,3)
rgb_layer = gview.GvRasterLayer(red_raster, rl_mode = gview.RLM_RGBA)
rgb_layer.set_source(1,green_raster)
rgb_layer.set_source(2,blue_raster)
rgb_layer.set_name('RGB layer')
self.viewarea.add_layer(rgb_layer)
self.viewarea.set_active_layer(rgb_layer)
self.rawgeo_update()
The resulting VRTDataset can then be exported normally. Note that 2 other methods are needed to open
3 files at once. A dialog for selecting the bands would have been nice but I didn't feel it was
necessary at that time :)
def rgb_open_cb(self, *args):
self.make_active()
dlg = filedlg.FileDialog(dialog_type=filedlg.FILE_OPEN, multiselect = 1 )
dlg.ok_button.connect('clicked', self.rgb_files_open_by_name, dlg)
dlg.show()
def rgb_files_open_by_name(self, widget, dlg, *args):
filenames = dlg.get_filenames()
if len(filenames) != 3:
gvutils.error('3 files needed for band merging')
return
datasets = []
for file in filenames:
datasets.append(gview.manager.get_dataset(file))
self.open_rgb_gdal_dataset(datasets)
Does this procedure look good to you guys? Would it be better to use the new
vrtutils.VRTDatasetConstructor class (great class!) to do this?
Thanks for your attention.
--
Mario B.
More information about the Gdal-dev
mailing list