Skip to content

[GH-3203] Preserve Geography coordinates and polygon ring semantics - #3207

Merged
jiayuasu merged 8 commits into
apache:masterfrom
jiayuasu:fix/geography-wkb-text
Jul 30, 2026
Merged

[GH-3203] Preserve Geography coordinates and polygon ring semantics#3207
jiayuasu merged 8 commits into
apache:masterfrom
jiayuasu:fix/geography-wkb-text

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Jul 29, 2026

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

  • Render default WKBGeography.toString() and toEWKT() output from the authoritative stored WKB/JTS representation.
  • Preserve exact coordinates, positive SRIDs, repeated LineString vertices, and empty polygons without an unnecessary S2 round trip.
  • Build ST_GeomToGeography values directly from JTS WKB so conversion does not introduce longitude/latitude drift.
  • Interpret polygon rings by their simple-features roles in all public Geography readers: the first ring is the shell and subsequent rings are holes, regardless of input winding.
  • Preserve the submitted WKB and coordinate order for structural output while normalizing only the S2-facing traversal used by spherical predicates.
  • Keep the explicit PrecisionModel text overloads on the S2 writer for callers that request precision-controlled output.
  • Add an internal orientation-preserving shape conversion for raster distance predicates. This keeps reprojected raster footprints directed when they cover more than a hemisphere without changing public Geography semantics.

Spark DataFrame display now agrees with WKB-backed structural functions such as ST_AsText. Spark and Flink use the same Geography reader and predicate behavior.

Polygon semantics

Public Geography polygon shells are normalized to an area of at most one hemisphere. A shell intended to represent more than half the sphere is interpreted as its complement, and reversing its coordinate sequence does not select the larger region. Structural WKB/WKT remains unchanged.

Raster distance predicates are the deliberate exception. Their internal conversion preserves the orientation of a reprojected raster footprint because that directed footprint may legitimately cover more than half the sphere.

Performance

The single-ring WkbS2Shape path computes orientation and origin containment without an additional full edge scan. In a local warmed-up benchmark using a 25,000-vertex polygon:

  • normalized shape construction: 1.406 ms, compared with 1.514 ms before the fast path;
  • ShapeIndex construction: 1.390 ms, compared with 1.480 ms;
  • cached predicate refinement: 291 ns versus 295 ns, within measurement noise;
  • the internal directed raster shape path: 0.428 ms.

How was this patch tested?

  • Full common module suite: 1,211 tests, 0 failures.
  • Spark 4.1 BroadcastIndexJoinSuite: 66 tests, 0 failures, including raster RS_DWithin coverage.
  • Flink Geography suites: 39 tests, 0 failures.
  • Added WKT, WKB, serialization, polygon winding, shell/hole, repeated-vertex, near-hemisphere, raster-footprint, nested collection, and empty-polygon regression coverage.
  • Spotless, Markdown lint, and commit hooks passed.

Did this PR include necessary documentation updates?

  • Yes. Spark SQL and Flink documentation now describe simple-feature polygon ring roles and the at-most-one-hemisphere behavior for ST_Area, ST_Contains, ST_Intersects, and ST_Within.
  • The existing predicate SVGs remain unchanged because they depict valid sub-hemisphere relationships and do not imply winding-sensitive behavior.

@jiayuasu
jiayuasu force-pushed the fix/geography-wkb-text branch from 410080d to e9c065c Compare July 29, 2026 17:48
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone Jul 30, 2026
@jiayuasu jiayuasu changed the title [GH-3203] Preserve WKB Geography text coordinates [GH-3203] Preserve Geography coordinates and polygon ring semantics Jul 30, 2026
@jiayuasu
jiayuasu marked this pull request as ready for review July 30, 2026 07:56
@jiayuasu
jiayuasu merged commit 6f2106b into apache:master Jul 30, 2026
44 checks passed
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.

[BUG]: WKBGeography object rendering truncates coordinates

1 participant