You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2022/04/07 04:23:35 UTC

[incubator-sedona] branch master updated: Resolved the issue SEDONA-104 (#603)

This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 4be749a7 Resolved the issue SEDONA-104 (#603)
4be749a7 is described below

commit 4be749a776b3a4744ff2bc80c1dff5e61526b257
Author: Kanchan Chowdhury <43...@users.noreply.github.com>
AuthorDate: Wed Apr 6 21:23:30 2022 -0700

    Resolved the issue SEDONA-104 (#603)
---
 core/src/test/resources/raster/test3.tif           | Bin 0 -> 6619 bytes
 .../spark/sql/sedona_sql/io/GeotiffSchema.scala    |   2 +-
 .../scala/org/apache/sedona/sql/rasterIOTest.scala |  22 +++++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/core/src/test/resources/raster/test3.tif b/core/src/test/resources/raster/test3.tif
new file mode 100644
index 00000000..776d7534
Binary files /dev/null and b/core/src/test/resources/raster/test3.tif differ
diff --git a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/io/GeotiffSchema.scala b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/io/GeotiffSchema.scala
index 91b1c102..08234338 100644
--- a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/io/GeotiffSchema.scala
+++ b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/io/GeotiffSchema.scala
@@ -179,7 +179,7 @@ object GeotiffSchema {
         // bands of a pixel will be put in [b0...b1...b2...]
         // Each "..." represent w * h pixels
         for (bandId <- 0 until nBands) {
-          val offset = i * width + j + nBands * bandId
+          val offset = i * width + j + width * height * bandId
           decoded(offset) = vals(bandId)
         }
       }
diff --git a/sql/src/test/scala/org/apache/sedona/sql/rasterIOTest.scala b/sql/src/test/scala/org/apache/sedona/sql/rasterIOTest.scala
index 8f0f8095..406f7086 100644
--- a/sql/src/test/scala/org/apache/sedona/sql/rasterIOTest.scala
+++ b/sql/src/test/scala/org/apache/sedona/sql/rasterIOTest.scala
@@ -70,6 +70,28 @@ class rasterIOTest extends TestBaseScala with BeforeAndAfter with GivenWhenThen
       assert(df.first().getAs[String](0).contains("img"))
 //      printf(df.first().getAs[String](0))
     }
+
+    it("should pass RS_GetBand for length of Band 2") {
+      var df = sparkSession.read.format("geotiff").option("dropInvalid", true).load(resourceFolder + "raster/test3.tif")
+      df = df.selectExpr(" image.data as data", "image.nBands as bands")
+      df = df.selectExpr("RS_GetBand(data, 2, bands) as targetBand")
+      assert(df.first().getAs[mutable.WrappedArray[Double]](0).length == 32 * 32)
+    }
+
+    it("should pass RS_GetBand for elements of Band 2") {
+      var df = sparkSession.read.format("geotiff").option("dropInvalid", true).load(resourceFolder + "raster/test3.tif")
+      df = df.selectExpr(" image.data as data", "image.nBands as bands")
+      df = df.selectExpr("RS_GetBand(data, 2, bands) as targetBand")
+      assert(df.first().getAs[mutable.WrappedArray[Double]](0)(1) == 956.0)
+    }
+
+    it("should pass RS_GetBand for elements of Band 4") {
+      var df = sparkSession.read.format("geotiff").option("dropInvalid", true).load(resourceFolder + "raster/test3.tif")
+      df = df.selectExpr(" image.data as data", "image.nBands as bands")
+      df = df.selectExpr("RS_GetBand(data, 4, bands) as targetBand")
+      assert(df.first().getAs[mutable.WrappedArray[Double]](0)(2) == 0.0)
+    }
+    
   }
 }