Skip to content

Conversation

@paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Jan 21, 2026

This PR implements an EWKB writer and uses it to implement ST_AsEWKB.

import sedona.db

sd = sedona.db.connect()

sd.sql("SELECT ST_AsEWKB(ST_GeomFromEWKT('SRID=26920;POINT (0 1)')) as ewkb").show()
#> ┌────────────────────────────────────────────────────┐
#> │                        ewkb                        │
#> │                       binary                       │
#> ╞════════════════════════════════════════════════════╡
#> │ 0101000020286900000000000000000000000000000000f03f │
#> └────────────────────────────────────────────────────┘

# Regular binary is shorter because it doesn't have the embedded SRID
sd.sql("SELECT ST_AsBinary(ST_GeomFromEWKT('SRID=26920;POINT (0 1)')) as ewkb").show()
#> ┌────────────────────────────────────────────┐
#> │                    ewkb                    │
#> │                   binary                   │
#> ╞════════════════════════════════════════════╡
#> │ 01010000000000000000000000000000000000f03f │
#> └────────────────────────────────────────────┘

@paleolimbot paleolimbot requested a review from Copilot January 22, 2026 06:18
Copy link
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 implements the ST_AsEWKB function with support for CRS (Coordinate Reference System) metadata, enabling EWKB (Extended Well-Known Binary) output that includes SRID information.

Changes:

  • Adds EWKB writer implementation with SRID support for all geometry types
  • Implements ST_AsEWKB scalar UDF with both type-level and item-level CRS support
  • Adds comprehensive test coverage for EWKB serialization across geometry types and dimensions

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rust/sedona-geometry/src/lib.rs Exports new ewkb_factory module
rust/sedona-geometry/src/ewkb_factory.rs Implements EWKB writer with SRID encoding for all geometry types
rust/sedona-functions/src/st_asewkb.rs Implements ST_AsEWKB UDF with CRS support
rust/sedona-functions/src/register.rs Registers ST_AsEWKB function in default function set
rust/sedona-functions/src/lib.rs Declares st_asewkb module
rust/sedona-functions/src/executor.rs Adds support for iterating over item CRS struct types
python/sedonadb/tests/functions/test_wkb.py Adds parametrized tests comparing SedonaDB and PostGIS EWKB output
python/sedonadb/python/sedonadb/testing.py Extends geom_or_null helper to support SRID parameter
python/sedonadb/pyproject.toml Adds pandas version constraint as workaround

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@paleolimbot paleolimbot marked this pull request as ready for review January 22, 2026 06:23
}
}

const ROUNDTRIP_CASES: [&str; 56] = [
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test case that have very large SRID values and nested GeometryCollection?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call! A few questionable things were happening for CRSes that couldn't be cleanly exported as an SRID

Copy link
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.

Looks good. Hope that georust/wkb will directly support writing EWKB. It supports parsing EWKB so writing EWKB is probably a reasonable feature to have in georust/wkb.

Comment on lines +386 to +389
ScalarValue::Struct(s)
if s.fields().len() == 2
&& s.fields()[0].name() == "item"
&& s.fields()[1].name() == "crs" =>
Copy link
Member

Choose a reason for hiding this comment

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

If I remember it correctly, this pattern for decomposing fields in struct type representing item with crs has appeared many times in the code base. Maybe we can define a helper method for doing this.

@paleolimbot
Copy link
Member Author

Hope that georust/wkb will directly support writing EWKB.

Agreed! I can make a PR with roughly this at some point.

this pattern for decomposing fields in struct type representing item with crs has appeared many times in the code base

Agreed! I opened a follow-up for this ( #546 ). It was tricky to implement a helper initially because there are slightly different requirements in various places but I think we're close to the point where we've collected all the patterns we'll need.

@paleolimbot paleolimbot changed the title feat(rust/sedona-function): Implement ST_AsEWKB with item CRS support feat(rust/sedona-functions): Implement ST_AsEWKB with item CRS support Jan 23, 2026
@paleolimbot paleolimbot merged commit ace5542 into apache:main Jan 23, 2026
15 checks passed
@paleolimbot paleolimbot deleted the st-ewkb-fns branch January 23, 2026 17:56
@paleolimbot paleolimbot added this to the 0.3.0 milestone Jan 26, 2026
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