<div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px">i'm trying to perfom a pansharpening process using the gdal_pansharpen tool.</div><div style="font-size:12.8px">I used the following code:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'Courier New'"><span style="color:rgb(128,128,128);font-style:italic">#!/usr/bin/env python<br></span><span style="color:rgb(128,128,128);font-style:italic"># -*- coding: utf-8 -*-<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(0,0,128);font-weight:bold">import </span>sys, os<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>osgeo <span style="color:rgb(0,0,128);font-weight:bold">import </span>gdal<br><br><span style="color:rgb(0,0,128);font-weight:bold">def </span>Usage():<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'Usage: gdal_pansharpen [--help-general] pan_dataset {spectral_dataset[,band=num]}+ out_dataset'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'                       [-of format] [-b band]* [-w weight]*'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'                       [-r {nearest,bilinear,cubic,cubicspline,lanczos,average}]'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'                       [-threads {ALL_CPUS|number}] [-bitdepth val] [-nodata val]'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'                       [-spat_adjust {union,intersection,none,nonewithoutwarning}]'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'                       [-verbose_vrt] [-co NAME=VALUE]* [-q]'</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">''</span>)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'Create a dataset resulting from a pansharpening operation.'</span>)<br>    <span style="color:rgb(0,0,128);font-weight:bold">return </span>-<span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,128);font-weight:bold">def </span>gdal_pansharpen(argv):<br><br>    argv = gdal.GeneralCmdLineProcessor( argv )<br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>argv <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>        <span style="color:rgb(0,0,128);font-weight:bold">return </span>-<span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)">    </span>pan_name = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>last_name = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>spectral_ds = []<br>    spectral_bands = []<br>    <span style="color:rgb(128,128,128)">out_name </span>= <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>bands = []<br>    weights = []<br>    format = <span style="color:rgb(0,128,128);font-weight:bold">'VRT'<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span>creation_options = []<br>    callback = gdal.TermProgress<br>    resampling = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>spat_adjust = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>verbose_vrt = <span style="color:rgb(0,0,128);font-weight:bold">False<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>num_threads = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>bitdepth = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>nodata = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold"><br></span><span style="color:rgb(0,0,128);font-weight:bold">    </span>i = <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">    </span>argc = <span style="color:rgb(0,0,128)">len</span>(argv)<br>    <span style="color:rgb(0,0,128);font-weight:bold">while </span>i < argc:<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-of' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            format = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"format " </span>+ format)<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-r' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            resampling = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"resampling " </span>+ resampling)<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-spat_adjust' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            spat_adjust = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-b' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            bands.append(<span style="color:rgb(0,0,128)">int</span>(argv[i+<span style="color:rgb(0,0,255)">1</span>]))<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-w' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            weights.append(<span style="color:rgb(0,0,128)">float</span>(argv[i+<span style="color:rgb(0,0,255)">1</span>]))<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-co' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            creation_options.append(argv[i+<span style="color:rgb(0,0,255)">1</span>])<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-threads' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            num_threads = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-bitdepth' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            bitdepth = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-nodata' </span><span style="color:rgb(0,0,128);font-weight:bold">and </span>i < <span style="color:rgb(0,0,128)">len</span>(argv)-<span style="color:rgb(0,0,255)">1</span>:<br>            nodata = argv[i+<span style="color:rgb(0,0,255)">1</span>]<br>            i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-q'</span>:<br>            callback = <span style="color:rgb(0,0,128);font-weight:bold">None<br></span><span style="color:rgb(0,0,128);font-weight:bold">        elif </span>argv[i] == <span style="color:rgb(0,128,128);font-weight:bold">'-verbose_vrt'</span>:<br>            verbose_vrt = <span style="color:rgb(0,0,128);font-weight:bold">True<br></span><span style="color:rgb(0,0,128);font-weight:bold">        elif </span>argv[i][<span style="color:rgb(0,0,255)">0</span>] == <span style="color:rgb(0,128,128);font-weight:bold">'-'</span>:<br>            sys.stderr.write(<span style="color:rgb(0,128,128);font-weight:bold">'Unrecognized option : %s</span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% argv[i])<br>            <span style="color:rgb(0,0,128);font-weight:bold">return </span>Usage()<br>        <span style="color:rgb(0,0,128);font-weight:bold">elif </span>pan_name <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>            pan_name = argv[i]<br>            pan_ds = gdal.Open(pan_name)<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>pan_ds <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>                <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">else</span>:<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>last_name <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>                pos = last_name.find(<span style="color:rgb(0,128,128);font-weight:bold">',band='</span>)<br>                <span style="color:rgb(0,0,128);font-weight:bold">if </span>pos > <span style="color:rgb(0,0,255)">0</span>:<br>                    spectral_name = last_name[<span style="color:rgb(0,0,255)">0</span>:pos]<br>                    ds = gdal.Open(spectral_name)<br>                    <span style="color:rgb(0,0,128);font-weight:bold">if </span>ds <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>                        <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">                    </span>band_num = <span style="color:rgb(0,0,128)">int</span>(last_name[pos+<span style="color:rgb(0,0,128)">len</span>(<span style="color:rgb(0,128,128);font-weight:bold">',band='</span>):])<br>                    band = ds.GetRasterBand(band_num)<br>                    spectral_ds.append(ds)<br>                    spectral_bands.append(band)<br>                <span style="color:rgb(0,0,128);font-weight:bold">else</span>:<br>                    spectral_name = last_name<br>                    ds = gdal.Open(spectral_name)<br>                    <span style="color:rgb(0,0,128);font-weight:bold">if </span>ds <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>                        <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">                    </span><span style="color:rgb(0,0,128);font-weight:bold">for </span>j <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(ds.RasterCount):<br>                        spectral_ds.append(ds)<br>                        spectral_bands.append(ds.GetRasterBand(j+<span style="color:rgb(0,0,255)">1</span>))<br><br>            last_name = argv[i]<br><br>        i = i + <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span>pan_name <span style="color:rgb(0,0,128);font-weight:bold">is None or </span><span style="color:rgb(0,0,128)">len</span>(spectral_bands) == <span style="color:rgb(0,0,255)">0</span>:<br>        <span style="color:rgb(0,0,128);font-weight:bold">return </span>Usage()<br>    out_name = last_name<br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">len</span>(bands) == <span style="color:rgb(0,0,255)">0</span>:<br>        bands = [ j+<span style="color:rgb(0,0,255)">1 </span><span style="color:rgb(0,0,128);font-weight:bold">for </span>j <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(spectral_bands)) ]<br>    <span style="color:rgb(0,0,128);font-weight:bold">else</span>:<br>        <span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(bands)):<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>bands[i] < <span style="color:rgb(0,0,255)">0 </span><span style="color:rgb(0,0,128);font-weight:bold">or </span>bands[i] > <span style="color:rgb(0,0,128)">len</span>(spectral_bands):<br>                <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'Invalid band number in -b: %d' </span>% bands[i])<br>                <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">len</span>(weights) != <span style="color:rgb(0,0,255)">0 </span><span style="color:rgb(0,0,128);font-weight:bold">and </span><span style="color:rgb(0,0,128)">len</span>(weights) != <span style="color:rgb(0,0,128)">len</span>(spectral_bands):<br>        <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'There must be as many -w values specified as input spectral bands'</span>)<br>        <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)"><br></span><span style="color:rgb(0,0,255)">    </span>vrt_xml = <span style="color:rgb(0,128,128);font-weight:bold">"""<VRTDataset subClass="VRTPansharpenedDataset"></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span>bands != [ j+<span style="color:rgb(0,0,255)">1 </span><span style="color:rgb(0,0,128);font-weight:bold">for </span>j <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(spectral_bands)) ]:<br>        <span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(bands)):<br>            band = spectral_bands[bands[i]-<span style="color:rgb(0,0,255)">1</span>]<br>            datatype = gdal.GetDataTypeName(band.DataType)<br>            colorname = gdal.GetColorInterpretationName(band.GetColorInterpretation())<br>            vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""  <VRTRasterBand dataType="%s" band="%d" subClass="VRTPansharpenedRasterBand"><br></span><span style="color:rgb(0,128,128);font-weight:bold">      <ColorInterp>%s</ColorInterp><br></span><span style="color:rgb(0,128,128);font-weight:bold">  </VRTRasterBand></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">""" </span>% (datatype, i+<span style="color:rgb(0,0,255)">1</span>, colorname)<br><br>    vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""  <PansharpeningOptions></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span><span style="color:rgb(0,0,128)">len</span>(weights) != <span style="color:rgb(0,0,255)">0</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""      <AlgorithmOptions></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">        </span>vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""        <Weights>"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">        </span><span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(weights)):<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>i > <span style="color:rgb(0,0,255)">0</span>: vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">","<br></span><span style="color:rgb(0,128,128);font-weight:bold">            </span>vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"%.16g" </span>% weights[i]<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"</Weights></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"<br></span><span style="color:rgb(0,128,128);font-weight:bold">        </span>vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""      </AlgorithmOptions></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold"><br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span>resampling <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">'      <Resampling>%s</Resampling></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% resampling<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>num_threads <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">'      <NumThreads>%s</NumThreads></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% num_threads<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>bitdepth <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">'      <BitDepth>%s</BitDepth></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% bitdepth<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>nodata <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">'      <NoData>%s</NoData></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% nodata<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>spat_adjust <span style="color:rgb(0,0,128);font-weight:bold">is not None</span>:<br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">'      <SpatialExtentAdjustment>%s</SpatialExtentAdjustment></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">' </span>% spat_adjust<br><br>    pan_relative=<span style="color:rgb(0,128,128);font-weight:bold">'0'<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span><span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">"panname: "</span>+pan_name)<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,0,128)">str</span>(os.path.isabs(pan_name)))<br>    <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,0,128)">str</span>(os.path.relpath(pan_name, os.path.dirname(out_name))))<br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>format.upper() == <span style="color:rgb(0,128,128);font-weight:bold">'VRT'</span>:<br>        <span style="color:rgb(0,0,128);font-weight:bold">if not </span>os.path.isabs(pan_name):<br>            pan_relative=<span style="color:rgb(0,128,128);font-weight:bold">'1'<br></span><span style="color:rgb(0,128,128);font-weight:bold">            </span>pan_name = os.path.relpath(pan_name, os.path.dirname(out_name))<br><br>    vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""    <PanchroBand><br></span><span style="color:rgb(0,128,128);font-weight:bold">      <SourceFilename relativeToVRT="%s">%s</SourceFilename><br></span><span style="color:rgb(0,128,128);font-weight:bold">      <SourceBand>1</SourceBand><br></span><span style="color:rgb(0,128,128);font-weight:bold">    </PanchroBand></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">""" </span>% (pan_relative, pan_name)<br>    <span style="color:rgb(0,0,128)">print</span>(vrt_xml)<br>    <span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(spectral_bands)):<br>        dstband = <span style="color:rgb(0,128,128);font-weight:bold">''<br></span><span style="color:rgb(0,128,128);font-weight:bold">        </span><span style="color:rgb(0,0,128);font-weight:bold">for </span>j <span style="color:rgb(0,0,128);font-weight:bold">in </span><span style="color:rgb(0,0,128)">range</span>(<span style="color:rgb(0,0,128)">len</span>(bands)):<br>            <span style="color:rgb(0,0,128);font-weight:bold">if </span>i + <span style="color:rgb(0,0,255)">1 </span>== bands[j]:<br>                dstband = <span style="color:rgb(0,128,128);font-weight:bold">' dstBand="%d"' </span>% (j+<span style="color:rgb(0,0,255)">1</span>)<br>                <span style="color:rgb(0,0,128);font-weight:bold">break<br></span><span style="color:rgb(0,0,128);font-weight:bold"><br></span><span style="color:rgb(0,0,128);font-weight:bold">        </span>ms_relative=<span style="color:rgb(0,128,128);font-weight:bold">'0'<br></span><span style="color:rgb(0,128,128);font-weight:bold">        </span>ms_name = spectral_ds[i].GetDescription()<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>format.upper() == <span style="color:rgb(0,128,128);font-weight:bold">'VRT'</span>:<br>            <span style="color:rgb(0,0,128);font-weight:bold">if not </span>os.path.isabs(ms_name):<br>                ms_relative=<span style="color:rgb(0,128,128);font-weight:bold">'1'<br></span><span style="color:rgb(0,128,128);font-weight:bold">                </span>ms_name = os.path.relpath(ms_name, os.path.dirname(out_name))<br><br>        vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""    <SpectralBand%s><br></span><span style="color:rgb(0,128,128);font-weight:bold">      <SourceFilename relativeToVRT="%s">%s</SourceFilename><br></span><span style="color:rgb(0,128,128);font-weight:bold">      <SourceBand>%d</SourceBand><br></span><span style="color:rgb(0,128,128);font-weight:bold">    </SpectralBand></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">""" </span>% (dstband, ms_relative, ms_name, spectral_bands[i].GetBand())<br><br>    vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""  </PansharpeningOptions></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span>vrt_xml += <span style="color:rgb(0,128,128);font-weight:bold">"""</VRTDataset></span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">    </span><span style="color:rgb(0,0,128);font-weight:bold">if </span>format.upper() == <span style="color:rgb(0,128,128);font-weight:bold">'VRT'</span>:<br>        f = gdal.VSIFOpenL(out_name, <span style="color:rgb(0,128,128);font-weight:bold">'wb'</span>)<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>f <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>            <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(0,128,128);font-weight:bold">'Cannot create %s' </span>% out_name)<br>            <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span>gdal.VSIFWriteL(vrt_xml, <span style="color:rgb(0,0,255)">1</span>, <span style="color:rgb(0,0,128)">len</span>(vrt_xml), f)<br>        gdal.VSIFCloseL(f)<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>verbose_vrt:<br>            vrt_ds = gdal.Open(out_name, gdal.GA_Update)<br>            vrt_ds.SetMetadata(vrt_ds.GetMetadata())<br>        <span style="color:rgb(0,0,128);font-weight:bold">else</span>:<br>            vrt_ds = gdal.Open(out_name)<br>        <span style="color:rgb(0,0,128);font-weight:bold">if </span>vrt_ds <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>            <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">    </span>vrt_ds = gdal.Open(vrt_xml)<br>    out_ds = gdal.GetDriverByName(format).CreateCopy(out_name, vrt_ds, <span style="color:rgb(0,0,255)">0</span>, creation_options, <span style="color:rgb(102,0,153)">callback </span>= callback)<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>out_ds <span style="color:rgb(0,0,128);font-weight:bold">is None</span>:<br>        <span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">    </span><span style="color:rgb(0,0,128);font-weight:bold">return </span><span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,128);font-weight:bold">def </span>main():<br>    <span style="color:rgb(0,0,128);font-weight:bold">return </span>gdal_pansharpen(sys.argv)<br><br><span style="color:rgb(0,0,128);font-weight:bold">if </span>__name__ == <span style="color:rgb(0,128,128);font-weight:bold">'__main__'</span>:<br>    sys.exit(gdal_pansharpen(sys.argv))</pre><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'Courier New'"><br></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:'Courier New'"><span style="color:rgb(36,39,41);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;font-size:15px;line-height:19.5px;white-space:normal">My input file is a 7 bands geotiff file and the band 8 of an Landsat8 images.</span><br></pre><pre style="white-space:pre-wrap"><p style="color:rgb(36,39,41);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;line-height:19.5px;white-space:normal">If i use the script as follow:</p><pre style="white-space:pre-wrap;color:rgb(57,51,24);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;word-wrap:normal;background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">gdal_pansharpen panchro</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">.</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">tif multispectral</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">.</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">tif pansharpend_output</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">.</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">tif</span></code></pre><p style="color:rgb(36,39,41);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;line-height:19.5px;white-space:normal">it returns with this error:</p><pre style="white-space:pre-wrap;color:rgb(57,51,24);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;word-wrap:normal;background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">ERROR </span><span style="margin:0px;padding:0px;border:0px;color:rgb(107,41,27)">1</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">:</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(43,145,175)">Missing</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)"> one of rasterXSize</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">,</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)"> rasterYSize </span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,139)">or</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)"> bands on </span><span style="margin:0px;padding:0px;border:0px;color:rgb(43,145,175)">VRTDataset</span><span style="margin:0px;padding:0px;border:0px;color:rgb(24,26,28)">.</span></code></pre><p style="color:rgb(36,39,41);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;line-height:19.5px;white-space:normal">I undestrand that the problem is the bands on the VRTDataset but for now i didn't find any solutions.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px;white-space:normal">I thank you in advance for any suggestions.<br></span></font></p><p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px;white-space:normal">Thank you,</span></font></p><p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px;white-space:normal">Lorenzo Bernardi</span></font></p></pre></div><span class="" style="font-size:12.8px"><font color="#888888"><div><br></div>-- <br><div><div dir="ltr"><pre cols="72" style="white-space:pre-wrap">Lorenzo Bernardi</pre></div></div></font></span><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><pre cols="72" style="white-space:pre-wrap;color:rgb(136,136,136)">Lorenzo Bernardi

<br></pre></div></div></div>