Skip to content

[GH-1996] Create object of S2Geography, and implement Point/Polyline/PolygonGeography with its encoder/decoder#1992

Merged
jiayuasu merged 15 commits into
apache:masterfrom
ZhuochengShang:zshang
Jul 1, 2025
Merged

[GH-1996] Create object of S2Geography, and implement Point/Polyline/PolygonGeography with its encoder/decoder#1992
jiayuasu merged 15 commits into
apache:masterfrom
ZhuochengShang:zshang

Conversation

@ZhuochengShang
Copy link
Copy Markdown
Collaborator

@ZhuochengShang ZhuochengShang commented Jun 20, 2025

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.

What changes were proposed in this PR?

The first step of porting https://github.com/paleolimbot/s2geography, ported S2Geography base class and 3 sub types.

How was this patch tested?

Added unit tests.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

@jiayuasu
Copy link
Copy Markdown
Member

@ZhuochengShang great work. Please create a GitHub issue and link the PR to that issue using [GH-XXXX]

@jiayuasu
Copy link
Copy Markdown
Member

Great work @ZhuochengShang . It is great to have a working PR that shows the progress. But when it is ready, we'd like to break it into a sequence of small PRs. This will make the review process easier.

@jiayuasu
Copy link
Copy Markdown
Member

Please also update the title of this PR to [GH-XXXX] that links to the GitHub issue.

@ZhuochengShang ZhuochengShang changed the title Create object of S2Geography, and implement PoinGeography with its en… [GH-1996]Create object of S2Geography, and implement PoinGeography with its en… Jun 20, 2025
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointShape.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointShape.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointShapeCoders.java Outdated
@paleolimbot
Copy link
Copy Markdown
Member

Thank you for this work so far! Just a note that if you (or Kristin or Jia) run across anything that doesn't make sense or is sub-optimial in the C++ version of S2Geography to let me know!

- Import org.datasyslab s2-geometry-library
- Clean up S2Geography abstract design
- Update Encode/Decode inside each kind of geography
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java Outdated
- Adding back EncodeTagged in S2Geography
- Let each geography type calls its own encode / decode function
- Change to use Kyro UnsafeInput and UnsafeOutput
Copy link
Copy Markdown
Member

@Kontinuation Kontinuation left a comment

Choose a reason for hiding this comment

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

The overall structure looks good. There are some additional comments mostly for the decoding part.

I also suggest that we add more comprehensive tests for encoding and decoding of geography objects. For instance, includeCovering option has not been tested for now. Adding a utility test function for round-trip encoding/decoding any geography objects and validate their equality would help writing such tests a lot.

Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/EncodeTag.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Outdated
Comment thread common/pom.xml Outdated
Comment thread common/pom.xml Outdated
Comment thread common/pom.xml Outdated
public class PolylineGeography extends S2Geography {
private static final Logger logger = Logger.getLogger(PolylineGeography.class.getName());

private final List<S2Polyline> polylines;
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.

We define PolylineGeography to contain a list of S2Polylines, which is different from the C++ version. I think this is a reasonable change, as it makes distinguishing between POLYGON and MULTIPOLYGON much easier as long as we ensure that each S2Polyline only contains one polygon. WDYT @paleolimbot

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.

I believe that Polyline in C++ is also a std::vector<S2Polyline>, but you're correct that the polygon is defined this way.

Paul (PostGIS) complained about this too, mostly because some multipolygons don't roundtrip through WKB/T/JTS. I've personally found it easier to keep the S2-centric structure since a lot of the time internally it doesn't matter. Either way is fine!

Comment thread common/src/test/java/org/apache/sedona/common/S2Geography/PointGeographyTest.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Outdated
@jiayuasu jiayuasu requested a review from Copilot June 27, 2025 20:00
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

Adds support for S2Geography objects (Point, Polyline, Polygon) with Kryo‐based encoding/decoding and corresponding round‐trip tests, and updates the S2 library dependency.

  • Introduce S2Geography base class and PointGeography, PolylineGeography, PolygonGeography subclasses with encode/decode logic
  • Add TestHelper utility and unit tests for each geography type (round‐trip and covering assertions)
  • Update pom.xml to use the forked org.datasyslab:s2-geometry-library and shade Google’s S2 package

Reviewed Changes

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

Show a summary per file
File Description
common/src/main/java/org/apache/sedona/common/S2Geography/S2Geography.java Base abstract class and encoding/decoding machinery
common/src/main/java/org/apache/sedona/common/S2Geography/PointGeography.java Implements point encoding/decoding and optimized compact path
common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java Implements polyline path handling and (de)serialization
common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Implements single‐loop polygon handling and (de)serialization
common/src/test/java/org/apache/sedona/common/S2Geography/TestHelper.java Utility for verifying round‐trip correctness and coverings
common/src/test/java/org/apache/sedona/common/S2Geography/PointGeographyTest.java Point geography unit tests
common/src/test/java/org/apache/sedona/common/S2Geography/PolylineGeographyTest.java Polyline geography unit tests
common/src/test/java/org/apache/sedona/common/S2Geography/PolygonGeographyTest.java Polygon geography unit tests
common/pom.xml Swap in the forked S2 library and add shading for Google S2
Comments suppressed due to low confidence (1)

common/src/test/java/org/apache/sedona/common/S2Geography/TestHelper.java:83

  • [nitpick] The error message uses a hard-coded index '1' for both polygon and loop, but you are checking loop zero. Consider using the actual loop index (e.g., '0') or dynamically inserting the index to avoid confusion.
          "Loop count mismatch in polygon[" + 1 + "]", pgOrig.numLoops(), pgDec.numLoops());

Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java Outdated
@jiayuasu
Copy link
Copy Markdown
Member

What is the status of this PR?

Copy link
Copy Markdown
Member

@Kontinuation Kontinuation left a comment

Choose a reason for hiding this comment

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

There are some minor issues related to the revised PolygonGeography. I think this PR is close to completion.

Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Outdated
Comment thread common/src/main/java/org/apache/sedona/common/S2Geography/PolygonGeography.java Outdated
Copy link
Copy Markdown
Member

@Kontinuation Kontinuation left a comment

Choose a reason for hiding this comment

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

Now it looks good to me. Thank you for your great work @ZhuochengShang

@Kontinuation Kontinuation changed the title [GH-1996]Create object of S2Geography, and implement PoinGeography with its en… [GH-1996] Create object of S2Geography, and implement PoinGeography with its encoder/decoder Jul 1, 2025
@Kontinuation Kontinuation changed the title [GH-1996] Create object of S2Geography, and implement PoinGeography with its encoder/decoder [GH-1996] Create object of S2Geography, and implement Point/Polyline/PolygonGeography with its encoder/decoder Jul 1, 2025
@jiayuasu jiayuasu added this to the sedona-1.8.0 milestone Jul 1, 2025
@jiayuasu jiayuasu merged commit cf01102 into apache:master Jul 1, 2025
35 checks passed
@paleolimbot
Copy link
Copy Markdown
Member

Awesome!

@ZhuochengShang ZhuochengShang deleted the zshang branch July 2, 2025 20:35
Kontinuation pushed a commit to Kontinuation/sedona that referenced this pull request Jan 21, 2026
…yline/PolygonGeography with its encoder/decoder (apache#1992)

* Create object of S2Geography, and implement PoinGeography with its encoder/decoder

* Add POLYLINE implementation on S2Geography

* Add POLYGON implements on S2Geography

* Match coding style

* "Apply Spotless formatting to PolylineGeographyTest"

* Redesign of S2Geography

- Import org.datasyslab s2-geometry-library
- Clean up S2Geography abstract design
- Update Encode/Decode inside each kind of geography

* clean up unnecessary files in current branch

* Refine design of EncodeTagged in S2Geography

- Adding back EncodeTagged in S2Geography
- Let each geography type calls its own encode / decode function
- Change to use Kyro UnsafeInput and UnsafeOutput

* Modify encoder() and add new test cases

* clean up code of encode and clarify comments

* Update POLYGON to only take one polygon

* Remove S2Regionwrapper & S2Shapewrapper

* clean up minor issue

* resolve minor issue with PolygonGeography
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants