Struct Omap

Source
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

Source

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?
examples/mountain_top_triangle.rs (lines 30-35)
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
Hide additional examples
examples/simple_example.rs (lines 17-22)
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}
Source

pub fn reserve_capacity(&mut self, symbol: impl Into<Symbol>, cap: usize)

Reserve capacity for cap elements for key symbol in the objects hashmap

Source

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?
examples/mountain_top_triangle.rs (line 50)
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
Hide additional examples
examples/simple_example.rs (line 64)
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}
Source

pub fn get_crs(&self) -> Option<u16>

Get the CRS of the map represented by an EPSG code

Source

pub fn get_ref_point(&self) -> Coord

Get the projected ref point of the map

Source

pub fn get_geo_ref_point(&self) -> Option<Coord>

Get the geographical ref point of the map

Source

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

Source

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

Source

pub fn mark_basemap_depressions(&mut self)

Mark closed basemap contour loops wound clockwise as depressions

Source

pub fn remove_empty_keys(&mut self)

Remove all keys without any objects in it

Source

pub fn num_entries(&self, key: impl Into<Symbol>) -> Option<usize>

Get the number of map objects for a given symbol in the map

Source

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?
examples/mountain_top_triangle.rs (lines 54-57)
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
Hide additional examples
examples/simple_example.rs (lines 73-76)
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}
Source

pub fn into_objects(self) -> HashMap<Symbol, Vec<MapObject>>

Consume the omap object and get the object hashmap

Trait Implementations§

Source§

impl Clone for Omap

Source§

fn clone(&self) -> Omap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Omap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Omap

§

impl RefUnwindSafe for Omap

§

impl Send for Omap

§

impl Sync for Omap

§

impl Unpin for Omap

§

impl UnwindSafe for Omap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.