gistools/proj/parse/
util.rs1use crate::proj::{BaseUnit, Unit};
2use alloc::string::String;
3
4pub fn to_camel_case(s: &str) -> String {
6 let mut result = String::new();
7 let mut capitalize_next = false;
8
9 for (i, c) in s.trim().chars().enumerate() {
10 if c == ' ' || c == '_' || c == '-' {
11 capitalize_next = true;
12 } else if i == 0 {
13 result.push(c.to_ascii_lowercase());
14 } else if capitalize_next {
15 result.push(c.to_ascii_uppercase());
16 capitalize_next = false;
17 } else {
18 result.push(c.to_ascii_lowercase());
19 }
20 }
21
22 result
23}
24
25pub fn to_pascal_case(s: &str) -> String {
27 let mut result = String::new();
28 let mut capitalize_next = true;
29
30 for c in s.trim().chars() {
31 if c == ' ' || c == '_' || c == '-' {
32 capitalize_next = true;
33 } else if capitalize_next {
34 result.push(c.to_ascii_uppercase());
35 capitalize_next = false;
36 } else {
37 result.push(c);
38 }
39 }
40
41 result
42}
43
44pub fn get_prime_meridian(name: &str) -> f64 {
47 match name.to_lowercase().as_str() {
48 "copenhagen" => 12.0, "greenwich" => 0.0, "lisbon" => -9.131906111111, "paris" => 2.337229166667, "bogota" => -74.080916666667, "madrid" => -3.687938888889, "rome" => 12.452333333333, "bern" => 7.439583333333, "jakarta" => 106.807719444444, "ferro" => -17.666666666667, "brussels" => 4.367975, "stockholm" => 18.058277777778, "athens" => 23.7163375, "budapest" => 19.040236111111, "oslo" => 10.722916666667, _ => 0.0,
65 }
66}
67
68pub fn linear_unit_to_meters(unit: &str) -> f64 {
70 match unit.trim().to_lowercase().as_str() {
71 "km" | "kilometer" => 1000.0,
72 "metre" | "meter" | "m" => 1.0,
73 "dm" | "decimeter" => 0.1,
74 "cm" | "centimeter" => 0.01,
75 "mm" | "millimeter" => 0.001,
76 "kmi" | "internationalnauticalmile" => 1852.0,
77 "in" | "internationalinch" => 0.0254,
78 "ft" | "internationalfoot" => 0.3048,
79 "yd" | "internationalyard" => 0.9144,
80 "mi" | "internationalstatutemile" => 1609.344,
81 "fath" | "internationalfathom" => 1.8288,
82 "ch" | "internationalchain" => 20.1168,
83 "link" | "internationallink" => 0.201168,
84 "us-in" | "ussurveyorinch" => 100.0 / 3937.0,
85 "us-ft" | "ussurveyorfoot" => 1200.0 / 3937.0,
86 "us-yd" | "ussurveyoryard" => 3600.0 / 3937.0,
87 "us-ch" | "ussurveyorchain" => 79200.0 / 3937.0,
88 "us-mi" | "ussurveyorstatutemile" => 6336000.0 / 3937.0,
89 "ind-yd" | "indianyard" => 0.91439523,
90 "ind-ft" | "indianfoot" => 0.30479841,
91 "ind-ch" | "indianchain" => 20.11669506,
92 _ => 0.0,
93 }
94}
95
96pub fn angular_unit_to_degrees(unit: &str) -> f64 {
98 match unit.trim().to_lowercase().as_str() {
99 "rad" | "radian" => 180.0 / core::f64::consts::PI,
100 "grad" | "grade" => 1.0 / 200.0 * 180.0,
101 "degree" => 1.0,
102 _ => 0.0,
103 }
104}
105
106pub fn name_to_unit(name: &str) -> Unit {
108 match name.to_lowercase().as_str() {
109 "false_easting" | "false_northing" => Unit::BaseUnit(BaseUnit::Metre),
110 "scale_factor" => Unit::BaseUnit(BaseUnit::Unity),
111 _ => Unit::BaseUnit(BaseUnit::Degree),
112 }
113}
114
115pub fn axis_name_to_order(name: &str) -> u8 {
117 match name.to_lowercase().as_str() {
118 "x" | "(x)" | "east" | "east (x)" | "(e)" | "easting" | "easting (x)" => 0,
119 "y" | "(y)" | "north" | "north (y)" | "(n)" | "northing" | "northing (y)" => 1,
120 "z" | "(z)" => 2,
121 "t" | "(t)" => 3,
122 _ => 0,
123 }
124}