Restructure command line args to use subcommands
This commit is contained in:
parent
0880f3e761
commit
d84a1ee40c
76
src/main.rs
76
src/main.rs
|
|
@ -1,5 +1,5 @@
|
||||||
use {
|
use {
|
||||||
clap::Parser,
|
clap::{Parser, Subcommand},
|
||||||
geo_types::Point,
|
geo_types::Point,
|
||||||
image::{ImageBuffer, Luma},
|
image::{ImageBuffer, Luma},
|
||||||
las::Read as LasRead,
|
las::Read as LasRead,
|
||||||
|
|
@ -13,26 +13,46 @@ use {
|
||||||
|
|
||||||
mod geonb;
|
mod geonb;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser)]
|
||||||
#[clap(author, version, about, long_about=None)]
|
#[command(author, version, about, long_about=None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
// Latitude to fetch LIDAR tile at
|
/// Print extra debug info when initializing graphics
|
||||||
#[clap(long)]
|
#[arg(long)]
|
||||||
latitude: Option<f64>,
|
|
||||||
|
|
||||||
// Longitude to fetch LIDAR tile at
|
|
||||||
#[clap(long)]
|
|
||||||
longitude: Option<f64>,
|
|
||||||
|
|
||||||
// Print extra debug info when initializing raphics
|
|
||||||
#[clap(long)]
|
|
||||||
debug_init: bool,
|
debug_init: bool,
|
||||||
|
|
||||||
#[clap(long)]
|
#[command(subcommand)]
|
||||||
laz_file: Option<PathBuf>,
|
command: Command,
|
||||||
|
}
|
||||||
|
|
||||||
#[clap(long)]
|
#[derive(Subcommand)]
|
||||||
grid_cell_size: Option<f64>,
|
enum Command {
|
||||||
|
/// Download data from GeoNB
|
||||||
|
GeoNB {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: GeoNBCommand,
|
||||||
|
},
|
||||||
|
/// Create a grid DEM from point data
|
||||||
|
GridPoints {
|
||||||
|
#[arg(long, short = 'i')]
|
||||||
|
laz_filename: PathBuf,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
grid_cell_size: f64,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum GeoNBCommand {
|
||||||
|
/// Download the LIDAR tile that includes a location
|
||||||
|
DownloadLidarTile {
|
||||||
|
/// Latitude to fetch LIDAR tile at
|
||||||
|
#[arg(long, allow_hyphen_values=true)]
|
||||||
|
latitude: f64,
|
||||||
|
|
||||||
|
/// Longitude to fetch LIDAR tile at
|
||||||
|
#[arg(long, allow_hyphen_values=true)]
|
||||||
|
longitude: f64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
trait FromFloatFloor<F> {
|
trait FromFloatFloor<F> {
|
||||||
|
|
@ -231,7 +251,14 @@ where
|
||||||
async fn main() -> Result<(), anyhow::Error> {
|
async fn main() -> Result<(), anyhow::Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
if let (Some(latitude), Some(longitude)) = (args.latitude, args.longitude) {
|
match args.command {
|
||||||
|
Command::GeoNB {
|
||||||
|
command:
|
||||||
|
GeoNBCommand::DownloadLidarTile {
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
},
|
||||||
|
} => {
|
||||||
let location = Proj::new_known_crs("+proj=longlat +datum=WGS84", "EPSG:2953", None)
|
let location = Proj::new_known_crs("+proj=longlat +datum=WGS84", "EPSG:2953", None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.convert(Point::new(longitude, latitude))
|
.convert(Point::new(longitude, latitude))
|
||||||
|
|
@ -257,12 +284,14 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
let point = wrapped_point.unwrap();
|
let point = wrapped_point.unwrap();
|
||||||
println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
|
println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Command::GridPoints {
|
||||||
if let Some(laz_filename) = args.laz_file {
|
laz_filename,
|
||||||
|
grid_cell_size,
|
||||||
|
} => {
|
||||||
let mut las_reader = las::Reader::from_path(laz_filename).unwrap();
|
let mut las_reader = las::Reader::from_path(laz_filename).unwrap();
|
||||||
let bounds = las_reader.header().bounds();
|
let bounds = las_reader.header().bounds();
|
||||||
if let Some(grid_cell_size) = args.grid_cell_size {
|
|
||||||
let num_cells_x = ((bounds.max.x - bounds.min.x) / grid_cell_size).ceil() as usize;
|
let num_cells_x = ((bounds.max.x - bounds.min.x) / grid_cell_size).ceil() as usize;
|
||||||
let num_cells_y = ((bounds.max.y - bounds.min.y) / grid_cell_size).ceil() as usize;
|
let num_cells_y = ((bounds.max.y - bounds.min.y) / grid_cell_size).ceil() as usize;
|
||||||
let mut height_grid = Grid::new(num_cells_y, num_cells_x);
|
let mut height_grid = Grid::new(num_cells_y, num_cells_x);
|
||||||
|
|
@ -288,8 +317,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
ImageBuffer::from_raw(num_cells_x as u32, num_cells_y as u32, grid_u8.data)
|
ImageBuffer::from_raw(num_cells_x as u32, num_cells_y as u32, grid_u8.data)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
image.save("test.png")?;
|
image.save("test.png")?;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue