This is an automated email from the ASF dual-hosted git repository.

kontinuation pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sedona-db.git


The following commit(s) were added to refs/heads/main by this push:
     new 8faf2cf3 feat(rust/sedona-testing): Add test helpers for loading 
raster test data (#587)
8faf2cf3 is described below

commit 8faf2cf32a2e03c9e89f8bd23216c8507cc20f8c
Author: Kristin Cowalcijk <[email protected]>
AuthorDate: Tue Mar 3 19:26:21 2026 +0800

    feat(rust/sedona-testing): Add test helpers for loading raster test data 
(#587)
    
    ## Summary
    
    Relevant PR adding raster files to sedona-testing: 
https://github.com/apache/sedona-testing/pull/10
    
    - Add `test_raster(name)` function in `data.rs` for resolving paths to 
raster test files from the `sedona-testing` submodule, mirroring the existing 
`test_geoparquet()` pattern.
    - Add `raster_from_single_band()` function in `rasters.rs` for 
programmatically building minimal single-band rasters in unit tests without 
GDAL or file I/O.
    - Update `sedona-testing` submodule to include raster test data files.
    
    Co-authored-by: Dewey Dunnington <[email protected]>
---
 rust/sedona-testing/src/data.rs    | 30 ++++++++++++++++++++++++++++++
 rust/sedona-testing/src/rasters.rs | 37 +++++++++++++++++++++++++++++++++++++
 submodules/sedona-testing          |  2 +-
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/rust/sedona-testing/src/data.rs b/rust/sedona-testing/src/data.rs
index a6bd991f..1db628bf 100644
--- a/rust/sedona-testing/src/data.rs
+++ b/rust/sedona-testing/src/data.rs
@@ -125,6 +125,22 @@ pub fn sedona_testing_dir() -> Result<String> {
     )
 }
 
+/// Get the path to a raster test file from the sedona-testing data directory.
+pub fn test_raster(name: &str) -> Result<String> {
+    let base = sedona_testing_dir()?;
+    let path = format!("{}/data/raster/{}", base, name);
+    if fs::exists(&path)? {
+        Ok(path)
+    } else {
+        sedona_internal_err!(
+            "sedona-testing raster file '{}' not found at '{}', \
+             run submodules/download-assets.py or check the file name",
+            name,
+            path
+        )
+    }
+}
+
 #[cfg(test)]
 mod test {
     use super::*;
@@ -172,4 +188,18 @@ mod test {
         env::remove_var("SEDONA_TESTING_DIR");
         assert!(maybe_dir.is_ok());
     }
+
+    #[test]
+    fn test_raster_resolves() {
+        // Test that test_raster can find existing raster files
+        let path = test_raster("test4.tiff");
+        assert!(path.is_ok(), "Failed to find test4.tiff: {:?}", path.err());
+        let path_str = path.unwrap();
+        assert!(path_str.ends_with("test4.tiff"));
+        assert!(fs::exists(&path_str).unwrap());
+
+        // Test that non-existent files return an error
+        let err = test_raster("nonexistent.tiff");
+        assert!(err.is_err());
+    }
 }
diff --git a/rust/sedona-testing/src/rasters.rs 
b/rust/sedona-testing/src/rasters.rs
index aea072ca..2aab413c 100644
--- a/rust/sedona-testing/src/rasters.rs
+++ b/rust/sedona-testing/src/rasters.rs
@@ -184,6 +184,43 @@ pub fn build_noninvertible_raster() -> StructArray {
     builder.finish().expect("finish")
 }
 
+/// Builds a single-band raster from raw bytes for tests.
+pub fn raster_from_single_band(
+    width: usize,
+    height: usize,
+    data_type: BandDataType,
+    band_bytes: &[u8],
+    crs: Option<&str>,
+) -> StructArray {
+    let mut builder = RasterBuilder::new(1);
+    let metadata = RasterMetadata {
+        width: width as u64,
+        height: height as u64,
+        upperleft_x: 0.0,
+        upperleft_y: 0.0,
+        scale_x: 1.0,
+        scale_y: -1.0,
+        skew_x: 0.0,
+        skew_y: 0.0,
+    };
+
+    builder.start_raster(&metadata, crs).expect("start raster");
+    builder
+        .start_band(BandMetadata {
+            datatype: data_type,
+            nodata_value: None,
+            storage_type: StorageType::InDb,
+            outdb_url: None,
+            outdb_band_id: None,
+        })
+        .expect("start band");
+    builder.band_data_writer().append_value(band_bytes);
+    builder.finish_band().expect("finish band");
+    builder.finish_raster().expect("finish raster");
+
+    builder.finish().expect("finish")
+}
+
 /// Determine if this tile contains a corner of the overall grid and return 
its position
 /// Returns Some(position) if this tile contains a corner, None otherwise
 fn get_corner_position(
diff --git a/submodules/sedona-testing b/submodules/sedona-testing
index c7bc17d7..4a05ef1c 160000
--- a/submodules/sedona-testing
+++ b/submodules/sedona-testing
@@ -1 +1 @@
-Subproject commit c7bc17d7109fc628959eb2850d4cfce3d483b1ee
+Subproject commit 4a05ef1c3c9dbeaab8568211112b32a2a50fcda4

Reply via email to