martin_core/tiles/cog/
errors.rs

1//! Error types for `Cloud Optimized GeoTIFF` operations.
2
3use std::path::PathBuf;
4
5use png::EncodingError;
6use tiff::TiffError;
7
8/// Errors that can occur when working with COG files.
9#[non_exhaustive]
10#[derive(thiserror::Error, Debug)]
11pub enum CogError {
12    /// Cannot decode file as valid TIFF.
13    #[error("Couldn't decode {1} as tiff file: {0}")]
14    InvalidTiffFile(#[source] TiffError, PathBuf),
15
16    /// Requested zoom level is outside the available range.
17    #[error(
18        "Requested zoom level {0} from file {1} is out of range. Possible zoom levels are {2} to {3}"
19    )]
20    ZoomOutOfRange(u8, PathBuf, u8, u8),
21
22    /// No images found in TIFF file.
23    #[error("Couldn't find any image in the tiff file: {0}")]
24    NoImagesFound(PathBuf),
25
26    /// Cannot seek to Image File Directory.
27    #[error("Couldn't seek to ifd number {1} (0 based indexing) in tiff file {2}: {0}")]
28    IfdSeekFailed(#[source] TiffError, usize, PathBuf),
29
30    /// TIFF file contains too many images.
31    #[error("Too many images in the tiff file: {0}")]
32    TooManyImages(PathBuf),
33
34    /// Required TIFF tags not found.
35    #[error("Couldn't find tags {1:?} at ifd {2} of tiff file {3}: {0}")]
36    TagsNotFound(#[source] TiffError, Vec<u16>, usize, PathBuf),
37
38    /// Unsupported planar configuration in TIFF.
39    #[error(
40        "Unsupported planar configuration {2} at IFD {1} in TIFF file {0}. Only planar configuration 1 is supported."
41    )]
42    PlanarConfigurationNotSupported(PathBuf, usize, u16),
43
44    /// Failed to read TIFF chunk data.
45    #[error("Failed to read {1}th chunk(0 based index) at ifd {2} from tiff file {3}: {0}")]
46    ReadChunkFailed(#[source] TiffError, u32, usize, PathBuf),
47
48    /// Failed to write PNG header.
49    #[error("Failed to write header of png file at {0}: {1}")]
50    WritePngHeaderFailed(PathBuf, #[source] EncodingError),
51
52    /// Failed to write PNG pixel data.
53    #[error("Failed to write pixel bytes to png file at {0}: {1}")]
54    WriteToPngFailed(PathBuf, #[source] EncodingError),
55
56    /// Unsupported color type or bit depth.
57    #[error("The color type {0:?} and its bit depth of the tiff file {1} is not supported yet")]
58    NotSupportedColorTypeAndBitDepth(tiff::ColorType, PathBuf),
59
60    /// Striped TIFF format not supported.
61    #[error("Striped tiff file is not supported, the tiff file is {0}")]
62    NotSupportedChunkType(PathBuf),
63
64    /// Invalid coordinate transformation information.
65    #[error("Coord transformation in {0} is invalid: {1}")]
66    InvalidGeoInformation(PathBuf, String),
67
68    /// Image pixels are not square.
69    #[error(
70        "The pixel size of the image {0} is not squared, the x_scale is {1}, the y_scale is {2}"
71    )]
72    NonSquaredImage(PathBuf, f64, f64),
73
74    /// Cannot determine tile origin from TIFF tags.
75    #[error(
76        "Calculating the tile origin failed for {0}: the length of ModelTiepointTag should be >= 6, or the length of ModelTransformationTag should be >= 12"
77    )]
78    GetOriginFailed(PathBuf),
79
80    /// Cannot determine full resolution from TIFF tags.
81    #[error(
82        "Get full resolution failed for {0}: either a valid ModelPixelScaleTag or ModelPixelScaleTag is required"
83    )]
84    GetFullResolutionFailed(PathBuf),
85
86    /// IO error.
87    #[error("IO error {0}: {1}")]
88    IoError(#[source] std::io::Error, PathBuf),
89}