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 145559dcbc [GH-2222] add Singlepoint, Singlepolyline for correctlty 
round trip WKT write (#2221)
145559dcbc is described below

commit 145559dcbc2ded7ed692591d252a1c5e8ad84ef3
Author: Zhuocheng Shang <122398181+zhuochengsh...@users.noreply.github.com>
AuthorDate: Tue Aug 5 12:01:28 2025 -0700

    [GH-2222] add Singlepoint, Singlepolyline for correctlty round trip WKT 
write (#2221)
    
    * add Singlepoint, Singlepolyline for correctlty round trip WKT write
    
    * kind check before call constructor
    
    * update error message
---
 .../sedona/common/S2Geography/PointGeography.java  | 11 +++++++++-
 .../common/S2Geography/PolylineGeography.java      | 13 ++++++++++++
 .../sedona/common/S2Geography/S2Geography.java     | 24 ++++++++++++++++++++--
 .../common/S2Geography/SinglePointGeography.java   |  2 +-
 .../S2Geography/SinglePolylineGeography.java       |  2 +-
 .../sedona/common/S2Geography/WKBReaderTest.java   |  4 ++--
 6 files changed, 49 insertions(+), 7 deletions(-)

diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java 
b/common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java
index d46a5b48fc..ab35a00223 100644
--- 
a/common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java
+++ 
b/common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java
@@ -46,8 +46,13 @@ public class PointGeography extends S2Geography {
   }
 
   /** Constructs especially for CELL_CENTER */
-  private PointGeography(GeographyKind kind, S2Point point) {
+  PointGeography(GeographyKind kind, S2Point point) {
     super(kind); // can be POINT or CELL_CENTER
+    if (kind != GeographyKind.POINT
+        && kind != GeographyKind.SINGLEPOINT
+        && kind != GeographyKind.CELL_CENTER) {
+      throw new IllegalArgumentException("Invalid GeographyKind for 
PointGeography: " + kind);
+    }
     points.add(point);
   }
 
@@ -239,6 +244,10 @@ public class PointGeography extends S2Geography {
       pts = S2Point.Shape.FAST_CODER.decode(bytes, cursor);
     }
 
+    if (tag.getKind() == GeographyKind.SINGLEPOINT) {
+      return new SinglePointGeography(pts.get(0));
+    }
+
     geo.points.addAll(pts);
     return geo;
   }
diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
 
b/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
index 030418268e..b57b7df664 100644
--- 
a/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
+++ 
b/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
@@ -58,6 +58,15 @@ public class PolylineGeography extends S2Geography {
     this.polylines = new ArrayList<>(polylines);
   }
 
+  public PolylineGeography(GeographyKind kind, S2Polyline polyline) {
+    super(kind);
+    if (kind != GeographyKind.POLYLINE && kind != 
GeographyKind.SINGLEPOLYLINE) {
+      throw new IllegalArgumentException("Invalid GeographyKind for 
PolylineGeography: " + kind);
+    }
+    this.polylines = new ArrayList<>();
+    this.polylines.add(polyline);
+  }
+
   @Override
   public int dimension() {
     return polylines.isEmpty() ? -1 : 1;
@@ -137,6 +146,10 @@ public class PolylineGeography extends S2Geography {
     // 5) Read the number of polylines (4-byte)
     int count = in.readInt();
 
+    if (tag.getKind() == GeographyKind.SINGLEPOLYLINE) {
+      return new SinglePolylineGeography(S2Polyline.decode(in));
+    }
+
     // 6) For each polyline, read its block and let 
S2Polyline.decode(InputStream) do the rest
     for (int i = 0; i < count; i++) {
       S2Polyline pl = S2Polyline.decode(in);
diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java 
b/common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java
index 9c257c76da..b352e6c3f2 100644
--- a/common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java
+++ b/common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java
@@ -24,6 +24,7 @@ import com.google.common.geometry.*;
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
+import org.locationtech.jts.geom.PrecisionModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,7 +57,9 @@ public abstract class S2Geography {
     GEOGRAPHY_COLLECTION(4),
     SHAPE_INDEX(5),
     ENCODED_SHAPE_INDEX(6),
-    CELL_CENTER(7);
+    CELL_CENTER(7),
+    SINGLEPOINT(8),
+    SINGLEPOLYLINE(9);
 
     private final int kind;
 
@@ -140,6 +143,21 @@ public abstract class S2Geography {
     region.getCellUnionBound(cellIds);
   }
 
+  @Override
+  public String toString() {
+    return this.toText(new PrecisionModel());
+  }
+
+  public String toString(PrecisionModel precisionModel) {
+    return this.toText(precisionModel);
+  }
+
+  public String toText(PrecisionModel precisionModel) {
+    WKTWriter writer = new WKTWriter();
+    writer.setPrecisionModel(precisionModel);
+    return writer.write(this);
+  }
+
   // ─── Encoding / decoding machinery 
────────────────────────────────────────────
   /**
    * Serialize this geography to an encoder. This does not include any 
encapsulating information
@@ -189,7 +207,7 @@ public abstract class S2Geography {
     out.flush();
   }
 
-  public S2Geography decodeTagged(InputStream is) throws IOException {
+  public static S2Geography decodeTagged(InputStream is) throws IOException {
     // wrap ONCE
     UnsafeInput kryoIn = new UnsafeInput(is, BUFFER_SIZE);
     EncodeTag topTag = EncodeTag.decode(kryoIn);
@@ -202,8 +220,10 @@ public abstract class S2Geography {
     switch (tag.getKind()) {
       case CELL_CENTER:
       case POINT:
+      case SINGLEPOINT:
         return PointGeography.decode(in, tag);
       case POLYLINE:
+      case SINGLEPOLYLINE:
         return PolylineGeography.decode(in, tag);
       case POLYGON:
         return PolygonGeography.decode(in, tag);
diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePointGeography.java
 
b/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePointGeography.java
index f546b0c38d..1b04bc1fd8 100644
--- 
a/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePointGeography.java
+++ 
b/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePointGeography.java
@@ -22,7 +22,7 @@ import com.google.common.geometry.S2Point;
 
 public class SinglePointGeography extends PointGeography {
   public SinglePointGeography(S2Point p) {
-    super(p);
+    super(GeographyKind.SINGLEPOINT, p);
   }
 
   public SinglePointGeography() {
diff --git 
a/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePolylineGeography.java
 
b/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePolylineGeography.java
index 2417c39aa7..d5e7342065 100644
--- 
a/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePolylineGeography.java
+++ 
b/common/src/main/java/org/apache/sedona/common/S2Geography/SinglePolylineGeography.java
@@ -22,7 +22,7 @@ import com.google.common.geometry.S2Polyline;
 
 public class SinglePolylineGeography extends PolylineGeography {
   public SinglePolylineGeography(S2Polyline p) {
-    super(p);
+    super(GeographyKind.SINGLEPOLYLINE, p);
   }
 
   public SinglePolylineGeography() {
diff --git 
a/common/src/test/java/org/apache/sedona/common/S2Geography/WKBReaderTest.java 
b/common/src/test/java/org/apache/sedona/common/S2Geography/WKBReaderTest.java
index 76a2086eeb..85313bf825 100644
--- 
a/common/src/test/java/org/apache/sedona/common/S2Geography/WKBReaderTest.java
+++ 
b/common/src/test/java/org/apache/sedona/common/S2Geography/WKBReaderTest.java
@@ -59,7 +59,7 @@ public class WKBReaderTest {
     S2Geography geo = reader.read(wkb);
 
     // Kind should be POINT
-    Assert.assertEquals(S2Geography.GeographyKind.POINT, geo.kind);
+    Assert.assertEquals(S2Geography.GeographyKind.SINGLEPOINT, geo.kind);
 
     // Extract the S2Point
     S2Point p = geo.shape(0).chain(0).get(0);
@@ -126,7 +126,7 @@ public class WKBReaderTest {
     S2Geography geo = reader.read(wkb);
 
     // Expect a POLYLINE geometry
-    Assert.assertEquals(S2Geography.GeographyKind.POLYLINE, geo.kind);
+    Assert.assertEquals(S2Geography.GeographyKind.SINGLEPOLYLINE, geo.kind);
 
     // Extract the two S2Points
     List<S2Point> pts = geo.shape(0).chain(0);

Reply via email to