jiayuasu opened a new issue, #3267:
URL: https://github.com/apache/sedona/issues/3267

   ## Background
   
   Sedona's compact Java geometry serializer already has wire-format tags for 
XY, XYZ, XYM, and XYZM coordinates. Spark's `GeometryUDT` and Flink's 
`GeometryTypeSerializer` both depend on this serializer when geometries cross 
execution or persistence boundaries.
   
   The writer currently chooses the coordinate layout from a geometry's first 
coordinate and checks whether that coordinate has finite Z and M values. This 
can discard recoverable dimensional information:
   
   - `LINESTRING Z (0 0 NaN, 1 1 3)` is encoded as XY because the first Z is 
NaN, so the later Z value is lost.
   - A multipart geometry can lose Z or M when the first member does not 
establish the layout but a later member does.
   - Coordinate-sequence measure metadata is ignored, so an XYM or XYZM 
sequence whose measure is NaN can be downgraded.
   - Empty Point and Polygon buffers are always written and reconstructed as 
XY, even when their coordinate sequence unambiguously carries M or ZM metadata.
   
   This became more visible while adding exact all-dimension equality in #3266, 
but it is a pre-existing GeometrySerde issue and should be fixed independently.
   
   ## Proposed behavior
   
   - Inspect every coordinate sequence rather than only the first coordinate.
   - Use explicit measure metadata for XYM and XYZM layouts.
   - Scan ambiguous three-dimensional JTS sequences for a finite Z beyond the 
first coordinate.
   - Inspect all polygon rings and multipart members.
   - Preserve recoverable M and ZM metadata for empty Point, LineString, 
Polygon, and typed empty multipart children when deserializing.
   - Reject recoverably heterogeneous layouts inside one Polygon or multipart 
geometry. The current compact format has one coordinate-layout header for the 
entire value, so silently choosing or promoting one layout cannot preserve 
every component's identity. A `GeometryCollection` remains available for 
heterogeneous layouts.
   - Keep the existing binary format and coordinate-layout tag values so 
previously serialized data remains readable.
   
   ## JTS representation boundary
   
   JTS 1.20's default coordinate-sequence factory represents both ordinary XY 
coordinates and declared XYZ coordinates whose Z values are all NaN as 
`dimension=3, measures=0` sequences. The default WKT reader therefore makes 
`POINT (1 2)` and `POINT Z (1 2 NaN)` indistinguishable before Sedona 
serialization begins. The serializer must continue normalizing that ambiguous 
case to XY rather than promoting ordinary XY data to XYZ.
   
   Similarly, a zero-member multipart or geometry collection exposes no child 
coordinate sequence from which a dimensional qualifier can be recovered. These 
cases require a broader construction or wire-format design if exact 
declared-dimension preservation is needed later.
   
   ## Validation
   
   Add focused round-trip coverage for:
   
   - leading-NaN XYZ, XYM, and XYZM coordinates;
   - later multipart members establishing a recoverable layout;
   - all-NaN measure metadata;
   - typed M/ZM empty atomic geometries and multipart children;
   - heterogeneous `GeometryCollection` children;
   - rejection of recoverably mixed Polygon or multipart layouts; and
   - ordinary default-JTS XY geometries remaining XY.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to