Skip to content

[GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure#2975

Open
zhangfengcdt wants to merge 4 commits into
apache:masterfrom
zhangfengcdt:bugfix/wkbgeography.write
Open

[GH-2830] Fix S2 Geography WKB writer to emit OGC-conformant polygon closure#2975
zhangfengcdt wants to merge 4 commits into
apache:masterfrom
zhangfengcdt:bugfix/wkbgeography.write

Conversation

@zhangfengcdt
Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

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.

@zhangfengcdt zhangfengcdt marked this pull request as ready for review May 19, 2026 22:56
@zhangfengcdt zhangfengcdt requested a review from jiayuasu as a code owner May 19, 2026 22:56
@zhangfengcdt zhangfengcdt requested a review from Copilot May 19, 2026 22:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Sedona’s S2Geography WKB serialization to emit OGC-conformant polygon rings by explicitly writing the closing vertex (last point equals first) for POLYGON and MULTIPOLYGON rings, and adds byte-level tests to enforce this invariant.

Changes:

  • Update WKBWriter.writePolygon to write numVertices + 1 coordinates per ring and duplicate the first vertex as the closing point.
  • Update WKBWriter.writeMultiPolygon to apply the same N+1 ring closure behavior for each polygon/ring.
  • Add unit tests that parse the emitted WKB byte stream to verify ring point counts and closure for POLYGON and MULTIPOLYGON.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java Writes OGC-closed rings by emitting an explicit closing coordinate for polygon rings.
common/src/test/java/org/apache/sedona/common/S2Geography/WKBWriterTest.java Adds byte-level tests to assert ring closure for POLYGON and MULTIPOLYGON WKB output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/WKBWriter.java Outdated
os.write(buf, 8);
ByteOrderValues.putDouble(lat, buf, byteOrder);
os.write(buf, 8);
if (n == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems to be duplicate of Line 327?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants