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 2023/09/01 08:47:54 UTC
[sedona] branch bug-fix-base64 updated: Fix the bug and improve documentation
This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch bug-fix-base64
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/bug-fix-base64 by this push:
new 03a13e26e Fix the bug and improve documentation
03a13e26e is described below
commit 03a13e26ecef0409df8adefda08a6c28c23de0e8
Author: Jia Yu <ji...@apache.org>
AuthorDate: Fri Sep 1 01:47:48 2023 -0700
Fix the bug and improve documentation
---
.../java/org/apache/sedona/common/raster/RasterOutputTest.java | 1 +
docs/api/sql/Raster-writer.md | 8 ++++----
sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala | 2 +-
.../spark/sql/sedona_sql/expressions/raster/RasterOutputs.scala | 2 +-
.../src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala | 4 ++--
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java
index a03d9f3f1..2fa06754e 100644
--- a/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java
+++ b/common/src/test/java/org/apache/sedona/common/raster/RasterOutputTest.java
@@ -33,6 +33,7 @@ public class RasterOutputTest
public void testAsBase64() throws IOException {
GridCoverage2D raster = rasterFromGeoTiff(resourceFolder + "raster/raster_with_no_data/test5.tiff");
String resultRaw = RasterOutputs.asBase64(raster);
+ System.out.println(resultRaw);
assertTrue(resultRaw.startsWith("iVBORw0KGgoAAAANSUhEUgAABaAAAALQCAMAAABR+ye1AAADAFBMVEXE9/W48vOq7PGa5u6L3"));
}
diff --git a/docs/api/sql/Raster-writer.md b/docs/api/sql/Raster-writer.md
index 2bc0307fa..445eb3fdf 100644
--- a/docs/api/sql/Raster-writer.md
+++ b/docs/api/sql/Raster-writer.md
@@ -9,18 +9,18 @@ To write a Sedona Raster DataFrame to raster files, you need to (1) first conver
You can use the following RS output functions (`RS_AsXXX`) to convert a Raster DataFrame to a binary DataFrame. Generally the output format of a raster can be different from the original input format. For example, you can use `RS_FromGeoTiff` to create rasters and save them using `RS_AsArcInfoAsciiGrid`.
-#### RS_Base64
+#### RS_AsBase64
-Introduction: Returns base64 encoded string of given raster.
+Introduction: Returns a base64 encoded string of the given raster. This function internally takes the first 4 bands as RGBA, and converts them to the PNG format, finally produces a base64 string. To visualize other bands, please use it together with `RS_Band`. You can take the resulting base64 string in [an online viewer](https://base64-viewer.onrender.com/) to check how the image looks like.
Since: `v1.5.0`
-Format: `RS_Base64(raster: Raster)`
+Format: `RS_AsBase64(raster: Raster)`
Spark SQL Example:
```sql
-SELECT RS_Base64(raster) from rasters
+SELECT RS_AsBase64(raster) from rasters
```
Output:
diff --git a/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala b/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
index b09c8952b..021e6035b 100644
--- a/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
+++ b/sql/common/src/main/scala/org/apache/sedona/sql/UDF/Catalog.scala
@@ -211,7 +211,7 @@ object Catalog {
function[RS_Intersects](),
function[RS_AsGeoTiff](),
function[RS_AsArcGrid](),
- function[RS_Base64](),
+ function[RS_AsBase64](),
function[RS_Width](),
function[RS_Height](),
function[RS_UpperLeftX](),
diff --git a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/raster/RasterOutputs.scala b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/raster/RasterOutputs.scala
index 081ed6d96..d3a7c91b9 100644
--- a/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/raster/RasterOutputs.scala
+++ b/sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/raster/RasterOutputs.scala
@@ -39,7 +39,7 @@ case class RS_AsArcGrid(inputExpressions: Seq[Expression])
}
}
-case class RS_Base64(inputExpressions: Seq[Expression]) extends InferredExpression(RasterOutputs.asBase64 _) {
+case class RS_AsBase64(inputExpressions: Seq[Expression]) extends InferredExpression(RasterOutputs.asBase64 _) {
protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = {
copy(inputExpressions = newChildren)
}
diff --git a/sql/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala b/sql/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala
index 5bcf618f9..6cff6ca8c 100644
--- a/sql/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala
+++ b/sql/common/src/test/scala/org/apache/sedona/sql/rasteralgebraTest.scala
@@ -470,9 +470,9 @@ class rasteralgebraTest extends TestBaseScala with BeforeAndAfter with GivenWhen
assert(writtenBinary1.length > writtenBinary2.length)
}
- it("Passed RS_Base64") {
+ it("Passed RS_AsBase64") {
val df = sparkSession.read.format("binaryFile").load(resourceFolder + "raster/raster_with_no_data/test5.tiff")
- val resultRaw = df.selectExpr("RS_Base64(RS_FromGeoTiff(content)) as raster").first().getString(0)
+ val resultRaw = df.selectExpr("RS_AsBase64(RS_FromGeoTiff(content)) as raster").first().getString(0)
assert(resultRaw.startsWith("iVBORw0KGgoAAAANSUhEUgAABaAAAALQCAMAAABR+ye1AAADAFBMVEXE9/W48vOq7PGa5u6L3"))
}