Skip to main content

qualia_geospatial/
wfs.rs

1//! Geological Feature & Vector Attribute Parser (WFS / GeoSPARQL).
2//!
3//! Dual-path "truth" ingestion: parses geological formations, lithology attributes,
4//! and stratigraphic ages from vector data to populate BankedConstituentLut mineral recipes.
5
6use qualia_core_db::q42::m64_matter::{Q42ConstituentLutEntry, BANK_1_PAGED_COUNT};
7
8/// A parsed geological stratigraphic formation record.
9#[derive(Debug, Clone, PartialEq)]
10pub struct GeologicUnitRecord {
11    /// Formation unit code (e.g. "Jmb" = Tertiary Monaro Basalt, "Gda" = Adamaby Granite).
12    pub unit_code: String,
13    /// Dominant rock classification (e.g. "Basalt", "Granite", "Silcrete", "Kaolinite Clay").
14    pub lithology: String,
15    /// Absolute geological age in millions of years (Ma).
16    pub stratigraphic_age_ma: f64,
17    /// Assigned LUT index in Bank 1 (128..223).
18    pub lut_index: u8,
19}
20
21/// Geological Vector Layer manager.
22#[derive(Debug, Clone)]
23pub struct GeologicVectorLayer {
24    pub units: Vec<GeologicUnitRecord>,
25}
26
27impl Default for GeologicVectorLayer {
28    fn default() -> Self {
29        Self::new_snowy_monaro_baseline()
30    }
31}
32
33impl GeologicVectorLayer {
34    /// Baseline regional geological formations for the Snowy Monaro / Talbingo region (GSNSW).
35    pub fn new_snowy_monaro_baseline() -> Self {
36        let units = vec![
37            GeologicUnitRecord {
38                unit_code: "Jmb".to_string(), // Monaro Basalt
39                lithology: "Basalt".to_string(),
40                stratigraphic_age_ma: 45.0,
41                lut_index: 128,
42            },
43            GeologicUnitRecord {
44                unit_code: "Gda".to_string(), // Adamaby Granite
45                lithology: "Granite".to_string(),
46                stratigraphic_age_ma: 410.0,
47                lut_index: 129,
48            },
49            GeologicUnitRecord {
50                unit_code: "Skt".to_string(), // Silurian Siltstone / Shale
51                lithology: "Siltstone".to_string(),
52                stratigraphic_age_ma: 425.0,
53                lut_index: 130,
54            },
55            GeologicUnitRecord {
56                unit_code: "Qa".to_string(), // Quaternary Alluvium / River Gravel
57                lithology: "Gravel".to_string(),
58                stratigraphic_age_ma: 0.1,
59                lut_index: 131,
60            },
61        ];
62        Self { units }
63    }
64
65    /// Resolves a geological unit code into its assigned ConstituentLUT index (0..255).
66    pub fn resolve_unit_to_lut_index(&self, unit_code: &str) -> Option<u8> {
67        self.units
68            .iter()
69            .find(|u| u.unit_code.eq_ignore_ascii_case(unit_code))
70            .map(|u| u.lut_index)
71    }
72
73    /// Compiles regional Bank 1 recipes (96 entries) from known geological units.
74    pub fn compile_bank_1_recipes(&self) -> [Q42ConstituentLutEntry; BANK_1_PAGED_COUNT] {
75        let mut recipes = [Q42ConstituentLutEntry::default(); BANK_1_PAGED_COUNT];
76
77        for unit in &self.units {
78            let offset = (unit.lut_index as usize).saturating_sub(128);
79            if offset < BANK_1_PAGED_COUNT {
80                match unit.lithology.as_str() {
81                    "Basalt" => {
82                        recipes[offset].bulk_density_kg_m3 = 2850;
83                        recipes[offset].friction_angle_deg = 44;
84                        recipes[offset].cohesion_kpa = 1100;
85                        recipes[offset].refractive_index_x100 = 164;
86                    }
87                    "Granite" => {
88                        recipes[offset].bulk_density_kg_m3 = 2680;
89                        recipes[offset].friction_angle_deg = 50;
90                        recipes[offset].cohesion_kpa = 4500;
91                        recipes[offset].refractive_index_x100 = 155;
92                    }
93                    "Siltstone" => {
94                        recipes[offset].bulk_density_kg_m3 = 2400;
95                        recipes[offset].friction_angle_deg = 30;
96                        recipes[offset].cohesion_kpa = 180;
97                        recipes[offset].refractive_index_x100 = 158;
98                    }
99                    _ => {}
100                }
101            }
102        }
103
104        for recipe in recipes.iter_mut() {
105            recipe.update_crc();
106        }
107
108        recipes
109    }
110}