Skip to content

Commit

Permalink
Add Int8 GDAL 3.7+ support
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed May 15, 2024
1 parent 4f14df9 commit 1f35c0f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
scala: ["2.12.19", "2.13.14"]
java: ["11", "21"]
java: ["11"] # "21"
runs-on: ubuntu-latest

env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ class GDALRasterSummarySpec extends AnyFunSpec with TestEnvironment with GivenWh
contextRDD.stitch().tile.band(0).renderPng().write("/tmp/raster-source-contextrdd-gdal.png")
}

it("Should cleanup GDAL Datasets by the end of the loop (10 iterations)") {
it("should cleanup GDAL Datasets by the end of the loop (10 iterations)") {
val inputPath = gdalGeoTiffPath("vlm/aspect-tiled.tif")
val targetCRS = WebMercator
val method = Bilinear
val layout = LayoutDefinition(GridExtent[Int](Extent(-2.0037508342789244E7, -2.0037508342789244E7, 2.0037508342789244E7, 2.0037508342789244E7), CellSize(9.554628535647032, 9.554628535647032)), 256)
val RasterExtent(Extent(exmin, eymin, exmax, eymax), ecw, ech, ecols, erows) = RasterExtent(Extent(-8769161.632988561, 4257685.794912352, -8750616.09900087, 4274482.8318780195), CellSize(9.554628535647412, 9.554628535646911))
val RasterExtent(Extent(exmin, eymin, exmax, eymax), ecw, ech, ecols, erows) = RasterExtent(Extent(-8769161.632988561, 4257685.794912352, -8750625.653629405, 4274473.277249484), CellSize(9.554628535647032,9.554628535647032))

cfor(0)(_ < 11, _ + 1) { _ =>
val reference = GDALRasterSource(inputPath).reproject(targetCRS, method = method).tileToLayout(layout, method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object GDALDataType {
List(
UnknownType,
TypeByte,
TypeInt8,
TypeUInt16,
TypeInt16,
TypeUInt32,
Expand Down Expand Up @@ -50,9 +51,13 @@ abstract sealed class GDALDataType(val code: Int) {
def toString: String = code.toString
}

// https://github.com/geotrellis/gdal-warp-bindings/blob/9d75e7c65c4c8a0c2c39175a75656bba458a46f0/src/main/java/com/azavea/gdal/GDALWarp.java#L26-L38
// https://github.com/geotrellis/gdal-warp-bindings/blob/v3.8.0/src/main/java/com/azavea/gdal/GDALWarp.java#L29-L41
// https://github.com/OSGeo/gdal/blob/v3.8.5/swig/include/gdal.i#L148-L165
// https://github.com/OSGeo/gdal/blob/9b9d3e35deba4c41e5b07558817a0569c937490d/frmts/gtiff/gtiffrasterband.cpp#L59C30-L59C46
// https://github.com/search?q=repo%3AOSGeo%2Fgdal%20SAMPLEFORMAT_INT&type=code
case object UnknownType extends GDALDataType(GDALWarp.GDT_Unknown)
case object TypeByte extends GDALDataType(GDALWarp.GDT_Byte)
case object TypeInt8 extends GDALDataType(14)
case object TypeUInt16 extends GDALDataType(GDALWarp.GDT_UInt16)
case object TypeInt16 extends GDALDataType(GDALWarp.GDT_Int16)
case object TypeUInt32 extends GDALDataType(GDALWarp.GDT_UInt32)
Expand Down
10 changes: 10 additions & 0 deletions gdal/src/main/scala/geotrellis/raster/gdal/GDALUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ object GDALUtils {
case _ => ByteCellType
}
}
case TypeInt8 =>
typeSizeInBits match {
case Some(bits) if bits == 1 => BitCellType
case _ =>
noDataValue match {
case Some(nd) if nd.toInt > Byte.MinValue.toInt && nd <= Byte.MaxValue.toInt => ByteUserDefinedNoDataCellType(nd.toByte)
case Some(nd) if nd.toInt == Byte.MinValue.toInt => ByteConstantNoDataCellType
case _ => ByteCellType
}
}
case TypeUInt16 =>
noDataValue match {
case Some(nd) if nd.toInt > 0 && nd <= 65535 => UShortUserDefinedNoDataCellType(nd.toShort)
Expand Down
Binary file modified gdal/src/test/resources/vlm/aspect-tiled-bilinear-linux.tif
Binary file not shown.
Binary file modified gdal/src/test/resources/vlm/aspect-tiled-near-merc-rdd.tif
Binary file not shown.
Binary file modified gdal/src/test/resources/vlm/aspect-tiled-near.tif
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class GDALReprojectRasterSourceSpec extends AnyFunSpec with RasterMatchers with
val uri = Resource.path("vlm/aspect-tiled.tif")

/**
* For some reasons, the Pipeline described above is OS specific,
* and Bilinear interpolation behaves differently.
* For some reason, the Pipeline described above is OS specific, and Bilinear interpolation behaves differently.
* To make tests pass there was generated one bilinear version under mac and anther inside a linux container.
* This test may require tiffs regeneration since resample method slightly changes with different the GDAL version change.
*
* TODO: investigate the nature of this bug later
* */
Expand Down
4 changes: 2 additions & 2 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ object Settings {
Test / fork := true,
Test / parallelExecution := false,
Test / testOptions += Tests.Argument("-oDF"),
javaOptions ++= Seq("-Djava.library.path=/usr/lib:/usr/local/lib")
// javaOptions ++= Seq("-Djava.library.path=/usr/lib:/usr/local/lib")
) ++ commonSettings

lazy val `gdal-spark` = Seq(
Expand All @@ -647,6 +647,6 @@ object Settings {
Test / fork := true,
Test / parallelExecution := false,
Test / testOptions += Tests.Argument("-oDF"),
javaOptions ++= Seq("-Djava.library.path=/usr/lib:/usr/local/lib")
// javaOptions ++= Seq("-Djava.library.path=/usr/lib:/usr/local/lib")
) ++ commonSettings
}

0 comments on commit 1f35c0f

Please sign in to comment.