Skip to content

Commit

Permalink
Fix for issue #113
Browse files Browse the repository at this point in the history
  • Loading branch information
jblindsay committed Sep 3, 2020
1 parent 8065f3c commit e78e919
Show file tree
Hide file tree
Showing 35 changed files with 164 additions and 132 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ for more details.
* Release Notes: *
******************

Version 1.X.X (XX-XX-2020)
- Added the ShadowTime model tool for modelling the proportion of daytime that a location is in shadow.
Version 1.4.0 (03-09-2020)
- Added the TimeInDaylight model tool for modelling the proportion of daytime that a location is not in shadow.
- Added the MapOffTerrainObjects tool.
- Added the FilterRasterFeaturesByArea tool.
- Added the LidarDigitalSurfaceModel tool.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/hydro_analysis/flow_accum_full_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl WhiteboxTool for FlowAccumulationFullWorkflow {
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl ToolManager {
tool_names.push("RelativeTopographicPosition".to_string());
tool_names.push("RemoveOffTerrainObjects".to_string());
tool_names.push("RuggednessIndex".to_string());
tool_names.push("ShadowTime".to_string());
tool_names.push("TimeInDaylight".to_string());
tool_names.push("SedimentTransportIndex".to_string());
tool_names.push("Slope".to_string());
tool_names.push("SlopeVsElevationPlot".to_string());
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl ToolManager {
}
"ruggednessindex" => Some(Box::new(terrain_analysis::RuggednessIndex::new())),
// "segmentterrain" => Some(Box::new(terrain_analysis::SegmentTerrain::new())),
"shadowtime" => Some(Box::new(terrain_analysis::ShadowTime::new())),
"timeindaylight" => Some(Box::new(terrain_analysis::TimeInDaylight::new())),
"sedimenttransportindex" => {
Some(Box::new(terrain_analysis::SedimentTransportIndex::new()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/stream_network_analysis/stream_link_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 25/06/2017
Last Modified: 18/10/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down
4 changes: 2 additions & 2 deletions src/tools/stream_network_analysis/stream_slope_continuous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ impl WhiteboxTool for StreamSlopeContinuous {
let mut mid_lat = (streams.configs.north - streams.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
cell_size_x = cell_size_x * (113200.0 * mid_lat.cos());
cell_size_y = cell_size_y * (113200.0 * mid_lat.cos());
cell_size_x = cell_size_x * (111320.0 * mid_lat.cos());
cell_size_y = cell_size_y * (111320.0 * mid_lat.cos());
diag_cell_size = (cell_size_x * cell_size_x + cell_size_y * cell_size_y).sqrt();
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/tools/terrain_analysis/aspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 22/06/2017
Last Modified: 30/01/2020
Last Modified: 03/09/2020
License: MIT
*/

Expand All @@ -25,7 +25,7 @@ use std::thread;
/// DEM is in the geographic coordinate system (latitude and longitude), the following equation
/// is used:
///
/// > zfactor = 1.0 / (113200.0 x cos(mid_lat))
/// > zfactor = 1.0 / (111320.0 x cos(mid_lat))
///
/// where `mid_lat` is the latitude of the centre of the raster, in radians.
///
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Aspect {
"Optional multiplier for when the vertical and horizontal units are not the same."
.to_owned(),
parameter_type: ParameterType::Float,
default_value: Some("1.0".to_owned()),
default_value: None,
optional: true,
});

Expand Down Expand Up @@ -162,7 +162,7 @@ impl WhiteboxTool for Aspect {
) -> Result<(), Error> {
let mut input_file = String::new();
let mut output_file = String::new();
let mut z_factor = 1f64;
let mut z_factor = -1f64;

if args.len() == 0 {
return Err(Error::new(
Expand Down Expand Up @@ -238,13 +238,15 @@ impl WhiteboxTool for Aspect {

let eight_grid_res = input.configs.resolution_x * 8.0;

if input.is_in_geographic_coordinates() {
if input.is_in_geographic_coordinates() && z_factor < 0.0 {
// calculate a new z-conversion factor
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
}
} else if z_factor < 0.0 {
z_factor = 1.0;
}

let mut output = Raster::initialize_using_file(&output_file, &input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 26/01/2019
Last Modified: 02/04/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -479,7 +479,7 @@ impl WhiteboxTool for AverageNormalVectorAngularDeviation {
let mut mid_lat = (configs.north - configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/terrain_analysis/circular_variance_of_aspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 26/01/2019
Last Modified: 02/04/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -481,7 +481,7 @@ impl WhiteboxTool for CircularVarianceOfAspect {
let mut mid_lat = (configs.north - configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/terrain_analysis/directional_relief.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 07/07/2017
Last Modified: 30/01/2020
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -276,7 +276,7 @@ impl WhiteboxTool for DirectionalRelief {
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
cell_size = cell_size * (113200.0 * mid_lat.cos());
cell_size = cell_size * (111320.0 * mid_lat.cos());
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/tools/terrain_analysis/drainage_preserving_smoothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay and Anthony Francioni
Created: 06/09/2018
Last Modified: 22/10/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -135,7 +135,7 @@ impl DrainagePreservingSmoothing {
"Optional multiplier for when the vertical and horizontal units are not the same."
.to_owned(),
parameter_type: ParameterType::Float,
default_value: Some("1.0".to_owned()),
default_value: None,
optional: true,
});

Expand Down Expand Up @@ -213,7 +213,7 @@ impl WhiteboxTool for DrainagePreservingSmoothing {
let mut num_iter = 3;
let mut reduction = 80f64;
let mut dfm_threshold = 0.15;
let mut z_factor = 1f64;
let mut z_factor = -1f64;
let mut max_z_diff = f64::INFINITY;

if args.len() == 0 {
Expand Down Expand Up @@ -340,14 +340,16 @@ impl WhiteboxTool for DrainagePreservingSmoothing {

let start = Instant::now();

if input.is_in_geographic_coordinates() {
if input.is_in_geographic_coordinates() && z_factor < 0.0 {
// calculate a new z-conversion factor
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
println!("It appears that the DEM is in geographic coordinates. The z-factor has been updated: {}.", z_factor);
}
} else if z_factor < 0.0 {
z_factor = 1.0;
}

let rows = input.configs.rows as isize;
Expand Down
12 changes: 7 additions & 5 deletions src/tools/terrain_analysis/edge_density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 27/01/2019
Last Modified: 22/10/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -95,7 +95,7 @@ impl EdgeDensity {
"Optional multiplier for when the vertical and horizontal units are not the same."
.to_owned(),
parameter_type: ParameterType::Float,
default_value: Some("1.0".to_owned()),
default_value: None,
optional: true,
});

Expand Down Expand Up @@ -170,7 +170,7 @@ impl WhiteboxTool for EdgeDensity {
let mut output_file = String::new();
let mut filter_size = 11usize;
let mut max_norm_diff = 5f64;
let mut z_factor = 1f64;
let mut z_factor = -1f64;

if args.len() == 0 {
return Err(Error::new(
Expand Down Expand Up @@ -281,14 +281,16 @@ impl WhiteboxTool for EdgeDensity {

let start = Instant::now();

if input.is_in_geographic_coordinates() {
if input.is_in_geographic_coordinates() && z_factor < 0.0 {
// calculate a new z-conversion factor
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
println!("It appears that the DEM is in geographic coordinates. The z-factor has been updated: {}.", z_factor);
}
} else if z_factor < 0.0 {
z_factor = 1.0;
}

let rows = input.configs.rows as isize;
Expand Down
12 changes: 7 additions & 5 deletions src/tools/terrain_analysis/feature_preserving_smoothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 23/11/2017
Last Modified: 22/10/2019
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -143,7 +143,7 @@ impl FeaturePreservingSmoothing {
"Optional multiplier for when the vertical and horizontal units are not the same."
.to_owned(),
parameter_type: ParameterType::Float,
default_value: Some("1.0".to_owned()),
default_value: None,
optional: true,
});

Expand Down Expand Up @@ -219,7 +219,7 @@ impl WhiteboxTool for FeaturePreservingSmoothing {
let mut filter_size = 11usize;
let mut max_norm_diff = 8f32;
let mut num_iter = 3;
let mut z_factor = 1f32;
let mut z_factor = -1f32;
let mut max_z_diff = f32::INFINITY;

if args.len() == 0 {
Expand Down Expand Up @@ -350,14 +350,16 @@ impl WhiteboxTool for FeaturePreservingSmoothing {

let start = Instant::now();

if input_dem.is_in_geographic_coordinates() {
if input_dem.is_in_geographic_coordinates() && z_factor < 0.0 {
// calculate a new z-conversion factor
let mut mid_lat = (input_dem.configs.north - input_dem.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = (1.0 / (113200.0 * mid_lat.cos())) as f32;
z_factor = (1.0 / (111320.0 * mid_lat.cos())) as f32;
println!("It appears that the DEM is in geographic coordinates. The z-factor has been updated to {}.", z_factor);
}
} else if z_factor < 0.0 {
z_factor = 1.0;
}

let input = Arc::new(input_dem.get_data_as_f32_array2d());
Expand Down
4 changes: 2 additions & 2 deletions src/tools/terrain_analysis/fetch_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 07/07/2017
Last Modified: 30/01/2020
Last Modified: 03/09/2020
License: MIT
*/

Expand Down Expand Up @@ -278,7 +278,7 @@ impl WhiteboxTool for FetchAnalysis {
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
cell_size = cell_size * (113200.0 * mid_lat.cos());
cell_size = cell_size * (111320.0 * mid_lat.cos());
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/tools/terrain_analysis/hillshade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 22/06/2017
Last Modified: 30/01/2020
Last Modified: 03/09/2020
License: MIT
*/

Expand All @@ -28,7 +28,7 @@ use std::thread;
/// DEM is in the geographic coordinate system (latitude and longitude), the following equation
/// is used:
///
/// > zfactor = 1.0 / (113200.0 x cos(mid_lat))
/// > zfactor = 1.0 / (111320.0 x cos(mid_lat))
///
/// where `mid_lat` is the latitude of the centre of the raster, in radians.
///
Expand Down Expand Up @@ -105,7 +105,7 @@ impl Hillshade {
"Optional multiplier for when the vertical and horizontal units are not the same."
.to_owned(),
parameter_type: ParameterType::Float,
default_value: Some("1.0".to_owned()),
default_value: None,
optional: true,
});

Expand Down Expand Up @@ -177,7 +177,7 @@ impl WhiteboxTool for Hillshade {
let mut output_file = String::new();
let mut azimuth = 315.0f64;
let mut altitude = 30.0f64;
let mut z_factor = 1f64;
let mut z_factor = -1f64;

if args.len() == 0 {
return Err(Error::new(
Expand Down Expand Up @@ -278,13 +278,15 @@ impl WhiteboxTool for Hillshade {
let cos_theta = altitude.cos();
let eight_grid_res = input.configs.resolution_x * 8.0;

if input.is_in_geographic_coordinates() {
if input.is_in_geographic_coordinates() && z_factor < 0.0 {
// calculate a new z-conversion factor
let mut mid_lat = (input.configs.north - input.configs.south) / 2.0;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
z_factor = 1.0 / (113200.0 * mid_lat.cos());
z_factor = 1.0 / (111320.0 * mid_lat.cos());
}
} else if z_factor < 0.0 {
z_factor = 1.0;
}

let mut configs = input.configs.clone();
Expand Down
8 changes: 4 additions & 4 deletions src/tools/terrain_analysis/horizon_angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Dr. John Lindsay
Created: 07/07/2017
Last Modified: 27/07/2020
Last Modified: 03/09/2020
License: MIT
NOTES: The tool should have the option to output a distance raster as well.
Expand Down Expand Up @@ -250,9 +250,9 @@ impl WhiteboxTool for HorizonAngle {
let mut mid_lat = ((configs.north - configs.south) / 2.0) as f32;
if mid_lat <= 90.0 && mid_lat >= -90.0 {
mid_lat = mid_lat.to_radians();
// cell_size = cell_size * (113200.0 * mid_lat.cos());
cell_size_x = cell_size_x * (113200.0 * mid_lat.cos());
cell_size_y = cell_size_y * (113200.0 * mid_lat.cos());
// cell_size = cell_size * (111320.0 * mid_lat.cos());
cell_size_x = cell_size_x * (111320.0 * mid_lat.cos());
cell_size_y = cell_size_y * (111320.0 * mid_lat.cos());
}
}

Expand Down
Loading

0 comments on commit e78e919

Please sign in to comment.