[][src]Struct vadeen_osm::OsmBuilder

pub struct OsmBuilder { /* fields omitted */ }

OsmBuilder makes it easy to build OSM maps from non OSM data. Polygons, multi polygons, poly lines and points are all represented as vectors of coordinates.

Nodes are automatically added and assigned ids. Ways and relations are automatically created with the correct references.

When building maps from OSM data the elements should be added directly to an Osm struct to preserve ids. You can also use the osm_io module which do exactly that when reading data.

Examples

let mut builder = OsmBuilder::default();

// Add a point, represented as one node.
builder.add_point((2.0, 2.0), vec![("power", "tower")]);

// Add a poly line, represented as two nodes and a way.
builder.add_polyline(
    vec![(2.0, 2.0), (4.0, 5.0)],
    vec![("power", "line")]
);

// Add a polygon, which is represented as one way and two nodes in osm.
builder.add_polygon(
    vec![
        // Outer polygon
        vec![(1.0, 1.0), (10.0, 10.0), (5.0, 5.0), (1.0, 1.0)],
        // If you want inner polygons, add them here...
        // Each inner polygon is represented as a way, the polygons are connected by a relation.
    ],
    vec![("natural", "water")]
);

let osm = builder.build();
assert_eq!(osm.nodes.len(), 5);
assert_eq!(osm.ways.len(), 2);
assert_eq!(osm.relations.len(), 0);

assert_eq!(osm.boundary, Some(Boundary::new((1.0, 1.0), (10.0, 10.0))));

Implementations

impl OsmBuilder[src]

pub fn build(self) -> Osm[src]

pub fn add_point<C: Into<Coordinate>, T: Into<Tag>>(
    &mut self,
    coordinate: C,
    tags: Vec<T>
)
[src]

pub fn add_polygon<C, T>(&mut self, parts: Vec<Vec<C>>, tags: Vec<T>) where
    C: Into<Coordinate>,
    T: Into<Tag>, 
[src]

First part is the outer polygon, rest of the parts is inner polygons. parts must not be empty or a panic will occur.

pub fn add_polyline<C, T>(&mut self, coordinates: Vec<C>, tags: Vec<T>) -> i64 where
    C: Into<Coordinate>,
    T: Into<Tag>, 
[src]

Trait Implementations

impl Default for OsmBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.