pub struct Tree2D<C, V> { /* private fields */ }Expand description
Two-dimensional tree that maps a location given by [C; 2] to a value V.
§References
Implementations§
Source§impl Tree2D<i64, String>
impl Tree2D<i64, String>
Sourcepub fn write(&self, writer: impl Write) -> Result<()>
Available on crate feature std only.
pub fn write(&self, writer: impl Write) -> Result<()>
std only.Writes the tree into a stream in RGC format.
RGC is an internal format of this crate that uses columnar storage to compress the data.
Sourcepub fn read(reader: impl Read) -> Result<Self>
Available on crate feature std only.
pub fn read(reader: impl Read) -> Result<Self>
std only.Reads a tree from the stream in RGC format.
§RGC format
RGC is an internal format of this crate that uses columnar storage to compress the data. To obtain a file in such a format you can use CLI utility provided in the Git repo. You can use any OSM-PBF file as an input.
In the following script europe-latest.osm.pbf (32 GiB) is used as an input.
CLI utiliy extracts names from each node, compresses them, and produces other.rgc.zst and
settlements.rgc.zst. The total size of the resulting files is around 200 MiB.
cargo run --bin geo-coding-cli --release -- convert europe-latest.osm.pbfSource§impl<C: Ord + Copy + Default, V: Default> Tree2D<C, V>
impl<C: Ord + Copy + Default, V: Default> Tree2D<C, V>
Sourcepub fn from_nodes(nodes: Vec<([C; 2], V)>) -> Self
pub fn from_nodes(nodes: Vec<([C; 2], V)>) -> Self
Create a new tree from the given nodes.
The nodes are recursively subdividded into two groups: one that is behind and one that is in front of the plane that goes through the median node. The plane alternates between x = 0 and y = 0 for each layer of the tree.
The values are moved from the vector without copying.
Sourcepub fn find_nearest<D>(
&self,
location: &[C; 2],
max_distance: D,
max_neighbours: usize,
calc_distance: impl FnMut(&[C; 2], &[C; 2]) -> D,
) -> Vec<(D, &[C; 2], &V)>
pub fn find_nearest<D>( &self, location: &[C; 2], max_distance: D, max_neighbours: usize, calc_distance: impl FnMut(&[C; 2], &[C; 2]) -> D, ) -> Vec<(D, &[C; 2], &V)>
Returns up to max_neighbours nodes within max_distance that are closest to the location.
The distance between nodes is computed using calc_distance.