Skip to content

Commit

Permalink
feat: extract get_las_writer fn
Browse files Browse the repository at this point in the history
  • Loading branch information
pnodet committed Aug 22, 2023
1 parent d400f96 commit 2bfe276
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/convert_pointcloud.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::collections::HashMap;

use crate::convert_point::convert_point;
use crate::get_las_writer::get_las_writer;
use crate::stations::{create_station_point, get_sum_coordinates, StationPoint};
use crate::utils::construct_las_path;

use anyhow::{Context, Result};
use e57::{E57Reader, PointCloud};
use las::Write;
use uuid::Uuid;
use std::collections::HashMap;

pub fn convert_pointcloud(
index: usize,
Expand All @@ -16,18 +14,9 @@ pub fn convert_pointcloud(
output_path: &String,
) -> Result<HashMap<usize, StationPoint>> {
let mut stations: HashMap<usize, StationPoint> = HashMap::new();
let las_path =
construct_las_path(output_path, index).context("Unable to create file path: ")?;

let mut builder = las::Builder::from((1, 4));
builder.point_format.has_color = true;
builder.generating_software = String::from("e57_to_las");
builder.guid =
Uuid::parse_str(&pointcloud.guid.clone().replace("_", "-")).unwrap_or(Uuid::new_v4());

let header = builder.into_header().context("Error encountered: ")?;

let mut writer = las::Writer::from_path(&las_path, header).context("Error encountered: ")?;
let mut writer =
get_las_writer(index, pointcloud, output_path).context("Unable to create writer: ")?;

let mut e57_reader = E57Reader::from_file(input_path).context("Failed to open e57 file: ")?;

Expand Down
27 changes: 27 additions & 0 deletions src/get_las_writer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::{fs::File, io::BufWriter};

use crate::utils::construct_las_path;
use anyhow::{Context, Result};
use e57::PointCloud;
use uuid::Uuid;

pub(crate) fn get_las_writer(
index: usize,
pointcloud: &PointCloud,
output_path: &String,
) -> Result<las::Writer<BufWriter<File>>> {
let las_path =
construct_las_path(output_path, index).context("Unable to create file path: ")?;

let mut builder = las::Builder::from((1, 4));
builder.point_format.has_color = true;
builder.generating_software = String::from("e57_to_las");
builder.guid =
Uuid::parse_str(&pointcloud.guid.clone().replace("_", "-")).unwrap_or(Uuid::new_v4());

let header = builder.into_header().context("Error encountered: ")?;

let writer = las::Writer::from_path(&las_path, header).context("Error encountered: ")?;

Ok(writer)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mod convert_file;
mod convert_point;
mod convert_pointcloud;
mod get_las_writer;
mod stations;
mod utils;

Expand Down

0 comments on commit 2bfe276

Please sign in to comment.