pub fn array_to_rasterfile<T>(
data: &Array2<T>,
nd: T,
geotrans: &[f64; 6],
geokeydir: &[u64],
proj: &str,
outfile: &PathBuf,
) -> Result<(), RasterError>Expand description
Writes a 2D array of values to a GeoTIFF raster with geo metadata.
§Type Parameters
T: The element type of the array, which must implementbytemuck::Pod(for safe byte casting) andToString(for writing NoData values to metadata).
§Parameters
- `data`: A 2D array (`ndarray::Array2<T>`) containing raster pixel values.
- `nd`: NoData value
- `geotrans`: A 6-element array defining the affine geotransform:
`[origin_x, pixel_size_x, rotation_x, origin_y, rotation_y, pixel_size_y]`.
- `geokeydir`: &[u64] the GeoKeyDirectoryTag (best got from reading a raster)
- `proj`: PROJ string (best got from reading a raster)
- `outfile`: The path to the output `.tif` file.§Returns
Ok() or a RasterError
§Errors
- Returns
RasterError::UnsupportedTypeifTcan’t be mapped to a TIFF format. - Propagates I/O and TIFF writing errors
§Example
let path = PathBuf::from("input.tif");
let (d8, nd, crs, geo, gdir, proj) = rasterfile_to_array::<u8>(&path)?;
/* do something with d8, or make a new array2 */
let out = PathBuf::from("output.tif");
if let Err(e) = array_to_rasterfile::<u8>(&d8, nd, &geo, &gdir, &proj, &out) {
eprintln!("Error occured while writing {}: {:?}", out.display(), e);
}