Skip to content

Commit

Permalink
constanttile fix: integrate remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Oct 10, 2024
1 parent 2cc473a commit 1a8adc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
30 changes: 12 additions & 18 deletions raster/src/main/scala/geotrellis/raster/ConstantTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import geotrellis.vector.Extent
import java.nio.ByteBuffer
import spire.syntax.cfor._

import java.lang


/**
* The trait underlying constant tile types.
Expand Down Expand Up @@ -83,21 +81,17 @@ abstract class ConstantTile extends Tile {
* @return The new Tile
*/
def convert(newType: CellType): Tile = {
if(dVal.isNaN && !newType.isInstanceOf[NoNoData]) {
ConstantTile.emptyTile(newType, cols, rows)
}else {
newType match {
case BitCellType => new BitConstantTile(if (iVal == 0) false else true, cols, rows)
case ct: ByteCells => ByteConstantTile(iVal.toByte, cols, rows, ct)
case ct: UByteCells => UByteConstantTile(iVal.toByte, cols, rows, ct)
case ct: ShortCells => ShortConstantTile(iVal.toShort , cols, rows, ct)
case ct: UShortCells => UShortConstantTile(iVal.toShort , cols, rows, ct)
case ct: IntCells => IntConstantTile(iVal , cols, rows, ct)
case ct: FloatCells => FloatConstantTile(dVal.toFloat , cols, rows, ct)
case ct: DoubleCells => DoubleConstantTile(dVal, cols, rows, ct)
}
newType match {
case ct: CellType if !ct.isInstanceOf[NoNoData] && dVal.isNaN => ConstantTile.emptyTile(newType, cols, rows)
case BitCellType => new BitConstantTile(if (iVal == 0) false else true, cols, rows)
case ct: ByteCells => ByteConstantTile(iVal.toByte, cols, rows, ct)
case ct: UByteCells => UByteConstantTile(iVal.toByte, cols, rows, ct)
case ct: ShortCells => ShortConstantTile(iVal.toShort , cols, rows, ct)
case ct: UShortCells => UShortConstantTile(iVal.toShort , cols, rows, ct)
case ct: IntCells => IntConstantTile(iVal , cols, rows, ct)
case ct: FloatCells => FloatConstantTile(dVal.toFloat , cols, rows, ct)
case ct: DoubleCells => DoubleConstantTile(dVal, cols, rows, ct)
}

}

def interpretAs(newCellType: CellType): Tile =
Expand Down Expand Up @@ -265,9 +259,9 @@ object ConstantTile {
t match {
case _: BitCells => BitConstantTile(false, cols, rows)
case ct: ByteUserDefinedNoDataCellType => ByteConstantTile(ct.noDataValue ,cols, rows, ct)
case ct: ByteCells => ByteConstantTile(t.asInstanceOf[HasNoData[Byte]].noDataValue ,cols, rows, ct)
case ct: ByteConstantNoDataCellType => ByteConstantTile(ct.noDataValue ,cols, rows, ct)
case ct: UByteConstantNoDataCellType => UByteConstantTile(ct.noDataValue ,cols, rows, ct)
case ct: UByteUserDefinedNoDataCellType => UByteConstantTile(ct.noDataValue ,cols, rows, ct)
case ct: UByteCells => UByteConstantTile(t.asInstanceOf[HasNoData[Byte]].noDataValue ,cols, rows, ct)
case ct: ShortUserDefinedNoDataCellType => {
val theNoData: Short = ct.noDataValue
ShortConstantTile(theNoData ,cols, rows, ct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ class ConstantTileSpec extends AnyFunSpec with Matchers with RasterMatchers with
}

describe("celltype conversion") {
it("should convert ByteConstantTile") {
it("should convert ByteConstantTile with nodata") {
val t = ByteConstantTile(byteNODATA, cols = 1, rows = 1)
assert(t.isNoDataTile)
assert(t.convert(t.cellType).isNoDataTile)
}

it("should convert ByteConstantTile") {
val t = ByteConstantTile(10, cols = 1, rows = 1)
assert(t.convert(FloatConstantNoDataCellType).getDouble(0,0) === 10.0)
}
}
}

0 comments on commit 1a8adc4

Please sign in to comment.