Skip to main content

PointObject

Struct PointObject 

Source
pub struct PointObject {
    pub tags: HashMap<String, String>,
    pub rotation: f64,
    pub symbol: Weak<RefCell<PointSymbol>>,
    /* private fields */
}
Expand description

A point object placed at a single location on the map.

Fields§

§tags: HashMap<String, String>

The tags associated with the object

§rotation: f64

Rotation of the symbol in radians.

§symbol: Weak<RefCell<PointSymbol>>

Weak reference to the point symbol used to render this object.

Implementations§

Source§

impl PointObject

Source

pub fn new(symbol: Weak<RefCell<PointSymbol>>, geometry: Point) -> Self

Create a new point object with the given symbol and position.

Source

pub fn get_geometry(&self) -> &Point

Get a shared reference to the point geometry.

Examples found in repository?
examples/from_path.rs (line 41)
28fn main() -> Result<(), Error> {
29    let mut map = Omap::from_path("./example_data/from_path.omap")?;
30
31    #[cfg(feature = "geo_ref")]
32    {
33        // we want to move the map center to the average position of all objects
34        let old_transform = map.geo_referencing.get_transform();
35
36        let mut mean_pos = Coord::zero();
37        let mut num_coords = 0;
38        for obj in map.parts.iter().flat_map(|part| part.iter_all_objects()) {
39            match obj {
40                MapObject::Point(object) => {
41                    mean_pos = mean_pos + object.get_geometry().0;
42                    num_coords += 1;
43                }
44                MapObject::Line(object) => {
45                    let geometry = object.get_geometry(0.1)?;
46                    mean_pos =
47                        mean_pos + geometry.0.iter().copied().reduce(|sum, c| sum + c).unwrap();
48                    num_coords += geometry.0.len();
49                }
50                MapObject::Area(object) => {
51                    let geometry = object.get_geometry(0.1)?;
52                    mean_pos = mean_pos
53                        + geometry
54                            .exterior()
55                            .0
56                            .iter()
57                            .copied()
58                            .reduce(|sum, c| sum + c)
59                            .unwrap();
60                    num_coords += geometry.exterior().0.len();
61                }
62                MapObject::Text(object) => {
63                    match object.get_geometry() {
64                        TextGeometry::SingleAnchor(coord) => mean_pos = mean_pos + *coord,
65                        TextGeometry::WrapBox(wrap_box) => mean_pos = mean_pos + wrap_box.anchor,
66                    }
67                    num_coords += 1;
68                }
69            }
70        }
71        mean_pos = mean_pos / num_coords as f64;
72
73        // now transform that into projected coords
74        let mean_proj_pos = old_transform.to_projected(mean_pos);
75
76        // get the new georef info for that position
77        let new_gr = GeoRef::initialize(
78            mean_proj_pos,
79            map.geo_referencing.crs_type,
80            2_469.,
81            map.geo_referencing.scale_denominator,
82        )
83        .unwrap();
84
85        // assign the new info
86        map.geo_referencing = new_gr;
87
88        // get the new map transform
89        let new_transform = map.geo_referencing.get_transform();
90
91        // transfrom every object out of the old map space to projected coords
92        // and from projected coord to the new map space
93        // NB! If the new projection were different than the old,
94        // a transfrom between projections using a proj library like proj-core would be needed
95        // and this function would return Err
96        map.apply_affine_between(&old_transform, &new_transform)
97            .unwrap();
98    };
99
100    println!("Map colors in order:");
101    for color in map.colors.iter() {
102        match color {
103            Color::SpotColor(ref_cell) => {
104                let b = ref_cell.try_borrow().unwrap();
105                println!("{} with spot name {}", b.color_name, b.spotcolor_name);
106            }
107            Color::MixedColor(ref_cell) => {
108                println!("{}", ref_cell.try_borrow().unwrap().color_name);
109            }
110        }
111    }
112
113    let erosion_gully = map
114        .symbols
115        .get_symbol_by_code(Code::new(107, 0, 0))
116        .unwrap()
117        .downgrade();
118
119    let mut ls = LineObject::new(
120        WeakLinePathSymbol::try_from(erosion_gully).unwrap(),
121        // geometry coordinates are always in mm of paper
122        LineString::new(vec![Coord { x: -60., y: -50. }, Coord { x: 60., y: -50. }]),
123    );
124    ls.tags.insert("Some Key".to_owned(), "My value".to_owned());
125
126    map.parts.0[0].add_object(ls);
127
128    let weak_symbol = map
129        .symbols
130        .get_symbol_by_name("Contour value")
131        .unwrap()
132        .downgrade();
133
134    let ts = TextObject::new(
135        Weak::<RefCell<TextSymbol>>::try_from(weak_symbol)
136            .expect("The symbol type of Contour value is not Text"),
137        TextGeometry::SingleAnchor(Coord { x: 0., y: 0. }),
138        "This is the middle of the map".to_owned(),
139    );
140    map.parts.0[0].add_object(ts);
141
142    map.write_to_file("./from_path_out.omap")
143}
Source

pub fn get_geometry_mut(&mut self) -> &mut Point

Get a mutable reference to the point geometry.

Source

pub fn apply_affine(&mut self, transform: &AffineMapTransform)

Apply an affine coordinate transform to the point position.

Source

pub fn into_geometry(self) -> Point

Consume this object and return its geometry.

Trait Implementations§

Source§

impl Clone for PointObject

Source§

fn clone(&self) -> PointObject

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PointObject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<PointObject> for MapObject

Source§

fn from(value: PointObject) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> 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<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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.