Hello there,
I am currently working on a geotiff parser where I want to parse a bunch of geology data into enums.
So I try to make this as quick as I can. Basically a geokey_directory contains data.
This data can be one of these types: Short
, Vec<Short>
, Vec<Double>
, String
.
Okay so long quite easy. Now each directory contains several keys and values which hold some of the data. So, e.g. the directory might look like this (simplified):
Key | data | Note |
---|---|---|
3075 | 17 | defines the ProjCoordTransGeoKey
|
1026 | `"unnamed | "` |
2057 | 3396190.0 |
stands for GeogSemiMajorAxisGeoKey
|
Okay cool, so what I want to do is, I want to store the data in an enum so that I later know that ProjCoordTransGeoKey
stands for 3075
and I don't have to remember what number that was. So I need to instatiate an enum by its value. I did this with the help of the matrix Rust group here sucessfully.
So now have a an enum for the keys, an enum for the values and save this as key value pairs in a hashmap.
Okay round two.
Now, when you look at the table above, the third entry indeed refers to a double value, in this case it refers to the mean radius of Mars. However the first entry does not refer to the number 17, rather it refers to a type (like an enum) for which number 17 means e.g. CT_Equirectangular
.
So some of the shorts actually refer to codes
in the geotiff spec (basically eleven other enums).
What I would like to do now is two things:
- Instead of saving things in a hashmap I would like the enum itself to save the values and
- I would like to parse the shorts which belong to other enums, to these enums.
I don't know how clear this is but on my branch I already tried to refactor my code and define all enums here however I have no idea on how to change my macro so I can use it here to parse and save the values I got from the geotiff.
I also have a test which shows how I would like to access the data later.
As a minimal example this is what I like to do:
enum_try_from! {
pub enum GeoKey {
Bla1(GeoKeyData) = 1024,
Bla2(SomeGeoEnum) = 1025,
// ...
}
}
// contains primitive types
pub enum GeoKeyData {
Short(u16),
// ...
}
// One of the 11 enums:
pub enum SomeGeoEnum{
Elipsoidblablalba = 32421,
// ...
}
// Usage:
let new_entry = GeoKey::create_new(1025, 32421)
// Test how I would like to access:
match new_entry {
GeoKey::Bla2(value) => assert_eq!(value, SomeGeoEnum::Elipsoidblablalba),
// ...
}
// Usage for primitive values:
let other_entry = GeoKey::create_new(1024, GeoKeyData::Short(123));
match other_entry {
GeoKey::Bla1(value) => assert_eq!(value, GeoKeyData::Short(123)),
// ...
}
I am very grateful if anyone can help me as I am pretty frustrated by now. What I have in my repo does not work and I don't know where to go. Please go easy on me as I just started Rust a few months ago and am a newb. Thats why my code is so shitty