You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "zhangfengcdt (via GitHub)" <gi...@apache.org> on 2026/05/19 17:24:55 UTC
[PR] [GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure [sedona]
zhangfengcdt opened a new pull request, #2975:
URL: https://github.com/apache/sedona/pull/2975
## Did you read the Contributor Guide?
- Yes, I have read the [Contributor Rules](https://sedona.apache.org/latest/community/rule/) and [Contributor Development Guide](https://sedona.apache.org/latest/community/develop/)
## Is this PR related to a ticket?
- Yes, and the PR name follows the format `[GH-XXX] my subject`. Closes #<issue_number>
## What changes were proposed in this PR?
Fix WKBGeography.getWKBBytes() to emit OGC-conformant (closed-ring) WKB.
## How was this patch tested?
- PolygonRingClosureTest — single-ring POLYGON, asserts num_points = 5 and point[4] == point[0].
- MultiPolygonRingClosureTest — walks the MULTIPOLYGON byte stream and asserts each ring's closure.
## Did this PR include necessary documentation updates?
- No, this PR does not affect any public API so no need to change the documentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure [sedona]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu merged PR #2975:
URL: https://github.com/apache/sedona/pull/2975
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure [sedona]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2975:
URL: https://github.com/apache/sedona/pull/2975#discussion_r3270199823
##########
common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java:
##########
@@ -317,10 +317,15 @@ private void writePolygon(int geometryType, PolygonGeography poly, OutStream os)
List<S2Loop> loops = s2poly.getLoops();
writeInt(loops.size(), os);
for (S2Loop loop : loops) {
+ // S2Loop stores N distinct vertices (loop is implicitly closed from
+ // vertex(n-1) back to vertex(0)). OGC WKB requires N+1 vertices with
+ // last == first. Emit the closing duplicate so downstream OGC-strict
+ // readers (e.g., geoarrow-c's WKB reader used by sedona-db's
+ // s2geography kernels) don't treat the ring as unclosed/degenerate.
int n = loop.numVertices();
- writeInt(n, os);
- for (int i = 0; i < n; i++) {
- S2LatLng ll = new S2LatLng(loop.vertex(i));
+ writeInt(n + 1, os);
+ for (int i = 0; i <= n; i++) {
+ S2LatLng ll = new S2LatLng(loop.vertex(i % n));
double lon = ll.lngDegrees();
Review Comment:
`loop.numVertices()` can be 0 for degenerate loops (S2 supports loops with 0/1/2 vertices; see usage like `new S2Loop(vertices)` where `vertices` may be empty). The new `i % n` will throw `ArithmeticException` when `n == 0`, whereas the previous implementation would safely write a 0-point ring. Please guard `n == 0` (write 0 and skip coords) or avoid modulo by writing vertices 0..n-1 and then explicitly duplicating vertex(0) when n>0.
##########
common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java:
##########
@@ -358,12 +363,14 @@ private void writeMultiPolygon(int geometryType, MultiPolygonGeography multiPoly
List<S2Loop> loops = s2poly.polygon.getLoops();
writeInt(loops.size(), os);
- // 4c) For each ring, write vertex count + coords
+ // 4c) For each ring, write vertex count + coords.
+ // Emit N+1 vertices with last == first for OGC WKB compliance;
+ // see the explanatory comment in writePolygon().
for (S2Loop loop : loops) {
int n = loop.numVertices();
- writeInt(n, os);
- for (int i = 0; i < n; i++) {
- S2LatLng ll = new S2LatLng(loop.vertex(i));
+ writeInt(n + 1, os);
+ for (int i = 0; i <= n; i++) {
+ S2LatLng ll = new S2LatLng(loop.vertex(i % n));
double lon = ll.lngDegrees();
Review Comment:
Same `n == 0` regression as `writePolygon()`: `loop.vertex(i % n)` will crash on empty/degenerate rings. Please handle `n == 0` before writing `n+1` points, or write the closing point without modulo (write 0..n-1 then vertex(0) if n>0).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure [sedona]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on code in PR #2975:
URL: https://github.com/apache/sedona/pull/2975#discussion_r3276153520
##########
common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java:
##########
@@ -358,20 +373,21 @@ private void writeMultiPolygon(int geometryType, MultiPolygonGeography multiPoly
List<S2Loop> loops = s2poly.polygon.getLoops();
writeInt(loops.size(), os);
- // 4c) For each ring, write vertex count + coords
+ // 4c) For each ring, write vertex count + coords.
+ // Emit N+1 vertices with last == first for OGC WKB compliance; see the
+ // explanatory comment in writePolygon(). Degenerate empty rings
+ // (n == 0) keep the prior behavior of writing a 0-point ring.
for (S2Loop loop : loops) {
int n = loop.numVertices();
- writeInt(n, os);
- for (int i = 0; i < n; i++) {
- S2LatLng ll = new S2LatLng(loop.vertex(i));
- double lon = ll.lngDegrees();
- double lat = ll.latDegrees();
-
- // X (lon) then Y (lat)—matches Point/LineString ordering
- ByteOrderValues.putDouble(lon, buf, byteOrder);
- os.write(buf, 8);
- ByteOrderValues.putDouble(lat, buf, byteOrder);
- os.write(buf, 8);
+ if (n == 0) {
Review Comment:
This code seems to be duplicate of Line 327?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure [sedona]
Posted by "zhangfengcdt (via GitHub)" <gi...@apache.org>.
zhangfengcdt commented on code in PR #2975:
URL: https://github.com/apache/sedona/pull/2975#discussion_r3277596096
##########
common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java:
##########
@@ -358,20 +373,21 @@ private void writeMultiPolygon(int geometryType, MultiPolygonGeography multiPoly
List<S2Loop> loops = s2poly.polygon.getLoops();
writeInt(loops.size(), os);
- // 4c) For each ring, write vertex count + coords
+ // 4c) For each ring, write vertex count + coords.
+ // Emit N+1 vertices with last == first for OGC WKB compliance; see the
+ // explanatory comment in writePolygon(). Degenerate empty rings
+ // (n == 0) keep the prior behavior of writing a 0-point ring.
for (S2Loop loop : loops) {
int n = loop.numVertices();
- writeInt(n, os);
- for (int i = 0; i < n; i++) {
- S2LatLng ll = new S2LatLng(loop.vertex(i));
- double lon = ll.lngDegrees();
- double lat = ll.latDegrees();
-
- // X (lon) then Y (lat)—matches Point/LineString ordering
- ByteOrderValues.putDouble(lon, buf, byteOrder);
- os.write(buf, 8);
- ByteOrderValues.putDouble(lat, buf, byteOrder);
- os.write(buf, 8);
+ if (n == 0) {
Review Comment:
Yes, I have added a helper function to consolidate them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org