paleolimbot commented on code in PR #591: URL: https://github.com/apache/sedona-db/pull/591#discussion_r2818141499
########## rust/sedona-raster/src/display.rs: ########## @@ -0,0 +1,163 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::fmt; + +use crate::affine_transformation::to_world_coordinate; +use crate::traits::RasterRef; +use sedona_schema::raster::StorageType; + +/// Wrapper for formatting a raster reference as a human-readable string. +/// +/// # Format +/// +/// Non-skewed rasters: +/// ```text +/// RASTER [WxH/nbands] @ [xmin ymin xmax ymax] / CRS +/// ``` +/// +/// Skewed rasters (includes skew parameters): +/// ```text +/// RASTER [WxH/nbands] @ [xmin ymin xmax ymax] skew=(skew_x, skew_y) / CRS +/// ``` +/// +/// With outdb bands: +/// ```text +/// RASTER [WxH/nbands] @ [xmin ymin xmax ymax] / CRS <outdb> +/// ``` +/// +/// Without CRS: +/// ```text +/// RASTER [WxH/nbands] @ [xmin ymin xmax ymax] +/// ``` +/// +/// # Examples +/// +/// ```text +/// RASTER [64x32/3] @ [43.08 79.07 171.08 143.07] / OGC:CRS84 +/// RASTER [3x4/1] @ [3 2.4 3.84 4.24] skew=(0.06, 0.08) / EPSG:2193 +/// RASTER [10x10/1] @ [0 0 10 10] / OGC:CRS84 <outdb> +/// ``` +pub struct RasterDisplay<'a>(pub &'a dyn RasterRef); + +impl fmt::Display for RasterDisplay<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let raster = self.0; + let metadata = raster.metadata(); + let bands = raster.bands(); + + let width = metadata.width(); + let height = metadata.height(); + let nbands = bands.len(); + + // Compute axis-aligned bounding box from 4 corners in world coordinates. + // This handles both skewed and non-skewed rasters correctly. + let w = width as i64; + let h = height as i64; + let (ulx, uly) = to_world_coordinate(raster, 0, 0); + let (urx, ury) = to_world_coordinate(raster, w, 0); + let (lrx, lry) = to_world_coordinate(raster, w, h); + let (llx, lly) = to_world_coordinate(raster, 0, h); + + let xmin = ulx.min(urx).min(lrx).min(llx); + let xmax = ulx.max(urx).max(lrx).max(llx); + let ymin = uly.min(ury).min(lry).min(lly); + let ymax = uly.max(ury).max(lry).max(lly); + + let skew_x = metadata.skew_x(); + let skew_y = metadata.skew_y(); + let has_skew = skew_x != 0.0 || skew_y != 0.0; + + let has_outdb = bands + .iter() + .any(|band| matches!(band.metadata().storage_type(), Ok(StorageType::OutDbRef))); + + // Write: RASTER [WxH/nbands] @ [xmin ymin xmax ymax] + write!( + f, + "RASTER [{width}x{height}/{nbands}] @ [{xmin} {ymin} {xmax} {ymax}]" + )?; Review Comment: In SedonaDB we have the good fortune of getting to print the type name at the top of the column, so I think we can get seven characters of width back for each item: ```suggestion // Write: [WxH/nbands] @ [xmin ymin xmax ymax] write!( f, "[{width}x{height}/{nbands}] @ [{xmin} {ymin} {xmax} {ymax}]" )?; ``` -- 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]
