1use crate::geokeys::{self, GeoKeyDirectory};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum RasterType {
8 PixelIsArea,
9 PixelIsPoint,
10 Unknown(u16),
11}
12
13impl RasterType {
14 pub fn from_code(code: u16) -> Self {
15 match code {
16 1 => Self::PixelIsArea,
17 2 => Self::PixelIsPoint,
18 other => Self::Unknown(other),
19 }
20 }
21}
22
23#[derive(Debug, Clone)]
25pub struct CrsInfo {
26 pub model_type: u16,
28 pub raster_type: u16,
30 pub projected_epsg: Option<u16>,
32 pub geographic_epsg: Option<u16>,
34 pub projection_citation: Option<String>,
36 pub geographic_citation: Option<String>,
38}
39
40impl CrsInfo {
41 pub fn from_geokeys(geokeys: &GeoKeyDirectory) -> Self {
43 Self {
44 model_type: geokeys.get_short(geokeys::GT_MODEL_TYPE).unwrap_or(0),
45 raster_type: geokeys.get_short(geokeys::GT_RASTER_TYPE).unwrap_or(1),
46 projected_epsg: geokeys.get_short(geokeys::PROJECTED_CS_TYPE),
47 geographic_epsg: geokeys.get_short(geokeys::GEOGRAPHIC_TYPE),
48 projection_citation: geokeys.get_ascii(geokeys::PROJ_CITATION).map(String::from),
49 geographic_citation: geokeys.get_ascii(geokeys::GEOG_CITATION).map(String::from),
50 }
51 }
52
53 pub fn epsg(&self) -> Option<u32> {
55 self.projected_epsg
56 .or(self.geographic_epsg)
57 .map(|e| e as u32)
58 }
59
60 pub fn raster_type_enum(&self) -> RasterType {
62 RasterType::from_code(self.raster_type)
63 }
64}