Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
bug fixes in prep for 0.14.1
  • Loading branch information
jblindsay committed Feb 11, 2019
1 parent 266c939 commit b1fcc40
Show file tree
Hide file tree
Showing 25 changed files with 1,149 additions and 136 deletions.
10 changes: 7 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ for more details.
* Release Notes: *
******************

Version 0.15.0 (XX-XX-2019)

Version 0.14.1 (10-02-2019)
- This release largely focuses on bug-fixes rather than feature additions. However, the
following tools were added to the library:
RasterArea

- Fixed a bug with the MultiscaleTopographicPositionImage tool that prevented proper output
for files in GeoTIFF format.
- Several other tool-specific bug fixes.

Version 0.14.0 (27-01-2019)
- The release largely focusses on bug-fixes rather than adding new features. The
- The release largely focuses on bug-fixes rather than adding new features. The
following tools were added to the project:
CircularVarianceOfAspect
EdgeDensity
Expand Down
44 changes: 35 additions & 9 deletions src/lidar/las.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct LasFile {
colour_data: Vec<ColourData>,
waveform_data: Vec<WaveformPacket>,
pub geokeys: GeoKeys,
wkt: String,
pub wkt: String,
// starting_point: usize,
header_is_set: bool,
pub use_point_intensity: bool,
Expand Down Expand Up @@ -100,6 +100,7 @@ impl LasFile {
output.file_mode = "w".to_string();
output.use_point_intensity = true;
output.use_point_userdata = true;
output.wkt = input.wkt.clone();

output.add_header(input.header.clone());

Expand Down Expand Up @@ -134,9 +135,9 @@ impl LasFile {
self.header.generating_software = "WhiteboxTools ".to_string();
self.header.number_of_points_by_return_old = [0, 0, 0, 0, 0];

self.header.x_scale_factor = 0.0001;
self.header.y_scale_factor = 0.0001;
self.header.z_scale_factor = 0.0001;
self.header.x_scale_factor = 0.001;
self.header.y_scale_factor = 0.001;
self.header.z_scale_factor = 0.001;

self.header_is_set = true;
}
Expand Down Expand Up @@ -1067,7 +1068,7 @@ impl LasFile {
let mut mantissa: usize = (format!("{}", (self.header.max_x - self.header.min_x).floor()))
.to_string()
.len();
let mut dec: f64 = 1.0 / 10_f64.powi(8 - mantissa as i32);
let mut dec: f64 = 1.0 / 10_f64.powi(7 - mantissa as i32);
if self.header.x_scale_factor == 0_f64 {
self.header.x_scale_factor = dec;
}
Expand Down Expand Up @@ -1184,7 +1185,8 @@ impl LasFile {
for i in 0..(self.header.number_of_vlrs as usize) {
total_vlr_size += self.vlr_data[i].record_length_after_header as u32;
}
self.header.offset_to_points = 235 + total_vlr_size; // THIS NEEDS TO BE FIXED WHEN LAS 1.4 SUPPORT IS ADDED FOR WRITING
// let alignment_bytes = self.header.header_size as u32 + total_vlr_size % 4u32;
self.header.offset_to_points = self.header.header_size as u32 + total_vlr_size; // + alignment_bytes; // THIS NEEDS TO BE FIXED WHEN LAS 1.4 SUPPORT IS ADDED FOR WRITING
u32_bytes = unsafe { mem::transmute(self.header.offset_to_points) };
writer.write_all(&u32_bytes)?;

Expand Down Expand Up @@ -1340,6 +1342,18 @@ impl LasFile {
writer.write_all(&vlr.binary_data)?;
}

// ////////////////////
// // Alignment bytes /
// ////////////////////
// if alignment_bytes > 0 {
// println!("alignment bytes: {}", alignment_bytes);
// for a in 0..alignment_bytes {
// writer.write_all(&[0u8]);
// }
// }

// println!("header: {:?}", self.header);

////////////////////////////////
// Write the point to the file /
////////////////////////////////
Expand All @@ -1352,6 +1366,18 @@ impl LasFile {
u32_bytes = unsafe { mem::transmute(val) };
writer.write_all(&u32_bytes)?;

// if i == 0 {
// println!("first point: {:?}", self.point_data[i]);
// }

// if i == 1 {
// println!("second point: {:?}", self.point_data[i]);
// }

// if i == 349527 {
// println!("last point: {:?}", self.point_data[i]);
// }

val = ((self.point_data[i].y - self.header.y_offset)
/ self.header.y_scale_factor) as i32;
u32_bytes = unsafe { mem::transmute(val) };
Expand All @@ -1369,13 +1395,13 @@ impl LasFile {

u8_bytes = unsafe { mem::transmute(self.point_data[i].point_bit_field) };
writer.write_all(&u8_bytes)?;

u8_bytes = unsafe { mem::transmute(self.point_data[i].class_bit_field) };
writer.write_all(&u8_bytes)?;

u8_bytes = unsafe { mem::transmute(self.point_data[i].scan_angle as i8) };
writer.write_all(&u8_bytes)?;

if self.use_point_userdata {
u8_bytes = unsafe { mem::transmute(self.point_data[i].user_data) };
writer.write_all(&u8_bytes)?;
Expand Down
6 changes: 6 additions & 0 deletions src/raster/arcascii_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ pub fn read_arcascii(
}
if vec[0].to_lowercase().contains("nrows") {
configs.rows = vec[vec.len() - 1].trim().parse::<f32>().unwrap() as usize;
if configs.columns > 0 {
data.reserve(configs.rows * configs.columns);
}
} else if vec[0].to_lowercase().contains("ncols") {
configs.columns = vec[vec.len() - 1].trim().parse::<f32>().unwrap() as usize;
if configs.rows > 0 {
data.reserve(configs.rows * configs.columns);
}
} else if vec[0].to_lowercase().contains("xllcorner") {
xllcenter = vec[vec.len() - 1]
.trim()
Expand Down
2 changes: 2 additions & 0 deletions src/raster/arcbinary_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub fn read_arcbinary(
yllcenter - (0.5 * configs.resolution_y) + (configs.rows as f64) * configs.resolution_y;
}

data.reserve(configs.rows * configs.columns);

// read the data file
let data_file = file_name.replace(".hdr", ".flt");
let mut f = File::open(data_file.clone())?;
Expand Down
1 change: 1 addition & 0 deletions src/raster/geotiff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub fn read_geotiff<'a>(

//data = vec![0.0f64; configs.rows * configs.columns];
data.clear();
data.reserve(configs.rows * configs.columns);
for _ in 0..configs.rows * configs.columns {
data.push(0.0f64);
}
Expand Down
6 changes: 6 additions & 0 deletions src/raster/grass_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ pub fn read_grass_raster(
let vec = line_split.collect::<Vec<&str>>();
if vec[0].to_lowercase().contains("rows") {
configs.rows = vec[1].trim().parse::<f32>().unwrap() as usize;
if configs.columns > 0 {
data.reserve(configs.rows * configs.columns);
}
} else if vec[0].to_lowercase().contains("cols") {
configs.columns = vec[1].trim().parse::<f32>().unwrap() as usize;
if configs.rows > 0 {
data.reserve(configs.rows * configs.columns);
}
} else if vec[0].to_lowercase().contains("north") {
configs.north = vec[1].trim().to_string().parse::<f64>().unwrap();
} else if vec[0].to_lowercase().contains("south") {
Expand Down
2 changes: 2 additions & 0 deletions src/raster/idrisi_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub fn read_idrisi(
configs.resolution_x = (configs.east - configs.west) / configs.columns as f64;
configs.resolution_y = (configs.north - configs.south) / configs.rows as f64;

data.reserve(configs.rows * configs.columns);

// read the data file
let data_file = file_name.replace(".rdc", ".rst");
let mut f = File::open(data_file.clone())?;
Expand Down
15 changes: 12 additions & 3 deletions src/raster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: June 2, 2017
Last Modified: 07/12/2018
Created: 02/06/2017
Last Modified: 09/02/2019
License: MIT
*/

Expand Down Expand Up @@ -250,18 +250,27 @@ impl Raster {
{
output.configs.nodata = 1.71041e38;
}
output.data.reserve(output.configs.rows * output.configs.columns);
output.data = vec![output.configs.nodata; output.configs.rows * output.configs.columns];
output
}

/// Returns the file name of the `Raster`, without the directory.
/// Returns the file name of the `Raster`, without the directory and file extension.
pub fn get_short_filename(&self) -> String {
let path = Path::new(&self.file_name);
let file_name = path.file_stem().unwrap();
let f = file_name.to_str().unwrap();
f.to_string()
}

/// Returns the file extension.
pub fn get_file_extension(&self) -> String {
let path = Path::new(&self.file_name);
let extension = path.extension().unwrap();
let e = extension.to_str().unwrap();
e.to_string()
}

/// Returns the value contained within a grid cell specified
/// by `row` and `column`.
pub fn get_value(&self, row: isize, column: isize) -> f64 {
Expand Down
2 changes: 2 additions & 0 deletions src/raster/saga_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub fn read_saga(
row_start = configs.rows - 1;
}

data.reserve(configs.rows * configs.columns);

// read the data file
let data_file = file_name.replace(".sgrd", ".sdat");
let mut f = File::open(data_file.clone())?;
Expand Down
2 changes: 2 additions & 0 deletions src/raster/surfer7_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub fn read_surfer7(
} as usize;
offset += 4;

data.reserve(configs.rows * configs.columns);

configs.west = unsafe {
mem::transmute::<[u8; 8], f64>([
buffer[offset],
Expand Down
1 change: 1 addition & 0 deletions src/raster/surfer_ascii_raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn read_surfer_ascii_raster(
}
configs.columns = vec[0].trim().parse::<f32>().unwrap() as usize;
configs.rows = vec[1].trim().parse::<f32>().unwrap() as usize;
data.reserve(configs.rows * configs.columns);
row = configs.rows - 1; // files are stored row major, bottom-to-top
num_cells = configs.rows * configs.columns;
data.clear();
Expand Down
Loading

0 comments on commit b1fcc40

Please sign in to comment.