[gdal-dev] Creating derived raster bands using python

Antonio Valentino antonio.valentino at tiscali.it
Sun Mar 8 08:30:05 EDT 2009


Il giorno Thu, 05 Mar 2009 09:26:51 -0500
Frank Warmerdam <warmerdam at pobox.com> ha scritto:

> Antonio Valentino wrote:
> > Hi list,
> > I'm trying to create a *Derived* raster band in a virtual dataset.
> > 
> > All my attempts seems to fail:
> > 
> >>>> ds.AddBand(options={'subClass': 'VRTDerivedRasterBand'})
> > 
> > raises an exception while
> > 
> >>>> ds.AddBand(options='subClass="VRTDerivedRasterBand"')
> >>>> ds.AddBand(options=['subClass="VRTDerivedRasterBand"'])
> 
> Antonio,
> 
> I believe the correct syntax is:
> 
>    ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> 
> The options should be a list of name=value pairs.  Your extra double
> quotes within the string will make the class name comparison fail
> since you are effectively passing "\"VRTDerivedRasterBand\"" in C
> terms.
> 
> Best regards,

Hi Frank,
thanks for helping.

I'm still having problems trying to create a derived raster bands via
python.
I'm using Ubuntu 8.10

$ uname -a
Linux mac1 2.6.27-13-generic #1 SMP Thu Feb 26 07:31:49 UTC 2009 x86_64
GNU/Linux

with GDAL 1.5.4 package from UbuntuGIS repo
(python-gdal_1.5.4-2~intreid3).

The execution of the following test script produces a segmentation
fault:

### BEGIN CODE
from osgeo import gdal
driver = gdal.GetDriverByName('VRT')
source_xml = '''<SimpleSource>
  <SourceFilename relativeToVRT="1">test.tif</SourceFilename>
</SimpleSource>'''

md = {'Description': 'Magnitude', 'PixelFunctionType': 'module',
'source_0': source_xml}

ds = driver.Create('test.vrt', 100, 100)
b = ds.GetRasterBand(1)
b.SetMetadata({'source_0': source_xml}, 'new_vrt_sources')
ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
b = ds.GetRasterBand(2)
b.SetMetadata(md, 'new_vrt_sources')
del ds
print open('test.vrt').read()
### END CODE

$ python test_derivedband.py
ERROR 1: Corrupt or empty VRT source XML document.
Segmentation fault


Maybe I'm still doing something wrong but the segfault is anomalous in
any case.

Should I create a ticket for this?


Regards

-- 
Antonio Valentino


More information about the gdal-dev mailing list