Skip to content

Commit

Permalink
Add lookuo command
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Nov 7, 2023
1 parent e4c1db0 commit 2b9fa43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
23 changes: 23 additions & 0 deletions hexit/src/lookup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::options::Lookup;
use anyhow::Result;
use byteorder::{LittleEndian as LE, ReadBytesExt};
use hextree::{disktree::DiskTree, Cell};

impl Lookup {
pub fn run(&self) -> Result<()> {
let raw_cell: u64 = self
.cell
.parse::<u64>()
.or_else(|_| u64::from_str_radix(&self.cell, 16))?;
let cell = Cell::try_from(raw_cell)?;
let mut disktree = DiskTree::open(&self.disktree)?;
match disktree.seek_to_cell(cell)? {
None => (),
Some((cell, rdr)) => {
let val = rdr.read_i16::<LE>()?;
println!("{cell}: {val}");
}
}
Ok(())
}
}
2 changes: 2 additions & 0 deletions hexit/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod combine;
mod lookup;
mod options;
mod progress_bar;
mod tesselate;
Expand All @@ -12,5 +13,6 @@ fn main() -> Result<()> {
match cli {
Cli::Tessellate(tesselate) => tesselate.run(),
Cli::Combine(combine) => combine.run(),
Cli::Lookup(lookup) => lookup.run(),
}
}
15 changes: 12 additions & 3 deletions hexit/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub enum Cli {
/// Generate a tessellated list of (cell, elevation) for each
/// input file.
Tessellate(Tesselate),

/// Combine previously tesselated files into a single
Combine(Combine),

Lookup(Lookup),
}

/// Generate a tessellated list of (cell, elevation) for each
/// input file.
#[derive(Debug, Clone, Args)]
pub struct Tesselate {
/// Reprocess height file even if corresponding output already
Expand All @@ -36,6 +37,7 @@ pub struct Tesselate {
pub input: Vec<PathBuf>,
}

/// Combine previously tesselated files into a single
#[derive(Debug, Clone, Args)]
pub struct Combine {
#[arg(short, long, default_value_t = Resolution::Ten)]
Expand All @@ -47,3 +49,10 @@ pub struct Combine {
/// Input tessaltions.
pub input: Vec<PathBuf>,
}

/// Lookup value for H3 cell in a disktree.
#[derive(Debug, Clone, Args)]
pub struct Lookup {
pub disktree: PathBuf,
pub cell: String,
}
6 changes: 0 additions & 6 deletions nasadem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,6 @@ impl Tile {
pub fn iter(&self) -> impl Iterator<Item = Sample<'_>> + '_ {
(0..(self.dimensions.0 * self.dimensions.1)).map(|index| Sample { tile: self, index })
}

/// Returns the number of elevation samples in this tile.
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.dimensions.0 * self.dimensions.1
}
}

/// Private API
Expand Down

0 comments on commit 2b9fa43

Please sign in to comment.