pub struct Omap { /* private fields */ }
Expand description
Struct representing an Orienteering map
The map will be georeferenced if self.epsg_crs.is_some() or else it is written in Local space
Implementations§
Source§impl Omap
impl Omap
Sourcepub fn new(
ref_point: Coord,
scale: Scale,
epsg_crs: Option<u16>,
meters_above_sea_level: Option<f64>,
) -> OmapResult<Self>
pub fn new( ref_point: Coord, scale: Scale, epsg_crs: Option<u16>, meters_above_sea_level: Option<f64>, ) -> OmapResult<Self>
Create a new map in the given scale centered at the ref_point
(projected coordinates) with an optional CRS and optional meters_above_sea_level
in elevation
All coordinates of objects added to the map must be relative the ref_point
The ref_point
can be retrieved with Self::get_ref_point
Examples found in repository?
24fn main() {
25 let map_center = DUMHOE;
26
27 let map_center_elevation_meters = 2_182.;
28 let crs_epsg_code = 25832;
29
30 let mut omap = Omap::new(
31 map_center,
32 Scale::S15_000,
33 Some(crs_epsg_code),
34 Some(map_center_elevation_meters),
35 )
36 .expect("Could not make map with the given CRS-code");
37
38 let ghp_point = Point(GALDHOPIGGEN - map_center);
39 let mut ghp_object = PointObject::from_point(ghp_point, PointSymbol::SpotHeight, 0.);
40 ghp_object.add_elevation_tag(2469.);
41
42 let dh_point = Point(DUMHOE - map_center);
43 let mut dh_object = PointObject::from_point(dh_point, PointSymbol::SpotHeight, 0.);
44 dh_object.add_elevation_tag(2182.);
45
46 let bh_point = Point(BUKKEHOE - map_center);
47 let mut bh_object = PointObject::from_point(bh_point, PointSymbol::SpotHeight, 0.);
48 bh_object.add_elevation_tag(2314.);
49
50 omap.add_object(ghp_object);
51 omap.add_object(dh_object);
52 omap.add_object(bh_object);
53
54 omap.write_to_file(
55 PathBuf::from_str("./mountain_top_triangle.omap").unwrap(),
56 Default::default(),
57 )
58 .expect("Could not write to file");
59}
More examples
9fn main() {
10 let map_center = Coord {
11 x: 323_877.,
12 y: 6_399_005.,
13 };
14 let map_center_elevation_meters = 100.;
15 let crs_epsg_code = 3006;
16
17 let mut omap = Omap::new(
18 map_center,
19 Scale::S15_000,
20 Some(crs_epsg_code),
21 Some(map_center_elevation_meters),
22 )
23 .expect("Could not make map with the given CRS-code");
24
25 // coordinates of geometry are in the same units as the map_center, but relative the map_center
26 let polygon = Polygon::new(
27 LineString::new(vec![
28 Coord { x: -50., y: -50. },
29 Coord { x: -50., y: 50. },
30 Coord { x: 50., y: 50. },
31 Coord { x: 50., y: -50. },
32 Coord { x: -50., y: -50. },
33 ]),
34 vec![],
35 );
36 let mut area_object =
37 AreaObject::from_polygon(polygon, AreaSymbol::RoughVineyard, 45.0_f64.to_radians());
38 area_object.add_tag("tag_key", "tag_value");
39
40 let line_string = LineString::new(vec![
41 Coord { x: -60., y: 20. },
42 Coord { x: -20., y: 25. },
43 Coord { x: 0., y: 27.5 },
44 Coord { x: 20., y: 26. },
45 Coord { x: 40., y: 22.5 },
46 Coord { x: 60., y: 20. },
47 Coord { x: 60., y: -20. },
48 Coord { x: -60., y: -20. },
49 ]);
50 let mut line_object = LineObject::from_line_string(line_string, LineSymbol::Contour);
51 line_object.add_elevation_tag(20.);
52
53 let point = Point::new(0.0_f64, 0.0_f64);
54 let point_object = PointObject::from_point(
55 point,
56 PointSymbol::ElongatedDotKnoll,
57 -45.0_f64.to_radians(),
58 );
59
60 let text_point = Point::new(0.0_f64, -30.0_f64);
61 let text = "some text".to_string();
62 let text_object = TextObject::from_point(text_point, TextSymbol::SpotHeight, text);
63
64 omap.add_object(area_object);
65 omap.add_object(line_object);
66 omap.add_object(point_object);
67 omap.add_object(text_object);
68
69 let max_bezier_deviation_meters = 2.5;
70
71 let bez_error = omap::BezierError::new(Some(max_bezier_deviation_meters), None);
72
73 omap.write_to_file(
74 PathBuf::from_str("./simple_example.omap").unwrap(),
75 bez_error,
76 )
77 .expect("Could not write to file");
78}
Sourcepub fn reserve_capacity(&mut self, symbol: impl Into<Symbol>, cap: usize)
pub fn reserve_capacity(&mut self, symbol: impl Into<Symbol>, cap: usize)
Reserve capacity for cap
elements for key symbol
in the objects hashmap
Sourcepub fn add_object(&mut self, obj: impl Into<MapObject>)
pub fn add_object(&mut self, obj: impl Into<MapObject>)
Insert an object in the objects hashmap
All coordinates of objects added to the map must be relative the map’s ref_point
Examples found in repository?
24fn main() {
25 let map_center = DUMHOE;
26
27 let map_center_elevation_meters = 2_182.;
28 let crs_epsg_code = 25832;
29
30 let mut omap = Omap::new(
31 map_center,
32 Scale::S15_000,
33 Some(crs_epsg_code),
34 Some(map_center_elevation_meters),
35 )
36 .expect("Could not make map with the given CRS-code");
37
38 let ghp_point = Point(GALDHOPIGGEN - map_center);
39 let mut ghp_object = PointObject::from_point(ghp_point, PointSymbol::SpotHeight, 0.);
40 ghp_object.add_elevation_tag(2469.);
41
42 let dh_point = Point(DUMHOE - map_center);
43 let mut dh_object = PointObject::from_point(dh_point, PointSymbol::SpotHeight, 0.);
44 dh_object.add_elevation_tag(2182.);
45
46 let bh_point = Point(BUKKEHOE - map_center);
47 let mut bh_object = PointObject::from_point(bh_point, PointSymbol::SpotHeight, 0.);
48 bh_object.add_elevation_tag(2314.);
49
50 omap.add_object(ghp_object);
51 omap.add_object(dh_object);
52 omap.add_object(bh_object);
53
54 omap.write_to_file(
55 PathBuf::from_str("./mountain_top_triangle.omap").unwrap(),
56 Default::default(),
57 )
58 .expect("Could not write to file");
59}
More examples
9fn main() {
10 let map_center = Coord {
11 x: 323_877.,
12 y: 6_399_005.,
13 };
14 let map_center_elevation_meters = 100.;
15 let crs_epsg_code = 3006;
16
17 let mut omap = Omap::new(
18 map_center,
19 Scale::S15_000,
20 Some(crs_epsg_code),
21 Some(map_center_elevation_meters),
22 )
23 .expect("Could not make map with the given CRS-code");
24
25 // coordinates of geometry are in the same units as the map_center, but relative the map_center
26 let polygon = Polygon::new(
27 LineString::new(vec![
28 Coord { x: -50., y: -50. },
29 Coord { x: -50., y: 50. },
30 Coord { x: 50., y: 50. },
31 Coord { x: 50., y: -50. },
32 Coord { x: -50., y: -50. },
33 ]),
34 vec![],
35 );
36 let mut area_object =
37 AreaObject::from_polygon(polygon, AreaSymbol::RoughVineyard, 45.0_f64.to_radians());
38 area_object.add_tag("tag_key", "tag_value");
39
40 let line_string = LineString::new(vec![
41 Coord { x: -60., y: 20. },
42 Coord { x: -20., y: 25. },
43 Coord { x: 0., y: 27.5 },
44 Coord { x: 20., y: 26. },
45 Coord { x: 40., y: 22.5 },
46 Coord { x: 60., y: 20. },
47 Coord { x: 60., y: -20. },
48 Coord { x: -60., y: -20. },
49 ]);
50 let mut line_object = LineObject::from_line_string(line_string, LineSymbol::Contour);
51 line_object.add_elevation_tag(20.);
52
53 let point = Point::new(0.0_f64, 0.0_f64);
54 let point_object = PointObject::from_point(
55 point,
56 PointSymbol::ElongatedDotKnoll,
57 -45.0_f64.to_radians(),
58 );
59
60 let text_point = Point::new(0.0_f64, -30.0_f64);
61 let text = "some text".to_string();
62 let text_object = TextObject::from_point(text_point, TextSymbol::SpotHeight, text);
63
64 omap.add_object(area_object);
65 omap.add_object(line_object);
66 omap.add_object(point_object);
67 omap.add_object(text_object);
68
69 let max_bezier_deviation_meters = 2.5;
70
71 let bez_error = omap::BezierError::new(Some(max_bezier_deviation_meters), None);
72
73 omap.write_to_file(
74 PathBuf::from_str("./simple_example.omap").unwrap(),
75 bez_error,
76 )
77 .expect("Could not write to file");
78}
Sourcepub fn get_ref_point(&self) -> Coord
pub fn get_ref_point(&self) -> Coord
Get the projected ref point of the map
Sourcepub fn get_geo_ref_point(&self) -> Option<Coord>
pub fn get_geo_ref_point(&self) -> Option<Coord>
Get the geographical ref point of the map
Sourcepub fn merge_lines(&mut self, delta: f64)
pub fn merge_lines(&mut self, delta: f64)
Merge line objects that are tip to tail. This method is gated behind the merge_lines
-feature
Line ends (directed) of the same symbol that are less than delta
units (same units as the crs, most often meters) apart are merged.
Elevation tags are respected and only elements with equal Elevation tags can be merged
Sourcepub fn make_dotknolls_and_depressions(
&mut self,
min_area: f64,
max_area: f64,
elongated_aspect: f64,
)
pub fn make_dotknolls_and_depressions( &mut self, min_area: f64, max_area: f64, elongated_aspect: f64, )
Turn small contour loops to dotknolls and depressions and remove the smallest ones dot_knolls smaller than (min+max)/2 + min will never be drawn as elongated
Sourcepub fn mark_basemap_depressions(&mut self)
pub fn mark_basemap_depressions(&mut self)
Mark closed basemap contour loops wound clockwise as depressions
Sourcepub fn remove_empty_keys(&mut self)
pub fn remove_empty_keys(&mut self)
Remove all keys without any objects in it
Sourcepub fn num_entries(&self, key: impl Into<Symbol>) -> Option<usize>
pub fn num_entries(&self, key: impl Into<Symbol>) -> Option<usize>
Get the number of map objects for a given symbol in the map
Sourcepub fn write_to_file(
self,
path: PathBuf,
bezier_error: BezierError,
) -> OmapResult<()>
pub fn write_to_file( self, path: PathBuf, bezier_error: BezierError, ) -> OmapResult<()>
Write the map to an omap file,
if path
is an invalid path then “auto_generated_map.omap” is the new path
Examples found in repository?
24fn main() {
25 let map_center = DUMHOE;
26
27 let map_center_elevation_meters = 2_182.;
28 let crs_epsg_code = 25832;
29
30 let mut omap = Omap::new(
31 map_center,
32 Scale::S15_000,
33 Some(crs_epsg_code),
34 Some(map_center_elevation_meters),
35 )
36 .expect("Could not make map with the given CRS-code");
37
38 let ghp_point = Point(GALDHOPIGGEN - map_center);
39 let mut ghp_object = PointObject::from_point(ghp_point, PointSymbol::SpotHeight, 0.);
40 ghp_object.add_elevation_tag(2469.);
41
42 let dh_point = Point(DUMHOE - map_center);
43 let mut dh_object = PointObject::from_point(dh_point, PointSymbol::SpotHeight, 0.);
44 dh_object.add_elevation_tag(2182.);
45
46 let bh_point = Point(BUKKEHOE - map_center);
47 let mut bh_object = PointObject::from_point(bh_point, PointSymbol::SpotHeight, 0.);
48 bh_object.add_elevation_tag(2314.);
49
50 omap.add_object(ghp_object);
51 omap.add_object(dh_object);
52 omap.add_object(bh_object);
53
54 omap.write_to_file(
55 PathBuf::from_str("./mountain_top_triangle.omap").unwrap(),
56 Default::default(),
57 )
58 .expect("Could not write to file");
59}
More examples
9fn main() {
10 let map_center = Coord {
11 x: 323_877.,
12 y: 6_399_005.,
13 };
14 let map_center_elevation_meters = 100.;
15 let crs_epsg_code = 3006;
16
17 let mut omap = Omap::new(
18 map_center,
19 Scale::S15_000,
20 Some(crs_epsg_code),
21 Some(map_center_elevation_meters),
22 )
23 .expect("Could not make map with the given CRS-code");
24
25 // coordinates of geometry are in the same units as the map_center, but relative the map_center
26 let polygon = Polygon::new(
27 LineString::new(vec![
28 Coord { x: -50., y: -50. },
29 Coord { x: -50., y: 50. },
30 Coord { x: 50., y: 50. },
31 Coord { x: 50., y: -50. },
32 Coord { x: -50., y: -50. },
33 ]),
34 vec![],
35 );
36 let mut area_object =
37 AreaObject::from_polygon(polygon, AreaSymbol::RoughVineyard, 45.0_f64.to_radians());
38 area_object.add_tag("tag_key", "tag_value");
39
40 let line_string = LineString::new(vec![
41 Coord { x: -60., y: 20. },
42 Coord { x: -20., y: 25. },
43 Coord { x: 0., y: 27.5 },
44 Coord { x: 20., y: 26. },
45 Coord { x: 40., y: 22.5 },
46 Coord { x: 60., y: 20. },
47 Coord { x: 60., y: -20. },
48 Coord { x: -60., y: -20. },
49 ]);
50 let mut line_object = LineObject::from_line_string(line_string, LineSymbol::Contour);
51 line_object.add_elevation_tag(20.);
52
53 let point = Point::new(0.0_f64, 0.0_f64);
54 let point_object = PointObject::from_point(
55 point,
56 PointSymbol::ElongatedDotKnoll,
57 -45.0_f64.to_radians(),
58 );
59
60 let text_point = Point::new(0.0_f64, -30.0_f64);
61 let text = "some text".to_string();
62 let text_object = TextObject::from_point(text_point, TextSymbol::SpotHeight, text);
63
64 omap.add_object(area_object);
65 omap.add_object(line_object);
66 omap.add_object(point_object);
67 omap.add_object(text_object);
68
69 let max_bezier_deviation_meters = 2.5;
70
71 let bez_error = omap::BezierError::new(Some(max_bezier_deviation_meters), None);
72
73 omap.write_to_file(
74 PathBuf::from_str("./simple_example.omap").unwrap(),
75 bez_error,
76 )
77 .expect("Could not write to file");
78}