Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions rust/sedona-testing/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ pub fn sedona_testing_dir() -> Result<String> {
)
}

/// Get the path to a raster test file from the sedona-testing data directory.
///
/// # Arguments
/// * `name` - The name of the raster file (e.g., "test1.tiff", "test4.tiff")
///
/// # Returns
/// The full path to the raster test file if it exists.
///
/// # Example
/// ```ignore
/// let path = test_raster("test4.tiff")?;
/// ```
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::*;
Expand Down Expand Up @@ -172,4 +199,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());
}
}
37 changes: 37 additions & 0 deletions rust/sedona-testing/src/rasters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading