feat(rust/sedona-functions): Add raster display support to SD_Format#591
feat(rust/sedona-functions): Add raster display support to SD_Format#591paleolimbot merged 5 commits intoapache:mainfrom
Conversation
Add raster formatting to SD_Format, displaying raster metadata (dimensions, geotransform, band count, outdb status) as a human-readable string instead of erroring on raster types.
1a373db to
f810dea
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds raster formatting support to the SD_Format function, enabling raster types to be displayed as human-readable strings. Previously, SD_Format returned an error when encountering raster types. Now it produces formatted output showing key metadata such as dimensions, geotransform parameters, band count, and OutDb status.
Changes:
- Modified
SD_Formatto support raster types by adding a newraster_value_to_formatted_valuefunction - Updated type conversion logic to map raster types to UTF8 output instead of returning an error
- Added
sedona-rasterdependency tosedona-functions
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rust/sedona-functions/src/sd_format.rs | Adds raster formatting logic with metadata display and width_hint support |
| rust/sedona-functions/Cargo.toml | Adds sedona-raster workspace dependency |
| Cargo.lock | Updates lock file with sedona-raster dependency for sedona-functions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
94bd826 to
88f92b2
Compare
| let _ = write!( | ||
| limited_output, | ||
| "Raster[w={}, h={}, ul=({:.6}, {:.6}), scale=({:.6}, {:.6}), skew=({:.6}, {:.6}), bands={}, outdb={}]", | ||
| metadata.width(), | ||
| metadata.height(), | ||
| metadata.upper_left_x(), | ||
| metadata.upper_left_y(), | ||
| metadata.scale_x(), | ||
| metadata.scale_y(), | ||
| metadata.skew_x(), | ||
| metadata.skew_y(), | ||
| bands.len(), | ||
| has_outdb_band | ||
| ); |
There was a problem hiding this comment.
At least for rasters that are not rotated or skewed, what I would really like to know are the bounds and CRS. Can this output be more like:
[WxH/nbands] @ [xmin ymin xmax ymax] / crs <outdb>
That may be a little more compact. Even for skewed data the 2D bounds are probably more useful output for human reading.
(Drawing from the last time I had to decide this: https://paleolimbot.github.io/wk/reference/grd.html )
There was a problem hiding this comment.
OK. I believe that this format requires the CRS to be abbreviated when it is possible. I'll submit the patch for refactoring the CRS abbreviation cache for ST_SetCRS before implementing this raster display format.
Move raster formatting from sd_format.rs into a new RasterDisplay wrapper
in sedona-raster/src/display.rs, per review feedback to keep display logic
in the raster crate.
Change the display format from raw geotransform parameters to show
axis-aligned bounding box and CRS, inspired by the wk R package:
RASTER [WxH/nbands] @ [xmin ymin xmax ymax] / CRS
Skew info is conditionally included when the raster is rotated.
PROJJSON CRS is shown as {...} to keep output compact.
Co-authored-by: Dewey Dunnington <dewey@dunnington.ca>
paleolimbot
left a comment
There was a problem hiding this comment.
I'm going to merge this since the lack of table output for rasters means we the examples we add error while rendering (e.g., #638), and not including those examples is more follow up work. I've created a follow up for the cache issue and if there are any outstanding issues!
Summary
SD_Format, displaying raster metadata (dimensions, geotransform, band count, outdb status) as a human-readable stringSD_Formatreturned an error for raster types; now it produces output like:Raster[w=1, h=2, ul=(1.000000, 2.000000), scale=(0.000000, -0.000000), skew=(0.000000, 0.000000), bands=1, outdb=false]width_hintoption for truncationsedona-rasterdependency tosedona-functionsExample