Struct Parser

Source
pub struct Parser { /* private fields */ }
Expand description

Main class that parses a pbf file and maintains a cache of relations/ways/nodes then provides methods to access the public transports (PTv2) inside that (cached) file

Implementations§

Source§

impl Parser

Main class, it parses the pbf file on new() and maintains an internal cache of relations / ways / nodes, to build on the fly PublicTransport representations

Source

pub fn new_ptv2(pbf_filename: &str, cpus: usize) -> Self

creates internal cache by parsing public transport v2 from pbf file in the pbf_filename path, in parallel with cpus threads

Source

pub fn new_aa(pbf_filename: &str, cpus: usize) -> Self

creates internal cache by parsing administrative areas from pbf file in the pbf_filename path, in parallel with cpus threads

Source

pub fn new(pbf_filename: &str, cpus: usize, filters: String) -> Self

creates internal cache by parsing the pbf file in the pbf_filename path, in parallel with cpus threads, filtering by tags in filters filters examples: “tag_key” the relation must have the tag “tag_key” “tag_key=tag_value” the relation must have the tag “tag_key” with value “tag_value” “tag_key=tag_value,tag_value2&tag_key2=tag_value3” the relation must have the tag “tag_key” with value “tag_value” or “tag_value2” and the tag “tag_key2” with value “tag_value3”

Examples found in repository?
src/example.rs (line 12)
4fn main() {
5    let pbf_filename_option = std::env::args().skip(1).next();
6    if pbf_filename_option == None {
7        return println!("Expected filename");
8    }
9    let pbf_filename = pbf_filename_option.unwrap();
10
11    let nthreads = num_cpus::get();
12    let parser = Parser::new(&pbf_filename, nthreads, "natural=beach".to_string());
13    // let parser = Parser::new_aa(&pbf_filename, nthreads);
14
15    let mut accum = 0usize;
16    let v1 = parser.get_areas(150_f64);
17    for _ in v1 {
18        accum += 1;
19    }
20
21    // OPTION2:
22    // let v2 = parser.par_map(|r| r.flatten_ways(150_f64).unwrap());
23
24    println!("OKs = {:?}", accum);
25}
Source

pub fn get_public_transports(&self, gap: f64) -> Vec<PublicTransport>

Builds a vector in parallel with all the public transport ways normalized and “fixed”. It works in parallel using the same amount of threads that were configured on new()

Source

pub fn par_map<R, F>(&self, func: &F) -> Vec<R>
where F: Fn(Relation) -> R + Sync + Send + Clone + 'static, R: Send + 'static,

Iterates in parallel through the cache of public transports and offers the possibility to further process them with the func function being executed in parallel It works in parallel using the same amount of threads that were configured on new()

Source

pub fn get_areas(&self, gap: f64) -> Vec<Area>

Builds a vector in parallel with all the areas normalized and “fixed”. It works in parallel using the same amount of threads that were configured on new()

Examples found in repository?
src/example.rs (line 16)
4fn main() {
5    let pbf_filename_option = std::env::args().skip(1).next();
6    if pbf_filename_option == None {
7        return println!("Expected filename");
8    }
9    let pbf_filename = pbf_filename_option.unwrap();
10
11    let nthreads = num_cpus::get();
12    let parser = Parser::new(&pbf_filename, nthreads, "natural=beach".to_string());
13    // let parser = Parser::new_aa(&pbf_filename, nthreads);
14
15    let mut accum = 0usize;
16    let v1 = parser.get_areas(150_f64);
17    for _ in v1 {
18        accum += 1;
19    }
20
21    // OPTION2:
22    // let v2 = parser.par_map(|r| r.flatten_ways(150_f64).unwrap());
23
24    println!("OKs = {:?}", accum);
25}
Source

pub fn get_relation_from_id(self, id: u64) -> Relation

Builds the Relation from the provided osm_id id

Source

pub fn get_relation_at(&self, index: usize) -> Relation

Builds the Relation at position index in the internal cache

Source

pub fn get_way_at(&self, index: usize) -> Way

Builds the Way at position index in the internal cache

Source

pub fn iter(self) -> ParserRelationIterator

Returns a sequential iterator that returns a Relation on each turn

Trait Implementations§

Source§

impl Clone for Parser

Source§

fn clone(&self) -> Parser

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 Parser

Source§

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

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

impl IntoIterator for Parser

Source§

type Item = Relation

The type of the elements being iterated over.
Source§

type IntoIter = ParserRelationIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

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> 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> 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.