| Crates.io | spatialarray |
| lib.rs | spatialarray |
| version | 0.2.0 |
| created_at | 2025-10-14 21:16:20.300371+00 |
| updated_at | 2025-10-18 07:16:10.676829+00 |
| description | SpatialArray: labeled n-dimensional arrays with spatial-aware helpers for geospatial and scientific workflows. |
| homepage | https://wayfinder-foundry.org |
| repository | https://github.com/Wayfinder-Foundry/spatialarray |
| max_upload_size | |
| id | 1883209 |
| size | 31,751 |
SpatialArray provides labeled n-dimensional arrays and helpers aimed at geospatial and scientific workflows built on ndarray.
Quick publish notes:
See the crate documentation at https://docs.rs/spatialarray (after first publish).
This library provides a structure for connecting human-readable dimension names (like "band", "time", "y", "x") to the underlying numerical data store powered by ndarray.
Add this to your Cargo.toml:
[dependencies]
spatialarray = "0.1"
use ndarray::ArrayD;
use spatialarray::SpatialArray;
use std::collections::HashMap;
// Create a simple 2D spatial array
let data = ArrayD::from_shape_vec(vec![3, 4], vec![
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12
]).unwrap();
let dims = vec!["y".to_string(), "x".to_string()];
let array = SpatialArray::new(data, dims);
println!("Dimensions: {:?}", array.dims());
println!("Shape: {:?}", array.shape());
use ndarray::ArrayD;
use spatialarray::SpatialArray;
use std::collections::HashMap;
// Create a 4D geospatial array: time × band × y × x
let data = ArrayD::from_shape_vec(vec![2, 3, 100, 100], vec![0.0; 60000]).unwrap();
let dims = vec![
"time".to_string(),
"band".to_string(),
"y".to_string(),
"x".to_string(),
];
let mut coords = HashMap::new();
coords.insert("time".to_string(), vec![
"2024-01-01".to_string(),
"2024-01-02".to_string()
]);
coords.insert("band".to_string(), vec![
"red".to_string(),
"green".to_string(),
"blue".to_string()
]);
let array = SpatialArray::with_coords(data, dims, coords);
// Query dimension indices
if let Some(idx) = array.dim_index("band") {
println!("Band dimension is at index: {}", idx);
}
// Select by coordinate label
if let Some(idx) = array.select_by_label("band", "green") {
println!("Green band is at index: {}", idx);
}
SpatialArray::new(data, dims) - Create array with dimension namesSpatialArray::with_coords(data, dims, coords) - Create array with dimension names and coordinatesdims() - Get dimension namesshape() - Get array shapendim() - Get number of dimensionsdata() - Get reference to underlying ndarrayinfo() - Get formatted string with array informationcoords(dim) - Get coordinates for a dimensionall_coords() - Get all coordinatesset_coords(dim, coords) - Set coordinates for a dimensiondim_index(dim) - Get the index of a dimension by nameselect_by_label(dim, label) - Find the index of a coordinate labelRun the included example:
cargo run --example basic_usage
This library is designed to be extended with additional geospatial functionality:
[Add your license here]
Contributions are welcome! Please feel free to submit a Pull Request.