pub fn rasterfile_to_array<T>(
fname: &PathBuf,
) -> Result<(Array2<T>, T, u16, [f64; 6], Vec<u64>, String), RasterError>where
T: FromStr + FromPrimitive,
<T as FromStr>::Err: Debug,
RasterError: From<<T as FromStr>::Err>,Expand description
Reads a single-band grayscale GeoTIFF raster file returning ndarry2 and metadata
§Type Parameters
T: The pixel value type. u8, u16, i16, f64 etc
§Parameters
fname: Path to the input.tifGeoTIFF file.
§Returns
A Result with a tuple containing:
- Array2<T>: The raster data in a 2D array.
- T: nodata
- u16: CRS (e.g. 2193)
- [f64; 6]: The affine GeoTransform in the format:
[origin_x, pixel_size_x, rotation_x, origin_y, rotation_y, pixel_size_y].
- Vec<u64>: raw GeoKeyDirectoryTag values (needed for writing to file)
- String: PROJ string (needed for writing to file)
§Errors
- Returns `RasterError` variants if reading fails, the type conversion for data or metadata
fails, or required tags are missing from the TIFF file.§Example
let path = PathBuf::from("input.tif");
let (d8, nd, crs, geo, gdir, proj) = rasterfile_to_array::<u8>(&path)?;