HUBDSM API: provide Raster.saveAsVrt methode for storing the Raster specification as VRT Raster

Issue #414 resolved
Andreas Janz created an issue

(requested by @Benjamin Jakimow )

Comments (4)

  1. Andreas Janz reporter

    @Benjamin Jakimow the GDAL Mask Band concept is too restrictive, because it only supports a single mask for all the bands.

    MaskBand: (GDAL >= 1.8.0) This element represents a mask band that is shared between all bands on the dataset (see GMF_PER_DATASET in RFC 15). It must contain a single VRTRasterBand child element, that is the description of the mask band itself.

    So, for now, I will skip band masks when saving as VRT.

  2. Andreas Janz reporter

    HUBDSM Raster specification can now be saved as GDAL VRT.

    So let’s for example use some EnMAP and HyMap bands:

    # use first three bands of EnMAP and the tree RGB bands from HyMap
    enmapRaster = Raster.open(enmap).select([1,2,3])
    hiresRaster = Raster.open(hires)
    

    Do some stuff with them, e.g. i) stack bands together, ii) reverse the order and iii) use 10m resolution instead of EnMAP’s 30m:

    # stack bands together
    stack = enmapRaster.addBands(hiresRaster)
    
    # reverse bands
    stack = stack[::-1]
    
    # use EnMAP grid at 10m resolution
    grid = enmapRaster.grid.withResolution(resolution=Resolution(x=10, y=10))
    stack = stack.withGrid(grid=grid)
    

    Finally, save it as a VRT to disk:

    # save as VRT
    vrt = stack.saveAsVrt(filename=r'stack.vrt')
    

    Check if VRT has all the specified infos:

    # print some infos
    print(vrt.grid.resolution)
    for band in vrt.bands:
        print(band.name)
        print(f'  NoDataValue: {band.noDataValue}')
        print(f'  NumpyDataType: {GDALTypeCodeToNumericTypeCode(band.gdalBand.gdalDataType)}')
    

    Print:

    Resolution(x=10.0, y=10.0)
    Blue
      NoDataValue: 0.0
      NumpyDataType: <class 'numpy.uint8'>
    Green
      NoDataValue: 0.0
      NumpyDataType: <class 'numpy.uint8'>
    Red
      NoDataValue: 0.0
      NumpyDataType: <class 'numpy.uint8'>
    band 10 (0.470000 Micrometers)
      NoDataValue: -99.0
      NumpyDataType: <class 'numpy.int16'>
    band 9 (0.465000 Micrometers)
      NoDataValue: -99.0
      NumpyDataType: <class 'numpy.int16'>
    band 8 (0.460000 Micrometers)
      NoDataValue: -99.0
      NumpyDataType: <class 'numpy.int16'>
    

  3. Log in to comment