paleolimbot opened a new pull request, #848:
URL: https://github.com/apache/sedona-db/pull/848

   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.
   
   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).
   
   ```python
   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} │
   # └────────────────────────────────────┘
   ```


-- 
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