Skip to content

GDALRasterSource works inconsistenly with BitCellType and ByteCellType #3232

Description

@pomadchin

At this point GDAL CellSize derivation does not take into account bitsPerSample, so it will never derive a BitCellType: https://github.com/locationtech/geotrellis/blob/master/gdal/src/main/scala/geotrellis/raster/gdal/GDALDataset.scala#L308

That is how it is used: https://github.com/locationtech/geotrellis/blob/master/gdal/src/main/scala/geotrellis/raster/gdal/GDALUtils.scala#L44

The proposal is to modify GDALWarp.get_band_data_type function to return not only the sampleFormat but a tuple of sampleFormat and bitsPerSample.

Add the following test into GDALRasterSourceSpec (it fails for the BitCellType now):

    describe("should derive the cellType consistently with GeoTiffRasterSource") {
      val ext = Extent(0.0, 0.0, 3.0, 3.0)
      val data = Array(
        1, 2, 3,
        4, 5, 6,
        7, 8, 9
      )

      List(BitCellType, ByteCellType, UByteCellType, ShortCellType, UShortCellType, IntCellType, FloatCellType, DoubleCellType).map { ct =>
        it(ct.getClass.getName.split("\\$").last.split("\\.").last) {
          val path = s"/tmp/gdal-$ct-test.tiff"
          val raster = Raster(ArrayTile(data, 3, 3).convert(ct), ext)
          GeoTiff(raster, LatLng).write(path)

          GDALRasterSource(path).cellType shouldBe ct
          GeoTiffRasterSource(path).cellType shouldBe ct
        }
      }
    }

P.S. The result of this PR can also be some test that simplifies the derivation function and proofs that we can't make it work consistently for Byte and UByte CellTypes.

P.P.S. it is definitely obvious that we can fix its behavior for the BitCellType

Activity

  1. self-assigned this
    on Apr 22, 2020
  2. changed the title [-]GDALRasterSource works inconsistenly with BitCellType[/-] [+]GDALRasterSource works inconsistenly with BitCellType and ByteCellType[/+] on Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions