omap/lib.rs
1//! Write Open Orienteering Mapper's .omap files in Rust
2//!
3//! # Example
4//!
5//! ```
6//! use omap::{
7//! objects::{AreaObject, LineObject, PointObject, TextObject, TagTrait},
8//! symbols::{AreaSymbol, LineSymbol, PointSymbol, TextSymbol},
9//! Omap, Scale,
10//! };
11//! use geo_types::{Coord, LineString, Polygon, Point};
12//! use std::{path::PathBuf, str::FromStr};
13//!
14//! let map_center = Coord {x: 463_575.5, y: 6_833_849.6};
15//! let map_center_elevation_meters = 2_469.;
16//! let crs_epsg_code = 25832;
17//!
18//! let mut omap = Omap::new(
19//! map_center,
20//! Scale::S15_000,
21//! Some(crs_epsg_code),
22//! Some(map_center_elevation_meters)
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//! ]), vec![]);
34//! let mut area_object = AreaObject::from_polygon(polygon, AreaSymbol::RoughVineyard, 45.0_f64.to_radians());
35//! area_object.add_tag("tag_key", "tag_value");
36//!
37//! let line_string = LineString::new(
38//! vec![
39//! Coord {x: -60., y: 20.},
40//! Coord {x: -20., y: 25.},
41//! Coord {x: 0., y: 27.5},
42//! Coord {x: 20., y: 26.},
43//! Coord {x: 40., y: 22.5},
44//! Coord {x: 60., y: 20.},
45//! Coord {x: 60., y: -20.},
46//! Coord {x: -60., y: -20.},
47//! ]
48//! );
49//! let mut line_object = LineObject::from_line_string(line_string, LineSymbol::Contour);
50//! line_object.add_elevation_tag(20.);
51//!
52//! let point = Point::new(0.0_f64, 0.0_f64);
53//! let point_object = PointObject::from_point(point, PointSymbol::ElongatedDotKnoll, -45.0_f64.to_radians());
54//!
55//! let text_point = Point::new(0.0_f64, -30.0_f64);
56//! let text = "some text".to_string();
57//! let text_object = TextObject::from_point(text_point, TextSymbol::SpotHeight, text);
58//!
59//! omap.add_object(area_object);
60//! omap.add_object(line_object);
61//! omap.add_object(point_object);
62//! omap.add_object(text_object);
63//!
64//! let max_bezier_deviation_meters = 2.5;
65//!
66//! omap.write_to_file(
67//! PathBuf::from_str("./my_map.omap").unwrap(),
68//! Some(max_bezier_deviation_meters)
69//! ).expect("Could not write to file");
70//! ```
71
72#![deny(
73 elided_lifetimes_in_paths,
74 explicit_outlives_requirements,
75 keyword_idents,
76 macro_use_extern_crate,
77 meta_variable_misuse,
78 missing_abi,
79 missing_debug_implementations,
80 missing_docs,
81 non_ascii_idents,
82 noop_method_call,
83 rust_2021_incompatible_closure_captures,
84 rust_2021_incompatible_or_patterns,
85 rust_2021_prefixes_incompatible_syntax,
86 rust_2021_prelude_collisions,
87 single_use_lifetimes,
88 trivial_casts,
89 trivial_numeric_casts,
90 unreachable_pub,
91 unsafe_code,
92 unsafe_op_in_unsafe_fn,
93 unused_crate_dependencies,
94 unused_extern_crates,
95 unused_import_braces,
96 unused_lifetimes,
97 unused_qualifications,
98 unused_results,
99 warnings
100)]
101
102/// Objects module
103pub mod objects;
104mod omap;
105mod scale;
106mod serialize;
107/// Symbols module
108pub mod symbols;
109
110pub use self::omap::Omap;
111pub use self::scale::Scale;
112
113/// crate result
114pub type OmapResult<T> = Result<T, OmapError>;
115
116use thiserror::Error;
117/// crate error
118#[derive(Error, Debug)]
119pub enum OmapError {
120 /// Map coordinate overflow
121 #[error("Map coordinate overflow")]
122 MapCoordinateOverflow,
123 /// Wrong geo_types geometry for a symbol
124 #[error(transparent)]
125 MismatchedGeometry(#[from] geo_types::Error),
126 /// IO error
127 #[error(transparent)]
128 IO(#[from] std::io::Error),
129 /// Projection error
130 #[error(transparent)]
131 Proj(#[from] proj4rs::errors::Error),
132 /// World magnetic model declination error
133 #[error(transparent)]
134 GeoMagnetic(#[from] world_magnetic_model::Error),
135}