Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LidarPointStats: more robust determination of row/col position of points #275

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions whitebox-tools-app/src/tools/lidar_analysis/lidar_point_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ impl WhiteboxTool for LidarPointStats {
let south: f64 = north - rows as f64 * grid_res;
let east = west + columns as f64 * grid_res;
let nodata = -32768.0f64;
let half_grid_res = grid_res / 2.0;
let ns_range = north - south;
let ew_range = east - west;

let mut configs = RasterConfigs {
..Default::default()
Expand Down Expand Up @@ -438,10 +435,12 @@ impl WhiteboxTool for LidarPointStats {
for i in 0..n_points {
pd = input[i];
p = input.get_transformed_coords(i);
col = (((columns - 1) as f64 * (p.x - west - half_grid_res) / ew_range)
.round()) as isize;
row = (((rows - 1) as f64 * (north - half_grid_res - p.y) / ns_range)
.round()) as isize;
col = out_num_pnts.get_column_from_x(p.x);
row = out_num_pnts.get_row_from_y(p.y);

// Force points exactly on the edge of the raster to be within the last column or row
if col == (columns as isize) { col = col - 1 };
if row == (rows as isize) { row = row - 1 };

out_num_pnts.increment(row, col, 1f64);

Expand Down Expand Up @@ -579,10 +578,12 @@ impl WhiteboxTool for LidarPointStats {
for i in 0..n_points {
pd = input[i];
p = input.get_transformed_coords(i);
col = (((columns - 1) as f64 * (p.x - west - half_grid_res) / ew_range)
.round()) as isize;
row = (((rows - 1) as f64 * (north - half_grid_res - p.y) / ns_range)
.round()) as isize;
col = out_elev_range.get_column_from_x(p.x);
row = out_elev_range.get_row_from_y(p.y);

// Force points exactly on the edge of the raster to be within the last column or row
if col == (columns as isize) { col = col - 1 };
if row == (rows as isize) { row = row - 1 };

new_min_max_z = false;
if p.z < min_z.get_value(row, col) {
Expand Down Expand Up @@ -699,10 +700,12 @@ impl WhiteboxTool for LidarPointStats {
for i in 0..n_points {
pd = input[i];
p = input.get_transformed_coords(i);
col = (((columns - 1) as f64 * (p.x - west - half_grid_res) / ew_range)
.round()) as isize;
row = (((rows - 1) as f64 * (north - half_grid_res - p.y) / ns_range)
.round()) as isize;
col = out_predominant_class.get_column_from_x(p.x);
row = out_predominant_class.get_row_from_y(p.y);

// Force points exactly on the edge of the raster to be within the last column or row
if col == (columns as isize) { col = col - 1 };
if row == (rows as isize) { row = row - 1 };

class = pd.classification();
class_histo[class as usize].increment(row, col, 1u16);
Expand Down