Created
April 2, 2024 22:36
-
-
Save JayKickliter/f047d5eb8185afd4ca55a009665c7859 to your computer and use it in GitHub Desktop.
ESA worldcover (land-type) typedefs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
#[repr(u8)] | |
pub(crate) enum WorldCover { | |
Tree = 10, | |
Shrub = 20, | |
Grass = 30, | |
Crop = 40, | |
Built = 50, | |
Bare = 60, | |
Frozen = 70, | |
Water = 80, | |
Wet = 90, | |
Mangrove = 95, | |
Moss = 100, | |
} | |
impl std::fmt::Display for WorldCover { | |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
f.write_str(self.to_str()) | |
} | |
} | |
impl WorldCover { | |
#[allow(dead_code)] | |
pub(crate) fn to_str(self) -> &'static str { | |
match self { | |
WorldCover::Tree => "TreeCover", | |
WorldCover::Shrub => "Shrubland", | |
WorldCover::Grass => "Grassland", | |
WorldCover::Crop => "Cropland", | |
WorldCover::Built => "BuiltUp", | |
WorldCover::Bare => "BareOrSparseVeg", | |
WorldCover::Frozen => "SnowAndIce", | |
WorldCover::Water => "Water", | |
WorldCover::Wet => "HerbaceousWetland", | |
WorldCover::Mangrove => "Mangroves", | |
WorldCover::Moss => "MossAndLichen", | |
} | |
} | |
} | |
impl TryFrom<u8> for WorldCover { | |
type Error = (); | |
fn try_from(other: u8) -> Result<WorldCover, ()> { | |
let val = match other { | |
10 => WorldCover::Tree, | |
20 => WorldCover::Shrub, | |
30 => WorldCover::Grass, | |
40 => WorldCover::Crop, | |
50 => WorldCover::Built, | |
60 => WorldCover::Bare, | |
70 => WorldCover::Frozen, | |
80 => WorldCover::Water, | |
90 => WorldCover::Wet, | |
95 => WorldCover::Mangrove, | |
100 => WorldCover::Moss, | |
_ => return Err(()), | |
}; | |
Ok(val) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment