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/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new c673aa3001 [GH-2299] add function of ST_AsEWKT (#2309)
c673aa3001 is described below

commit c673aa3001d63856f22e38f657349476cbbca3d9
Author: Zhuocheng Shang <[email protected]>
AuthorDate: Mon Aug 25 22:05:31 2025 -0700

    [GH-2299] add function of ST_AsEWKT (#2309)
    
    * add function of ST_AsEWKT
    
    * fix WKT output
    
    * fix geography typo
---
 .../sedona/common/S2Geography/Geography.java       | 10 ++++++++
 .../sedona/common/S2Geography/WKTWriter.java       | 20 ++++++++++------
 .../apache/sedona/common/geography/Functions.java  |  5 ++++
 .../sedona/common/Geography/ConstructorsTest.java  | 28 ++++++++++++----------
 .../sedona/common/Geography/FunctionTest.java      | 14 +++++------
 docs/api/sql/geography/Constructor.md              |  8 +++----
 docs/api/sql/geography/Function.md                 | 22 +++++++++++++++++
 .../sql/sedona_sql/expressions/Functions.scala     |  6 +++--
 .../apache/sedona/sql/dataFrameAPITestScala.scala  |  4 +---
 .../geography/ConstructorsDataFrameAPITest.scala   |  8 +++----
 .../sedona/sql/geography/ConstructorsTest.scala    | 10 ++++----
 .../sql/geography/FunctionsDataFrameAPITest.scala  | 15 ++++++++++--
 .../sedona/sql/geography/FunctionsTest.scala       |  8 +++++++
 13 files changed, 110 insertions(+), 48 deletions(-)

diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/Geography.java 
b/common/src/main/java/org/apache/sedona/common/S2Geography/Geography.java
index bfc5d6df35..284c5761f1 100644
--- a/common/src/main/java/org/apache/sedona/common/S2Geography/Geography.java
+++ b/common/src/main/java/org/apache/sedona/common/S2Geography/Geography.java
@@ -171,6 +171,16 @@ public abstract class Geography {
     return writer.write(this);
   }
 
+  public String toEWKT() {
+    return toEWKT(new PrecisionModel(PrecisionModel.FIXED));
+  }
+
+  public String toEWKT(PrecisionModel precisionModel) {
+    WKTWriter writer = new WKTWriter(true);
+    writer.setPrecisionModel(precisionModel);
+    return writer.write(this);
+  }
+
   // ─── Encoding / decoding machinery 
────────────────────────────────────────────
   /**
    * Serialize this geography to an encoder. This does not include any 
encapsulating information
diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/WKTWriter.java 
b/common/src/main/java/org/apache/sedona/common/S2Geography/WKTWriter.java
index dc416fc136..71da85646e 100644
--- a/common/src/main/java/org/apache/sedona/common/S2Geography/WKTWriter.java
+++ b/common/src/main/java/org/apache/sedona/common/S2Geography/WKTWriter.java
@@ -49,6 +49,7 @@ public class WKTWriter {
 
   private static final int INDENT = 2;
   private static final int OUTPUT_DIMENSION = 2;
+  private boolean EWKT = false;
 
   /**
    * Creates the <code>DecimalFormat</code> used to write <code>double</code>s 
with a sufficient
@@ -91,6 +92,11 @@ public class WKTWriter {
     this(OUTPUT_DIMENSION);
   }
 
+  public WKTWriter(boolean isEwkt) {
+    this(OUTPUT_DIMENSION);
+    this.EWKT = isEwkt;
+  }
+
   /**
    * Creates a writer that writes {@link Geography}s with the given output 
dimension (2 to 4). The
    * output follows the following rules:
@@ -404,7 +410,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(point, writer);
+    if (EWKT) writeSRID(point, writer);
     writer.write(WKTConstants.POINT);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -437,7 +443,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(lineString, writer);
+    if (EWKT) writeSRID(lineString, writer);
     writer.write(WKTConstants.LINESTRING);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -469,7 +475,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(polygon, writer);
+    if (EWKT) writeSRID(polygon, writer);
     writer.write(WKTConstants.POLYGON);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -495,7 +501,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(multipoint, writer);
+    if (EWKT) writeSRID(multipoint, writer);
     writer.write(WKTConstants.MULTIPOINT);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -521,7 +527,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(multiLineString, writer);
+    if (EWKT) writeSRID(multiLineString, writer);
     writer.write(WKTConstants.MULTILINESTRING);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -548,7 +554,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(multiPolygon, writer);
+    if (EWKT) writeSRID(multiPolygon, writer);
     writer.write(WKTConstants.MULTIPOLYGON);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
@@ -574,7 +580,7 @@ public class WKTWriter {
       Writer writer,
       OrdinateFormat formatter)
       throws IOException {
-    writeSRID(geometryCollection, writer);
+    if (EWKT) writeSRID(geometryCollection, writer);
     writer.write(WKTConstants.GEOMETRYCOLLECTION);
     writer.write(" ");
     appendOrdinateText(outputOrdinates, writer);
diff --git 
a/common/src/main/java/org/apache/sedona/common/geography/Functions.java 
b/common/src/main/java/org/apache/sedona/common/geography/Functions.java
index 996c2ec7eb..0957e33aca 100644
--- a/common/src/main/java/org/apache/sedona/common/geography/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/geography/Functions.java
@@ -80,4 +80,9 @@ public class Functions {
 
     return new S2Polygon(loop);
   }
+
+  /** Return EWKT for geography object */
+  public static String asEWKT(Geography geography) {
+    return geography.toEWKT();
+  }
 }
diff --git 
a/common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java 
b/common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java
index 7fa19c0ce5..c454daca8e 100644
--- 
a/common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java
+++ 
b/common/src/test/java/org/apache/sedona/common/Geography/ConstructorsTest.java
@@ -50,11 +50,11 @@ public class ConstructorsTest {
 
     geog = Constructors.geogFromEWKT("SRID=4269; POINT (1 1)");
     assertEquals(4269, geog.getSRID());
-    assertEquals("SRID=4269; POINT (1 1)", geog.toString());
+    assertEquals("SRID=4269; POINT (1 1)", geog.toEWKT());
 
     geog = Constructors.geogFromEWKT("SRID=4269;POINT (1 1)");
     assertEquals(4269, geog.getSRID());
-    assertEquals("SRID=4269; POINT (1 1)", geog.toString());
+    assertEquals("SRID=4269; POINT (1 1)", geog.toEWKT());
 
     ParseException invalid =
         assertThrows(ParseException.class, () -> 
Constructors.geogFromEWKT("not valid"));
@@ -76,7 +76,7 @@ public class ConstructorsTest {
 
     // Test specifying SRID
     result = Constructors.geogFromWKB(wkb, 1000);
-    assertEquals("SRID=1000; POINT (-64 45)", result.toString());
+    assertEquals("POINT (-64 45)", result.toString());
     assertEquals(1000, result.getSRID());
 
     // Test EWKB with SRID
@@ -84,12 +84,12 @@ public class ConstructorsTest {
     geog.setSRID(2000);
     wkb = wkbWriter.write(geog);
     result = Constructors.geogFromWKB(wkb);
-    assertEquals("SRID=2000; POINT (-64 45)", result.toString());
+    assertEquals("POINT (-64 45)", result.toString());
     assertEquals(2000, result.getSRID());
 
     // Test overriding SRID
     result = Constructors.geogFromWKB(wkb, 3000);
-    assertEquals("SRID=3000; POINT (-64 45)", result.toString());
+    assertEquals("POINT (-64 45)", result.toString());
     assertEquals(3000, result.getSRID());
     result = Constructors.geogFromWKB(wkb, 0);
     assertEquals("POINT (-64 45)", result.toString());
@@ -102,14 +102,14 @@ public class ConstructorsTest {
     byte[] wkbBytes = WKBReader.hexToBytes(ewkbString);
     Geography result = Constructors.geogFromWKB(wkbBytes);
     String expectedGeom = "SRID=4326; POINT (0 1)";
-    assertEquals(expectedGeom, result.toString());
+    assertEquals(expectedGeom, result.toEWKT());
     assertEquals(4326, result.getSRID());
 
     ewkbString =
         
"0103000020E61000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000";
     wkbBytes = WKBReader.hexToBytes(ewkbString);
     result = Constructors.geogFromWKB(wkbBytes);
-    expectedGeom = "SRID=4326; POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))";
+    expectedGeom = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))";
     assertEquals(expectedGeom, result.toString());
     assertEquals(4326, result.getSRID());
 
@@ -127,7 +127,7 @@ public class ConstructorsTest {
             + "000000000000F0BF000000000000F0BF";
     wkbBytes = WKBReader.hexToBytes(ewkbString);
     result = Constructors.geogFromWKB(wkbBytes);
-    expectedGeom = "SRID=4326; MULTIPOLYGON (((0 0, 1 0, 1 1, 0 0)), ((-1 -1, 
-1 0, 0 -1, -1 -1)))";
+    expectedGeom = "MULTIPOLYGON (((0 0, 1 0, 1 1, 0 0)), ((-1 -1, -1 0, 0 -1, 
-1 -1)))";
     assertEquals(expectedGeom, result.toString());
     assertEquals(4326, result.getSRID());
   }
@@ -136,14 +136,16 @@ public class ConstructorsTest {
   public void geogFromGeoHash() throws ParseException {
     Geography geog = Constructors.geogFromGeoHash("9q9j8ue2v71y5zzy0s4q", 16);
     String expectedWkt =
-        "SRID=4326; POLYGON ((-122.3061 37.554162, -122.3061 37.554162, 
-122.3061 37.554162, -122.3061 37.554162, -122.3061 37.554162))";
-    String actualWkt = geog.toText(new PrecisionModel(1e6));
+        "POLYGON ((-122.3061 37.554162, -122.3061 37.554162, -122.3061 
37.554162, -122.3061 37.554162, -122.3061 37.554162))";
+    assertNotNull(geog);
+    String actualWkt = geog.toString(new PrecisionModel(1e6));
     assertEquals(expectedWkt, actualWkt);
 
     geog = Constructors.geogFromGeoHash("s00twy01mt", 4);
     expectedWkt =
-        "SRID=4326; POLYGON ((0.703125 0.8789062, 1.0546875 0.8789062, 
1.0546875 1.0546875, 0.703125 1.0546875, 0.703125 0.8789062))";
-    actualWkt = geog.toText(new PrecisionModel(1e6));
+        "POLYGON ((0.703125 0.8789062, 1.0546875 0.8789062, 1.0546875 
1.0546875, 0.703125 1.0546875, 0.703125 0.8789062))";
+    assertNotNull(geog);
+    actualWkt = geog.toString(new PrecisionModel(1e6));
     assertEquals(expectedWkt, actualWkt);
   }
 
@@ -266,7 +268,7 @@ public class ConstructorsTest {
     assertEquals(4326, got.getSRID());
     org.locationtech.jts.io.WKTWriter wktWriter = new 
org.locationtech.jts.io.WKTWriter();
     wktWriter.setPrecisionModel(new PrecisionModel(PrecisionModel.FIXED));
-    assertEquals(expected, got.toString());
+    assertEquals(expected, got.toEWKT());
   }
 
   @Test
diff --git 
a/common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java 
b/common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java
index c7f1f6dcb3..aac8247a8d 100644
--- a/common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java
+++ b/common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java
@@ -82,8 +82,9 @@ public class FunctionTest {
         "POLYGON ((3.314971 50.80372, 7.092053 50.80372, 7.092053 53.5104, 
3.314971 53.5104, 3.314971 50.80372))";
     Geography g = Constructors.geogFromWKT(nl, 4326);
     Geography env = Functions.getEnvelope(g, true);
-    String expectedWKT = "SRID=4326; POLYGON ((3.3 50.8, 7.1 50.8, 7.1 53.5, 
3.3 53.5, 3.3 50.8))";
+    String expectedWKT = "POLYGON ((3.3 50.8, 7.1 50.8, 7.1 53.5, 3.3 53.5, 
3.3 50.8))";
     assertEquals(expectedWKT, env.toString());
+    assertEquals(4326, env.getSRID());
   }
 
   @Test
@@ -113,12 +114,11 @@ public class FunctionTest {
     Geography g = Constructors.geogFromWKT(fiji, 4326);
     Geography env = Functions.getEnvelope(g, /*split*/ true);
     String expectedWKT =
-        "SRID=4326; MULTIPOLYGON (((177.3 -18.3, 180 -18.3, 180 -16, 177.3 
-16, 177.3 -18.3)), "
+        "MULTIPOLYGON (((177.3 -18.3, 180 -18.3, 180 -16, 177.3 -16, 177.3 
-18.3)), "
             + "((-180 -18.3, -179.8 -18.3, -179.8 -16, -180 -16, -180 
-18.3)))";
     assertEquals(expectedWKT, env.toString());
 
-    expectedWKT =
-        "SRID=4326; POLYGON ((177.3 -18.3, -179.8 -18.3, -179.8 -16, 177.3 
-16, 177.3 -18.3))";
+    expectedWKT = "POLYGON ((177.3 -18.3, -179.8 -18.3, -179.8 -16, 177.3 -16, 
177.3 -18.3))";
     env = Functions.getEnvelope(g, /*split*/ false);
     assertEquals(expectedWKT, env.toString());
   }
@@ -137,8 +137,7 @@ public class FunctionTest {
     Geography g = Constructors.geogFromWKT(antarctica, 4326);
     Geography env = Functions.getEnvelope(g, true);
 
-    String expectedWKT =
-        "SRID=4326; POLYGON ((-180 -63.3, 180 -63.3, 180 -90, -180 -90, -180 
-63.3))";
+    String expectedWKT = "POLYGON ((-180 -63.3, 180 -63.3, 180 -90, -180 -90, 
-180 -63.3))";
     assertEquals((expectedWKT), (env.toString()));
 
     String multiCountry =
@@ -147,8 +146,7 @@ public class FunctionTest {
     g = Constructors.geogFromWKT(multiCountry, 4326);
     env = Functions.getEnvelope(g, true);
 
-    String expectedWKT2 =
-        "SRID=4326; POLYGON ((-180 53.5, 180 53.5, 180 -90, -180 -90, -180 
53.5))";
+    String expectedWKT2 = "POLYGON ((-180 53.5, 180 53.5, 180 -90, -180 -90, 
-180 53.5))";
     assertEquals((expectedWKT2), (env.toString()));
   }
 }
diff --git a/docs/api/sql/geography/Constructor.md 
b/docs/api/sql/geography/Constructor.md
index 1845ea9174..90e1acc6b6 100644
--- a/docs/api/sql/geography/Constructor.md
+++ b/docs/api/sql/geography/Constructor.md
@@ -52,7 +52,7 @@ Since: `v1.8.0`
 SQL Example
 
 ```sql
-SELECT ST_GeogFromEWKB([01 02 00 00 20 E6 10 00 00 02 00 00 00 00 00 00 00 84 
D6 00 C0 00 00 00 00 80 B5 D6 BF 00 00 00 60 E1 EF F7 BF 00 00 00 80 07 5D E5 
BF])
+SELECT ST_AsEWKT(ST_GeogFromEWKB([01 02 00 00 20 E6 10 00 00 02 00 00 00 00 00 
00 00 84 D6 00 C0 00 00 00 00 80 B5 D6 BF 00 00 00 60 E1 EF F7 BF 00 00 00 80 
07 5D E5 BF]))
 ```
 
 Output:
@@ -80,7 +80,7 @@ SELECT ST_GeogFromGeoHash('9q9j8ue2v71y5zzy0s4q', 16)
 Output:
 
 ```
-SRID=4326; POLYGON ((-122.3061 37.554162, -122.3061 37.554162, -122.3061 
37.554162, -122.3061 37.554162, -122.3061 37.554162))"
+POLYGON ((-122.3061 37.554162, -122.3061 37.554162, -122.3061 37.554162, 
-122.3061 37.554162, -122.3061 37.554162))"
 ```
 
 ## ST_GeogFromWKT
@@ -110,7 +110,7 @@ LINESTRING (1 2, 3 4, 5 6)
 SQL Example
 
 ```sql
-SELECT ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)', 4326)
+SELECT ST_AsEWKT(ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)', 4326))
 ```
 
 Output:
@@ -132,7 +132,7 @@ Since: `v1.8.0`
 SQL example:
 
 ```sql
-SELECT ST_GeogFromEWKT('SRID=4326; LINESTRING (0 0, 3 3, 4 4)')
+SELECT ST_AsEWKT(ST_GeogFromEWKT('SRID=4326; LINESTRING (0 0, 3 3, 4 4)'))
 ```
 
 Output:
diff --git a/docs/api/sql/geography/Function.md 
b/docs/api/sql/geography/Function.md
index 4d8563ed18..4c05f5e8a4 100644
--- a/docs/api/sql/geography/Function.md
+++ b/docs/api/sql/geography/Function.md
@@ -38,3 +38,25 @@ Output:
 ```
 POLYGON ((177.3 -18.3, -179.8 -18.3, -179.8 -16, 177.3 -16, 177.3 -18.3))
 ```
+
+## ST_AsEWKT
+
+Introduction: Return the Extended Well-Known Text representation of a 
geography.
+EWKT is an extended version of WKT which includes the SRID of the geography.
+The format originated in PostGIS but is supported by many GIS tools.
+
+Format: `ST_AsEWKT (A: Geography)`
+
+Since: `v1.8.0`
+
+SQL Example
+
+```sql
+SELECT ST_AsEWKT(ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)', 4326))
+```
+
+Output:
+
+```
+SRID=4326; LINESTRING (1 2, 3 4, 5 6)
+```
diff --git 
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
 
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index 8c4ad05f4c..001ac1a787 100644
--- 
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++ 
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -37,6 +37,7 @@ import 
org.apache.spark.sql.sedona_sql.expressions.LibPostalUtils.{getExpanderFr
 import org.apache.spark.unsafe.types.UTF8String
 import org.apache.spark.util.Utils
 import com.mapzen.jpostal.{AddressExpander, AddressParser}
+import org.apache.sedona.common.S2Geography.Geography
 import org.apache.spark.sql.catalyst.expressions.codegen.Block.BlockHelper
 
 private[apache] case class ST_LabelPoint(inputExpressions: Seq[Expression])
@@ -1277,8 +1278,9 @@ private[apache] case class ST_Force2D(inputExpressions: 
Seq[Expression])
  * @param inputExpressions
  */
 private[apache] case class ST_AsEWKT(inputExpressions: Seq[Expression])
-    extends InferredExpression((geom: Geometry) => Functions.asEWKT(geom)) {
-  // (geog: Geography) => Functions.asEWKT(geog)
+    extends InferredExpression(
+      (geom: Geometry) => Functions.asEWKT(geom),
+      (geog: Geography) => 
org.apache.sedona.common.geography.Functions.asEWKT(geog)) {
   protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = 
{
     copy(inputExpressions = newChildren)
   }
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala 
b/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
index 8fa0eae4d8..ea4cd18c13 100644
--- 
a/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
+++ 
b/spark/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala
@@ -239,9 +239,7 @@ class dataFrameAPITestScala extends TestBaseScala {
       val df =
         sparkSession.sql("SELECT 'POINT(0.0 1.0)' AS 
wkt").select(ST_GeogFromWKT("wkt", 4326))
       val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography]
-      assert(
-        actualResult.toString(
-          new PrecisionModel(PrecisionModel.FIXED)) == "SRID=4326; POINT (0 
1)")
+      assert(actualResult.toString(new PrecisionModel(PrecisionModel.FIXED)) 
== "POINT (0 1)")
       assert(actualResult.getSRID == 4326)
     }
 
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsDataFrameAPITest.scala
 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsDataFrameAPITest.scala
index 39768f236f..21a6a56b93 100644
--- 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsDataFrameAPITest.scala
+++ 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsDataFrameAPITest.scala
@@ -57,7 +57,7 @@ class ConstructorsDataFrameAPITest extends TestBaseScala {
     val array = WKBReader.hexToBytes(hexStr)
     val wkbSeq = Seq[Array[Byte]](array)
     val df = 
wkbSeq.toDF("wkb").select(st_constructors.ST_GeogFromWKB(col("wkb")))
-    val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography].toString()
+    val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography].toEWKT()
     val expectedResult =
       "GEOMETRYCOLLECTION (SRID=4326; POINT (0 1), SRID=4326; POINT (0 1), 
SRID=4326; POINT (2 3), SRID=4326; LINESTRING (2 3, 4 5), SRID=4326; LINESTRING 
(0 1, 2 3), SRID=4326; LINESTRING (4 5, 6 7), SRID=4326; POLYGON ((0 0, 0 10, 
10 10, 10 0, 0 0), (9 1, 9 9, 1 9, 1 1, 9 1)), SRID=4326; POLYGON ((0 0, 0 10, 
10 10, 10 0, 0 0), (9 1, 9 9, 1 9, 1 1, 9 1)), SRID=4326; POLYGON ((-9 0, -9 
10, -1 10, -1 0, -9 0)))"
     assert(actualResult == expectedResult)
@@ -69,7 +69,7 @@ class ConstructorsDataFrameAPITest extends TestBaseScala {
         0, 0, -128, -75, -42, -65, 0, 0, 0, 96, -31, -17, -9, -65, 0, 0, 0, 
-128, 7, 93, -27,
         -65))
     val df = wkbSeq.toDF("wkb") select (st_constructors.ST_GeogFromEWKB("wkb"))
-    val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography].toString()
+    val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography].toEWKT()
     val expectedResult = {
       "SRID=4326; LINESTRING (-2.1 -0.4, -1.5 -0.7)"
     }
@@ -82,7 +82,7 @@ class ConstructorsDataFrameAPITest extends TestBaseScala {
       .sql("SELECT 'SRID=4269;POINT(0.0 1.0)' AS wkt")
       .select(st_constructors.ST_GeogFromEWKT("wkt"))
     val actualResult = df.take(1)(0).get(0).asInstanceOf[Geography]
-    assert(actualResult.toString() == "SRID=4269; POINT (0 1)")
+    assert(actualResult.toEWKT() == "SRID=4269; POINT (0 1)")
     assert(actualResult.getSRID == 4269)
   }
 
@@ -93,7 +93,7 @@ class ConstructorsDataFrameAPITest extends TestBaseScala {
     val actualResult =
       df.take(1)(0).get(0).asInstanceOf[Geography].toText(new 
PrecisionModel(1e6))
     var expectedWkt =
-      "SRID=4326; POLYGON ((-122.3061 37.554162, -122.3061 37.554162, 
-122.3061 37.554162, -122.3061 37.554162, -122.3061 37.554162))"
+      "POLYGON ((-122.3061 37.554162, -122.3061 37.554162, -122.3061 
37.554162, -122.3061 37.554162, -122.3061 37.554162))"
     assertEquals(expectedWkt, actualResult)
   }
 
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala
 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala
index 4606c6f8ec..d253685206 100644
--- 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala
+++ 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/ConstructorsTest.scala
@@ -37,7 +37,7 @@ class ConstructorsTest extends TestBaseScala {
       sparkSession.sql(s"SELECT ST_GeogFromGeoHash('$geohash','$precision') AS 
geog").first()
     var geoStr = row.get(0).asInstanceOf[Geography].toText(new 
PrecisionModel(1e6))
     var expectedWkt =
-      "SRID=4326; POLYGON ((-122.3061 37.554162, -122.3061 37.554162, 
-122.3061 37.554162, -122.3061 37.554162, -122.3061 37.554162))"
+      "POLYGON ((-122.3061 37.554162, -122.3061 37.554162, -122.3061 
37.554162, -122.3061 37.554162, -122.3061 37.554162))"
     assertEquals(expectedWkt, geoStr)
 
     geohash = "s00twy01mt"
@@ -45,13 +45,13 @@ class ConstructorsTest extends TestBaseScala {
     row = sparkSession.sql(s"SELECT 
ST_GeogFromGeoHash('$geohash','$precision') AS geog").first()
     geoStr = row.get(0).asInstanceOf[Geography].toText(new PrecisionModel(1e6))
     expectedWkt =
-      "SRID=4326; POLYGON ((0.703125 0.8789062, 1.0546875 0.8789062, 1.0546875 
1.0546875, 0.703125 1.0546875, 0.703125 0.8789062))"
+      "POLYGON ((0.703125 0.8789062, 1.0546875 0.8789062, 1.0546875 1.0546875, 
0.703125 1.0546875, 0.703125 0.8789062))"
     assertEquals(expectedWkt, geoStr)
   }
 
   it("Passed ST_GeogFromWKT") {
     val wkt = "LINESTRING (1 2, 3 4, 5 6)"
-    val wktExpected = "SRID=4326; LINESTRING (1 2, 3 4, 5 6)"
+    val wktExpected = "LINESTRING (1 2, 3 4, 5 6)"
     val row = sparkSession.sql(s"SELECT ST_GeogFromWKT('$wkt', 4326) AS 
geog").first()
     // Write output with precisionModel
     val geoStr = row.get(0).asInstanceOf[Geography].toString()
@@ -63,7 +63,7 @@ class ConstructorsTest extends TestBaseScala {
 
   it("Passed ST_GeogFromText") {
     val wkt = "LINESTRING (1 2, 3 4, 5 6)"
-    val wktExpected = "SRID=4326; LINESTRING (1 2, 3 4, 5 6)"
+    val wktExpected = "LINESTRING (1 2, 3 4, 5 6)"
     val row = sparkSession.sql(s"SELECT ST_GeogFromText('$wkt', 4326) AS 
geog").first()
     // Write output with precisionModel
     val geoStr = row.get(0).asInstanceOf[Geography].toString()
@@ -167,7 +167,7 @@ class ConstructorsTest extends TestBaseScala {
       "SRID=4326; LINESTRING (-2.1 -0.4, -1.5 -0.7)"
     }
     assert(geography.first().getAs[Geography](0).getSRID == 4326)
-    assert(geography.first().getAs[Geography](0).toString.equals(expectedGeog))
+    assert(geography.first().getAs[Geography](0).toEWKT().equals(expectedGeog))
   }
 
   it("Passed ST_GeogToGeometry polygon") {
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsDataFrameAPITest.scala
 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsDataFrameAPITest.scala
index be21c792c0..9d25f26bf5 100644
--- 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsDataFrameAPITest.scala
+++ 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsDataFrameAPITest.scala
@@ -38,7 +38,7 @@ class FunctionsDataFrameAPITest extends TestBaseScala {
 
     val env = df.first().get(0).asInstanceOf[Geography]
     val expectedWKT =
-      "SRID=4326; POLYGON ((-180 -63.3, 180 -63.3, 180 -90, -180 -90, -180 
-63.3))";
+      "POLYGON ((-180 -63.3, 180 -63.3, 180 -90, -180 -90, -180 -63.3))";
     assertEquals(expectedWKT, env.toString)
   }
 
@@ -55,8 +55,19 @@ class FunctionsDataFrameAPITest extends TestBaseScala {
 
     val env = df.first().get(0).asInstanceOf[Geography]
     val expectedWKT =
-      "SRID=4326; POLYGON ((177.3 -18.3, -179.8 -18.3, -179.8 -16, 177.3 -16, 
177.3 -18.3))";
+      "POLYGON ((177.3 -18.3, -179.8 -18.3, -179.8 -16, 177.3 -16, 177.3 
-18.3))";
     assertEquals(expectedWKT, env.toString)
   }
 
+  it("Passed ST_AsEWKT") {
+    val wkt = "LINESTRING (1 2, 3 4, 5 6)"
+    val wktExpected = "SRID=4326; LINESTRING (1 2, 3 4, 5 6)"
+    val df = sparkSession
+      .sql(s"SELECT '$wkt' AS wkt")
+      .select(st_constructors.ST_GeogFromWKT(col("wkt"), lit(4326)).as("geog"))
+      .select(st_functions.ST_AsEWKT(col("geog")))
+    val geoStr = df.first().get(0)
+    assert(geoStr == wktExpected)
+  }
+
 }
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsTest.scala
 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsTest.scala
index 7f3af6eb2e..aa56f7d7f5 100644
--- 
a/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsTest.scala
+++ 
b/spark/common/src/test/scala/org/apache/sedona/sql/geography/FunctionsTest.scala
@@ -54,4 +54,12 @@ class FunctionsTest extends TestBaseScala {
     val functionDf = sparkSession.sql("select ST_Envelope(null, false)")
     assert(functionDf.first().get(0) == null)
   }
+
+  it("Passed ST_AsEWKT") {
+    val wkt = "LINESTRING (1 2, 3 4, 5 6)"
+    val wktExpected = "SRID=4326; LINESTRING (1 2, 3 4, 5 6)"
+    val row = sparkSession.sql(s"SELECT ST_AsEWKT(ST_GeogFromText('$wkt', 
4326)) AS geog").first()
+    val geoStr = row.get(0)
+    assert(geoStr == wktExpected)
+  }
 }

Reply via email to