[gdal-dev] Creating derived raster bands using python

Antonio Valentino antonio.valentino at tiscali.it
Sun Mar 8 16:41:55 EDT 2009


Il giorno Sun, 8 Mar 2009 20:51:46 +0100
Even Rouault <even.rouault at mines-paris.org> ha scritto:

> Antonio,
> 
> There are 2 issues :

[cut]

> - the crash comes from the fact that you don't have defined a pixel
> function for the derived band. I've created ticket 
> http://trac.osgeo.org/gdal/ticket/2877 about that one.

Even, 
I didn't say in previous post but the test.tif actually exists and the
pixel function "module" is defined. I did it via a fake plugin that
registers pixel-functions and then put it in the GDAL_DRIVER_PATH.

If I manually write the VRT file all works well:

$ cat test1.vrt 
<VRTDataset rasterXSize="100" rasterYSize="100">
  <VRTRasterBand dataType="Byte" band="1"
subClass="VRTDeriveDRasterBand"> <Description>Magnitude</Description>
    <PixelFunctionType>module</PixelFunctionType>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">test.tif</SourceFilename>
      <SourceBand>1</SourceBand>
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>

$ gdal_translate test1.vrt out.tif
Input file size is 100, 100
0...10...20...30...40...50...60...70...80...90...100 - done.

I'm just not able to write the VRT file using python.

thanks for help

> Le Sunday 08 March 2009 13:30:05 Antonio Valentino, vous avez écrit :
> > 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