You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "james-willis (via GitHub)" <gi...@apache.org> on 2026/10/01 21:32:33 UTC

[I] GEOS-backed functions drop Z/M from empty geometries [sedona-db]

james-willis opened a new issue, #1384:
URL: https://github.com/apache/sedona-db/issues/1384

   GEOS-backed functions return a 2-D empty when given a Z (or M) empty geometry. For example, `POINT Z EMPTY` comes back as `POINT EMPTY`. GEOS itself keeps the dimension: Shapely on the same GEOS (3.13.1) returns `POINT Z EMPTY`.
   
   Found while testing the sedonadb-geopandas wrappers in apache/sedona-db#1354.
   
   ## Repro
   
   ```python
   import sedona.db
   
   sd = sedona.db.connect()
   sd.sql("""
   WITH t AS (SELECT ST_GeomFromWKT('POINT Z EMPTY') AS g)
   SELECT ST_AsText(g) AS roundtrip,
          ST_AsText(ST_FlipCoordinates(g)) AS flip,
          ST_AsText(ST_Simplify(g, 1)) AS simplify,
          ST_AsText(ST_Normalize(g)) AS normalize,
          ST_AsText(ST_MakeValid(g)) AS make_valid,
          ST_AsText(ST_Centroid(g)) AS centroid,
          ST_AsText(ST_PointOnSurface(g)) AS point_on_surface
   FROM t
   """).show()
   ```
   
   | | SedonaDB | Shapely 2.1.2 / GEOS 3.13.1 |
   |---|---|---|
   | round trip | `POINT Z EMPTY` | `POINT Z EMPTY` |
   | `ST_FlipCoordinates` (not GEOS) | `POINT Z EMPTY` | n/a |
   | `ST_Simplify` / `ST_SimplifyPreserveTopology` | `POINT EMPTY` | `POINT Z EMPTY` |
   | `ST_Normalize` | `POINT EMPTY` | `POINT Z EMPTY` |
   | `ST_MakeValid` | `POINT EMPTY` | `POINT Z EMPTY` |
   | `ST_Centroid` / `ST_PointOnSurface` | `POINT EMPTY` | `POINT Z EMPTY` |
   
   `LINESTRING Z EMPTY` and `POLYGON Z EMPTY` behave the same way. So do `POINT M EMPTY`, `POINT ZM EMPTY`, `MULTIPOINT Z EMPTY` and `GEOMETRYCOLLECTION Z EMPTY`, which all come back 2-D from `ST_Normalize`. Non-empty Z geometries keep their Z. For example, `ST_Simplify` on a `LINESTRING Z` returns a `LINESTRING Z`.
   
   ## Cause
   
   The input conversion in `c/sedona-geos/src/wkb_to_geos.rs` handles empties with the dimensionless constructors: `create_empty_point()`, `create_empty_line_string()`, `create_empty_polygon()` and `create_empty_collection(..)`. These always create an XY geometry, so the Z/M dimension in the input WKB is lost before GEOS runs. The non-empty paths pass the WKB dimension through to the coordinate sequence and are unaffected.
   
   A likely fix is to build empties from an empty coordinate sequence with the input's dimension. `geos_to_wkb.rs` already writes the output dimension from `has_z()`/`has_m()`, and GEOS 3.12+ reports `has_z() == true` for a Z empty, so the output side should then round-trip. A regression test over `{POINT, LINESTRING, POLYGON, MULTI*, GEOMETRYCOLLECTION} {Z, M, ZM} EMPTY` through a GEOS-backed function would cover it.
   
   ## Versions
   
   - SedonaDB built from main (the conversion code is unchanged at `bdbfb7f97`)
   - Expected values from Shapely 2.1.2 / GEOS 3.13.1
   


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org