Skip to content

feat(rust/sedona-functions,c/sedona-proj): Support geography in CRS/SRID functions#848

Open
paleolimbot wants to merge 9 commits into
apache:mainfrom
paleolimbot:geog-crs-defaults
Open

feat(rust/sedona-functions,c/sedona-proj): Support geography in CRS/SRID functions#848
paleolimbot wants to merge 9 commits into
apache:mainfrom
paleolimbot:geog-crs-defaults

Conversation

@paleolimbot
Copy link
Copy Markdown
Member

@paleolimbot paleolimbot commented May 15, 2026

This PR adds support for Geography in functions that work with CRSes. There was limited support for Geography with item-crs but it had been excluded from ST_Transform and ST_SetSRID and the srid-setting shortcuts in ST_Point and friends.

This PR also validates target CRSes so that it's harder to specify an invalid crs in ST_SetSRID or ST_Transform. This isn't perfect...CRSes that contain an elevation aren't going to be validated here but there are workarounds (specify a 2D crs, which will leave the Z values intact, and restore the 3D crs on the trip back to geometry).

I'm not sure exaclty what the use case is for item crs with geography but it was easy enough to support here so I went for it. Supporting NAD83 is probably useful because I think the average radius over north america is slightly more accurate (but still not a replacement for true geodescic edge support).

import pyproj
import sedona.db

sd = sedona.db.connect()

# Defaults to ogc:crs84
sd.sql("SELECT ST_GeogFromWKT('POINT (0 1)')").schema
# SedonaSchema with 1 field:
#   st_geogfromwkt(Utf8("POINT (0 1)")): geography<Wkb(ogc:crs84, Spherical)>

# Can be other stuff like NAD27
sd.sql("SELECT ST_GeogFromWKT('POINT (0 1)', 'EPSG:4267')").schema
# SedonaSchema with 1 field:
#   st_geogfromwkt(Utf8("POINT (0 1)"),Utf8("EPSG:4267")): geography<Wkb(epsg:4267, Spherical)>

# Works for any GeographicCRS if PROJJSON (even on Mars!)
mars_crs = pyproj.CRS('IAU:49900')

sd.sql("SELECT ST_GeogFromWKT('POINT (0 1)', $1)", params=(mars_crs, )).schema
# SedonaSchema with 1 field:
#   st_geogfromwkt(Utf8("POINT (0 1)"),$1): geography<Wkb(iau:49900, Spherical)>

# Works for item/crs case if you are searching for ways to make your life difficult
# Only works with a few hard-coded auth:code combinations for now
sd.sql("""
    SELECT ST_GeogFromWKT('POINT (0 1)', crs) AS geog
    FROM (VALUES 
        ('EPSG:4326'),
        ('EPSG:4267'),
        ('EPSG:4269')
    ) AS t(crs)
""").show()
# ┌────────────────────────────────────┐
# │                geog                │
# │               struct               │
# ╞════════════════════════════════════╡
# │ {item: POINT(0 1), crs: OGC:CRS84} │
# ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │ {item: POINT(0 1), crs: EPSG:4267} │
# ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
# │ {item: POINT(0 1), crs: EPSG:4269} │
# └────────────────────────────────────┘

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions github-actions Bot requested a review from prantogg May 15, 2026 20:30
@paleolimbot paleolimbot requested review from Copilot and removed request for prantogg May 15, 2026 21:52
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

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

Comment thread rust/sedona-schema/src/crs.rs Outdated
Comment thread rust/sedona-schema/src/crs.rs Outdated
Comment thread rust/sedona-schema/src/crs.rs Outdated
Comment thread rust/sedona-schema/src/datatypes.rs Outdated
Comment thread rust/sedona-schema/src/crs.rs Outdated
Comment thread c/sedona-proj/src/st_transform.rs Outdated
Comment thread rust/sedona-functions/src/st_setsrid.rs
Comment thread rust/sedona-schema/src/crs.rs
@paleolimbot paleolimbot marked this pull request as ready for review May 15, 2026 22:51
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.

2 participants