Skip to content

Commit c2859d2

Browse files
committed
Moved array function tests to RasterFunctionsSpec.
1 parent 1fff31b commit c2859d2

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -110,45 +110,6 @@ class ExplodeSpec extends TestEnvironment with TestData {
110110
cells.count(_.isNaN) should be(tiles.size)
111111
}
112112

113-
it("should convert tile into array") {
114-
val query = sql(
115-
"""select rf_tile_to_array_int(
116-
| rf_make_constant_tile(1, 10, 10, 'int8raw')
117-
|) as intArray
118-
|""".stripMargin)
119-
query.as[Array[Int]].first.sum should be (100)
120-
121-
val tile = FloatConstantTile(1.1f, 10, 10, FloatCellType)
122-
val df = Seq[Tile](tile).toDF("tile")
123-
val arrayDF = df.select(rf_tile_to_array_double($"tile").as[Array[Double]])
124-
arrayDF.first().sum should be (110.0 +- 0.0001)
125-
126-
checkDocs("rf_tile_to_array_int")
127-
}
128-
129-
it("should convert an array into a tile") {
130-
val tile = TestData.randomTile(10, 10, FloatCellType)
131-
val df = Seq[Tile](tile, null).toDF("tile")
132-
val arrayDF = df.withColumn("tileArray", rf_tile_to_array_double($"tile"))
133-
134-
val back = arrayDF.withColumn("backToTile", rf_array_to_tile($"tileArray", 10, 10))
135-
136-
val result = back.select($"backToTile".as[Tile]).first
137-
138-
assert(result.toArrayDouble() === tile.toArrayDouble())
139-
140-
// Same round trip, but with SQL expression for rf_array_to_tile
141-
val resultSql = arrayDF.selectExpr("rf_array_to_tile(tileArray, 10, 10) as backToTile").as[Tile].first
142-
143-
assert(resultSql.toArrayDouble() === tile.toArrayDouble())
144-
145-
val hasNoData = back.withColumn("withNoData", rf_with_no_data($"backToTile", 0))
146-
147-
val result2 = hasNoData.select($"withNoData".as[Tile]).first
148-
149-
assert(result2.cellType.asInstanceOf[UserDefinedNoData[_]].noDataValue === 0)
150-
}
151-
152113
it("should reassemble single exploded tile") {
153114
val tile = TestData.randomTile(10, 10, FloatCellType)
154115
val df = Seq[Tile](tile).toDF("tile")

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,48 @@ class RasterFunctionsSpec extends TestEnvironment with RasterMatchers {
568568
}
569569
}
570570

571+
describe("array operations") {
572+
it("should convert tile into array") {
573+
val query = sql(
574+
"""select rf_tile_to_array_int(
575+
| rf_make_constant_tile(1, 10, 10, 'int8raw')
576+
|) as intArray
577+
|""".stripMargin)
578+
query.as[Array[Int]].first.sum should be (100)
579+
580+
val tile = FloatConstantTile(1.1f, 10, 10, FloatCellType)
581+
val df = Seq[Tile](tile).toDF("tile")
582+
val arrayDF = df.select(rf_tile_to_array_double($"tile").as[Array[Double]])
583+
arrayDF.first().sum should be (110.0 +- 0.0001)
584+
585+
checkDocs("rf_tile_to_array_int")
586+
checkDocs("rf_tile_to_array_double")
587+
}
588+
589+
it("should convert an array into a tile") {
590+
val tile = TestData.randomTile(10, 10, FloatCellType)
591+
val df = Seq[Tile](tile, null).toDF("tile")
592+
val arrayDF = df.withColumn("tileArray", rf_tile_to_array_double($"tile"))
593+
594+
val back = arrayDF.withColumn("backToTile", rf_array_to_tile($"tileArray", 10, 10))
595+
596+
val result = back.select($"backToTile".as[Tile]).first
597+
598+
assert(result.toArrayDouble() === tile.toArrayDouble())
599+
600+
// Same round trip, but with SQL expression for rf_array_to_tile
601+
val resultSql = arrayDF.selectExpr("rf_array_to_tile(tileArray, 10, 10) as backToTile").as[Tile].first
602+
603+
assert(resultSql.toArrayDouble() === tile.toArrayDouble())
604+
605+
val hasNoData = back.withColumn("withNoData", rf_with_no_data($"backToTile", 0))
606+
607+
val result2 = hasNoData.select($"withNoData".as[Tile]).first
608+
609+
assert(result2.cellType.asInstanceOf[UserDefinedNoData[_]].noDataValue === 0)
610+
}
611+
}
612+
571613
describe("analytical transformations") {
572614
it("should compute rf_normalized_difference") {
573615
val df = Seq((three, two)).toDF("three", "two")

0 commit comments

Comments
 (0)