Skip to content

Commit 905390f

Browse files
committed
Updated ShowableTile to render NoData values differently.
1 parent c2859d2 commit 905390f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

core/src/main/scala/org/locationtech/rasterframes/tiles/ShowableTile.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
package org.locationtech.rasterframes.tiles
2323
import org.locationtech.rasterframes._
24-
import geotrellis.raster.Tile
24+
import geotrellis.raster.{Tile, isNoData}
2525

2626
class ShowableTile(val delegate: Tile) extends FixedDelegatingTile {
2727
override def equals(obj: Any): Boolean = obj match {
@@ -39,8 +39,14 @@ object ShowableTile {
3939
val dims = tile.dimensions
4040

4141
val data = if (tile.cellType.isFloatingPoint)
42-
tile.toArrayDouble()
43-
else tile.toArray()
42+
tile.toArrayDouble().map {
43+
case c if isNoData(c) => "--"
44+
case c => c.toString
45+
}
46+
else tile.toArray().map {
47+
case c if isNoData(c) => "--"
48+
case c => c.toString
49+
}
4450

4551
val cells = if(tile.size <= maxCells) {
4652
data.mkString("[", ",", "]")

core/src/test/scala/org/locationtech/rasterframes/TileUDTSpec.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
*/
2121

2222
package org.locationtech.rasterframes
23-
import geotrellis.raster.{CellType, Tile}
23+
import geotrellis.raster
24+
import geotrellis.raster.{CellType, NoNoData, Tile}
2425
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
2526
import org.apache.spark.sql.rf._
2627
import org.apache.spark.sql.types.StringType
@@ -98,6 +99,12 @@ class TileUDTSpec extends TestEnvironment with TestData with Inspectors {
9899
forEveryConfig { tile =>
99100
val stringified = Seq(tile).toDF("tile").select($"tile".cast(StringType)).as[String].first()
100101
stringified should be(ShowableTile.show(tile))
102+
103+
if(!tile.cellType.isInstanceOf[NoNoData]) {
104+
val withNd = tile.mutable
105+
withNd.update(0, raster.NODATA)
106+
ShowableTile.show(withNd) should include("--")
107+
}
101108
}
102109
}
103110
}

0 commit comments

Comments
 (0)