From e78e919b73706f881aa49812614ddaf2d04cfeda Mon Sep 17 00:00:00 2001 From: John Lindsay Date: Thu, 3 Sep 2020 13:17:39 -0400 Subject: [PATCH] Fix for issue #113 --- .DS_Store | Bin 10244 -> 10244 bytes readme.txt | 4 ++-- .../flow_accum_full_workflow.rs | 2 +- src/tools/mod.rs | 4 ++-- .../stream_network_analysis/stream_link_id.rs | 2 +- .../stream_slope_continuous.rs | 4 ++-- src/tools/terrain_analysis/aspect.rs | 14 ++++++------ ...average_normal_vector_angular_deviation.rs | 4 ++-- .../circular_variance_of_aspect.rs | 4 ++-- .../terrain_analysis/directional_relief.rs | 4 ++-- .../drainage_preserving_smoothing.rs | 12 ++++++----- src/tools/terrain_analysis/edge_density.rs | 12 ++++++----- .../feature_preserving_smoothing.rs | 12 ++++++----- src/tools/terrain_analysis/fetch_analysis.rs | 4 ++-- src/tools/terrain_analysis/hillshade.rs | 14 ++++++------ src/tools/terrain_analysis/horizon_angle.rs | 8 +++---- .../hypsometrically_tinted_hillshade.rs | 14 ++++++------ src/tools/terrain_analysis/mod.rs | 4 ++-- .../multidirectional_hillshade.rs | 14 ++++++------ .../terrain_analysis/multiscale_roughness.rs | 4 ++-- .../multiscale_roughness_signature.rs | 4 ++-- .../multiscale_std_dev_normals.rs | 4 ++-- .../multiscale_std_dev_normals_signature.rs | 4 ++-- .../pennock_landform_class.rs | 12 ++++++----- src/tools/terrain_analysis/plan_curvature.rs | 14 ++++++------ src/tools/terrain_analysis/prof_curvature.rs | 14 ++++++------ src/tools/terrain_analysis/relative_aspect.rs | 12 ++++++----- .../terrain_analysis/ruggedness_index.rs | 12 ++++++----- src/tools/terrain_analysis/slope.rs | 14 ++++++------ .../terrain_analysis/slope_vs_elev_plot.rs | 6 +++--- .../spherical_std_dev_of_normals.rs | 4 ++-- .../standard_deviation_of_slope.rs | 12 ++++++----- src/tools/terrain_analysis/tan_curvature.rs | 12 ++++++----- .../{shadow_time.rs => time_in_daylight.rs} | 20 +++++++++--------- src/tools/terrain_analysis/total_curvature.rs | 12 ++++++----- 35 files changed, 164 insertions(+), 132 deletions(-) rename src/tools/terrain_analysis/{shadow_time.rs => time_in_daylight.rs} (99%) diff --git a/.DS_Store b/.DS_Store index 4a690839e9bbdb6c2490fce725fdebba3833ede6..e562abf11514d5c89308619a61ba7de5c2ece00f 100644 GIT binary patch delta 75 zcmZn(XbISmCd_zZa=LJXhIn+Y#KLm&M^Wd^CL))(H?u4JVcE= -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()); } } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index feb0f52b1..9c5853979 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -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()); @@ -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())) } diff --git a/src/tools/stream_network_analysis/stream_link_id.rs b/src/tools/stream_network_analysis/stream_link_id.rs index eaa3544e2..e49a3d5a9 100644 --- a/src/tools/stream_network_analysis/stream_link_id.rs +++ b/src/tools/stream_network_analysis/stream_link_id.rs @@ -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 */ diff --git a/src/tools/stream_network_analysis/stream_slope_continuous.rs b/src/tools/stream_network_analysis/stream_slope_continuous.rs index 018ba9508..15afbdc4f 100644 --- a/src/tools/stream_network_analysis/stream_slope_continuous.rs +++ b/src/tools/stream_network_analysis/stream_slope_continuous.rs @@ -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(); } } diff --git a/src/tools/terrain_analysis/aspect.rs b/src/tools/terrain_analysis/aspect.rs index 90ad23b81..bfc4fd8a5 100644 --- a/src/tools/terrain_analysis/aspect.rs +++ b/src/tools/terrain_analysis/aspect.rs @@ -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 */ @@ -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. /// @@ -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, }); @@ -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( @@ -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); diff --git a/src/tools/terrain_analysis/average_normal_vector_angular_deviation.rs b/src/tools/terrain_analysis/average_normal_vector_angular_deviation.rs index 88f63c45c..3a66fc3c1 100644 --- a/src/tools/terrain_analysis/average_normal_vector_angular_deviation.rs +++ b/src/tools/terrain_analysis/average_normal_vector_angular_deviation.rs @@ -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 */ @@ -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()); } } diff --git a/src/tools/terrain_analysis/circular_variance_of_aspect.rs b/src/tools/terrain_analysis/circular_variance_of_aspect.rs index dfbda3a76..ed60d222b 100644 --- a/src/tools/terrain_analysis/circular_variance_of_aspect.rs +++ b/src/tools/terrain_analysis/circular_variance_of_aspect.rs @@ -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 */ @@ -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()); } } diff --git a/src/tools/terrain_analysis/directional_relief.rs b/src/tools/terrain_analysis/directional_relief.rs index 2f7bd033a..efd1e0af8 100644 --- a/src/tools/terrain_analysis/directional_relief.rs +++ b/src/tools/terrain_analysis/directional_relief.rs @@ -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 */ @@ -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()); } } diff --git a/src/tools/terrain_analysis/drainage_preserving_smoothing.rs b/src/tools/terrain_analysis/drainage_preserving_smoothing.rs index cc9400cef..5beb15ea5 100644 --- a/src/tools/terrain_analysis/drainage_preserving_smoothing.rs +++ b/src/tools/terrain_analysis/drainage_preserving_smoothing.rs @@ -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 */ @@ -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, }); @@ -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 { @@ -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; diff --git a/src/tools/terrain_analysis/edge_density.rs b/src/tools/terrain_analysis/edge_density.rs index b518fb127..bbce7a2f5 100644 --- a/src/tools/terrain_analysis/edge_density.rs +++ b/src/tools/terrain_analysis/edge_density.rs @@ -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 */ @@ -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, }); @@ -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( @@ -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; diff --git a/src/tools/terrain_analysis/feature_preserving_smoothing.rs b/src/tools/terrain_analysis/feature_preserving_smoothing.rs index 836a9551f..f3663458f 100644 --- a/src/tools/terrain_analysis/feature_preserving_smoothing.rs +++ b/src/tools/terrain_analysis/feature_preserving_smoothing.rs @@ -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 */ @@ -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, }); @@ -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 { @@ -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()); diff --git a/src/tools/terrain_analysis/fetch_analysis.rs b/src/tools/terrain_analysis/fetch_analysis.rs index 60ec56218..cfe833457 100644 --- a/src/tools/terrain_analysis/fetch_analysis.rs +++ b/src/tools/terrain_analysis/fetch_analysis.rs @@ -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 */ @@ -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()); } } diff --git a/src/tools/terrain_analysis/hillshade.rs b/src/tools/terrain_analysis/hillshade.rs index aaf3071c8..6c9f841ab 100644 --- a/src/tools/terrain_analysis/hillshade.rs +++ b/src/tools/terrain_analysis/hillshade.rs @@ -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 */ @@ -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. /// @@ -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, }); @@ -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( @@ -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(); diff --git a/src/tools/terrain_analysis/horizon_angle.rs b/src/tools/terrain_analysis/horizon_angle.rs index da3e3481a..1850f0358 100644 --- a/src/tools/terrain_analysis/horizon_angle.rs +++ b/src/tools/terrain_analysis/horizon_angle.rs @@ -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. @@ -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()); } } diff --git a/src/tools/terrain_analysis/hypsometrically_tinted_hillshade.rs b/src/tools/terrain_analysis/hypsometrically_tinted_hillshade.rs index 8c5c76850..f5223a595 100644 --- a/src/tools/terrain_analysis/hypsometrically_tinted_hillshade.rs +++ b/src/tools/terrain_analysis/hypsometrically_tinted_hillshade.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 09/07/2020 -Last Modified: 19/07/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -43,7 +43,7 @@ use std::thread; /// Z conversion factor. If the 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. /// @@ -169,7 +169,7 @@ impl HypsometricallyTintedHillshade { "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, }); @@ -253,7 +253,7 @@ impl WhiteboxTool for HypsometricallyTintedHillshade { let mut multidirection360mode = false; // let mut azimuth = 315.0f64; let mut altitude = 45.0f64; - let mut z_factor = 1f64; + let mut z_factor = -1f64; let mut hs_alpha = 0.5f32; let mut brightness = 0.5f32; let mut atmospheric_alpha = 0.0f32; @@ -430,13 +430,15 @@ impl WhiteboxTool for HypsometricallyTintedHillshade { 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 rows = input.configs.rows as isize; diff --git a/src/tools/terrain_analysis/mod.rs b/src/tools/terrain_analysis/mod.rs index 251667d6c..2e56892b9 100644 --- a/src/tools/terrain_analysis/mod.rs +++ b/src/tools/terrain_analysis/mod.rs @@ -52,7 +52,7 @@ mod relative_topographic_position; mod remove_off_terrain_objects; mod ruggedness_index; mod sediment_transport_index; -mod shadow_time; +mod time_in_daylight; mod slope; mod slope_vs_elev_plot; mod spherical_std_dev_of_normals; @@ -118,7 +118,7 @@ pub use self::relative_topographic_position::RelativeTopographicPosition; pub use self::remove_off_terrain_objects::RemoveOffTerrainObjects; pub use self::ruggedness_index::RuggednessIndex; pub use self::sediment_transport_index::SedimentTransportIndex; -pub use self::shadow_time::ShadowTime; +pub use self::time_in_daylight::TimeInDaylight; pub use self::slope::Slope; pub use self::slope_vs_elev_plot::SlopeVsElevationPlot; pub use self::spherical_std_dev_of_normals::SphericalStdDevOfNormals; diff --git a/src/tools/terrain_analysis/multidirectional_hillshade.rs b/src/tools/terrain_analysis/multidirectional_hillshade.rs index 2a5530b43..e2be83d68 100644 --- a/src/tools/terrain_analysis/multidirectional_hillshade.rs +++ b/src/tools/terrain_analysis/multidirectional_hillshade.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 19/07/2020 -Last Modified: 19/07/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -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. The Z conversion factor can also be used /// used to apply a vertical exageration to further emphasize landforms within the hillshade output. @@ -109,7 +109,7 @@ impl MultidirectionalHillshade { "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, }); @@ -195,7 +195,7 @@ impl WhiteboxTool for MultidirectionalHillshade { let mut input_file = String::new(); let mut output_file = String::new(); let mut altitude = 30.0f64; - let mut z_factor = 1f64; + let mut z_factor = -1f64; let mut multidirection360mode = false; if args.len() == 0 { @@ -288,13 +288,15 @@ impl WhiteboxTool for MultidirectionalHillshade { 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(); diff --git a/src/tools/terrain_analysis/multiscale_roughness.rs b/src/tools/terrain_analysis/multiscale_roughness.rs index 721399bf3..5cb919e8a 100644 --- a/src/tools/terrain_analysis/multiscale_roughness.rs +++ b/src/tools/terrain_analysis/multiscale_roughness.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 26/02/2018 -Last Modified: 22/10/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -270,7 +270,7 @@ impl WhiteboxTool for MultiscaleRoughness { 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()); } } diff --git a/src/tools/terrain_analysis/multiscale_roughness_signature.rs b/src/tools/terrain_analysis/multiscale_roughness_signature.rs index dda6319f0..be7731c51 100644 --- a/src/tools/terrain_analysis/multiscale_roughness_signature.rs +++ b/src/tools/terrain_analysis/multiscale_roughness_signature.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 27/02/2018 -Last Modified: 22/10/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -279,7 +279,7 @@ impl WhiteboxTool for MultiscaleRoughnessSignature { 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()); } } diff --git a/src/tools/terrain_analysis/multiscale_std_dev_normals.rs b/src/tools/terrain_analysis/multiscale_std_dev_normals.rs index 6f69265ea..65782c128 100644 --- a/src/tools/terrain_analysis/multiscale_std_dev_normals.rs +++ b/src/tools/terrain_analysis/multiscale_std_dev_normals.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 05/06/2019 -Last Modified: 13/06/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -352,7 +352,7 @@ impl WhiteboxTool for MultiscaleStdDevNormals { let mut mid_lat = (configs.north - configs.south) as f32 / 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()); } } diff --git a/src/tools/terrain_analysis/multiscale_std_dev_normals_signature.rs b/src/tools/terrain_analysis/multiscale_std_dev_normals_signature.rs index c112440a2..a5bc2a20c 100644 --- a/src/tools/terrain_analysis/multiscale_std_dev_normals_signature.rs +++ b/src/tools/terrain_analysis/multiscale_std_dev_normals_signature.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 20/06/2019 -Last Modified: 20/06/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -312,7 +312,7 @@ impl WhiteboxTool for MultiscaleStdDevNormalsSignature { let mut mid_lat = (configs.north - configs.south) as f32 / 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()); } } diff --git a/src/tools/terrain_analysis/pennock_landform_class.rs b/src/tools/terrain_analysis/pennock_landform_class.rs index b0a72dcc9..0b1bee004 100644 --- a/src/tools/terrain_analysis/pennock_landform_class.rs +++ b/src/tools/terrain_analysis/pennock_landform_class.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 12/07/2017 -Last Modified: 30/01/2020 +Last Modified: 03/09/2020 License: MIT Notes: Some degree of DEM smoothing is likely required to get reasonable results. @@ -135,7 +135,7 @@ impl PennockLandformClass { "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, }); @@ -205,7 +205,7 @@ impl WhiteboxTool for PennockLandformClass { ) -> Result<(), Error> { let mut input_file = String::new(); let mut output_file = String::new(); - let mut z_factor = 1f64; + let mut z_factor = -1f64; let mut slope_threshold = 3f64; let mut prof_threshold = 0.1_f64; let mut plan_threshold = 0f64; @@ -321,13 +321,15 @@ impl WhiteboxTool for PennockLandformClass { let four_times_cell_size_sqrd = cell_size_sqrd * 4.0f64; let eight_grid_res = cell_size * 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); diff --git a/src/tools/terrain_analysis/plan_curvature.rs b/src/tools/terrain_analysis/plan_curvature.rs index ec43756bf..3130b6ea8 100644 --- a/src/tools/terrain_analysis/plan_curvature.rs +++ b/src/tools/terrain_analysis/plan_curvature.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 01/06/2017 -Last Modified: 30/01/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -28,7 +28,7 @@ use std::thread; /// elevation in the DEM by the Z Conversion Factor. If the 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. /// @@ -84,7 +84,7 @@ impl PlanCurvature { "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, }); @@ -158,7 +158,7 @@ impl WhiteboxTool for PlanCurvature { ) -> 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( @@ -234,13 +234,15 @@ impl WhiteboxTool for PlanCurvature { let cell_size_sqrd = cell_size * cell_size; let four_times_cell_size_sqrd = cell_size_sqrd * 4.0f64; - 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); diff --git a/src/tools/terrain_analysis/prof_curvature.rs b/src/tools/terrain_analysis/prof_curvature.rs index 2c48b2703..b8487b44e 100644 --- a/src/tools/terrain_analysis/prof_curvature.rs +++ b/src/tools/terrain_analysis/prof_curvature.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 22/062017 -Last Modified: 30/01/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -29,7 +29,7 @@ use std::thread; /// elevation in the DEM by the Z Conversion Factor. If the 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. /// @@ -84,7 +84,7 @@ impl ProfileCurvature { "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, }); @@ -158,7 +158,7 @@ impl WhiteboxTool for ProfileCurvature { ) -> 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( @@ -234,13 +234,15 @@ impl WhiteboxTool for ProfileCurvature { let cell_size_sqrd = cell_size * cell_size; let four_times_cell_size_sqrd = cell_size_sqrd * 4.0f64; - 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); diff --git a/src/tools/terrain_analysis/relative_aspect.rs b/src/tools/terrain_analysis/relative_aspect.rs index db9c312af..446e484f8 100644 --- a/src/tools/terrain_analysis/relative_aspect.rs +++ b/src/tools/terrain_analysis/relative_aspect.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 17/06/2017 -Last Modified: 30/01/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -84,7 +84,7 @@ impl RelativeAspect { "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, }); @@ -159,7 +159,7 @@ impl WhiteboxTool for RelativeAspect { let mut input_file = String::new(); let mut output_file = String::new(); let mut azimuth = 0.0f64; - let mut z_factor = 1f64; + let mut z_factor = -1f64; if args.len() == 0 { return Err(Error::new( @@ -244,13 +244,15 @@ impl WhiteboxTool for RelativeAspect { let eight_grid_res = input.configs.resolution_x * 8.0; - if input.configs.xy_units.contains("deg") { + 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); diff --git a/src/tools/terrain_analysis/ruggedness_index.rs b/src/tools/terrain_analysis/ruggedness_index.rs index ddce6c9ea..22cc62ff8 100644 --- a/src/tools/terrain_analysis/ruggedness_index.rs +++ b/src/tools/terrain_analysis/ruggedness_index.rs @@ -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 */ @@ -76,7 +76,7 @@ impl RuggednessIndex { "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, }); @@ -150,7 +150,7 @@ impl WhiteboxTool for RuggednessIndex { ) -> 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( @@ -221,13 +221,15 @@ impl WhiteboxTool for RuggednessIndex { let start = Instant::now(); - if input.configs.xy_units.contains("deg") { + 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); diff --git a/src/tools/terrain_analysis/slope.rs b/src/tools/terrain_analysis/slope.rs index 406cb443b..f13d830c0 100644 --- a/src/tools/terrain_analysis/slope.rs +++ b/src/tools/terrain_analysis/slope.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 22/06/2017 -Last Modified: 21/02/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -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. /// @@ -95,7 +95,7 @@ impl Slope { "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, }); @@ -183,7 +183,7 @@ impl WhiteboxTool for Slope { ) -> Result<(), Error> { let mut input_file = String::new(); let mut output_file = String::new(); - let mut z_factor = 1f64; + let mut z_factor = -1f64; let mut units_numeric = 1; // degrees if args.len() == 0 { @@ -270,13 +270,15 @@ impl WhiteboxTool for Slope { 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); diff --git a/src/tools/terrain_analysis/slope_vs_elev_plot.rs b/src/tools/terrain_analysis/slope_vs_elev_plot.rs index 0bb8c900d..6aea910f6 100644 --- a/src/tools/terrain_analysis/slope_vs_elev_plot.rs +++ b/src/tools/terrain_analysis/slope_vs_elev_plot.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 01/02/2018 -Last Modified: 12/10/2018 +Last Modified: 03/09/2020 License: MIT */ @@ -277,7 +277,7 @@ impl WhiteboxTool for SlopeVsElevationPlot { 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()); } } @@ -424,7 +424,7 @@ impl WhiteboxTool for SlopeVsElevationPlot { 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()); } } diff --git a/src/tools/terrain_analysis/spherical_std_dev_of_normals.rs b/src/tools/terrain_analysis/spherical_std_dev_of_normals.rs index 3e01afe00..ceed6c5a8 100644 --- a/src/tools/terrain_analysis/spherical_std_dev_of_normals.rs +++ b/src/tools/terrain_analysis/spherical_std_dev_of_normals.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 22/05/2019 -Last Modified: 22/10/2019 +Last Modified: 03/09/2020 License: MIT */ @@ -490,7 +490,7 @@ impl WhiteboxTool for SphericalStdDevOfNormals { 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()); } } diff --git a/src/tools/terrain_analysis/standard_deviation_of_slope.rs b/src/tools/terrain_analysis/standard_deviation_of_slope.rs index 583ca105d..ce322ccd3 100644 --- a/src/tools/terrain_analysis/standard_deviation_of_slope.rs +++ b/src/tools/terrain_analysis/standard_deviation_of_slope.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Anthony Francioni Created: 26/05/2018 -Last Modified: 30/01/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -63,7 +63,7 @@ impl StandardDeviationOfSlope { "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, }); @@ -155,7 +155,7 @@ impl WhiteboxTool for StandardDeviationOfSlope { ) -> Result<(), Error> { let mut input_file = String::new(); let mut output_file = String::new(); - let mut z_factor = 1f64; + let mut z_factor = -1f64; let mut filter_size_x = 11usize; let mut filter_size_y = 11usize; @@ -292,13 +292,15 @@ impl WhiteboxTool for StandardDeviationOfSlope { let nodata = input.configs.nodata; 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); diff --git a/src/tools/terrain_analysis/tan_curvature.rs b/src/tools/terrain_analysis/tan_curvature.rs index ec6790b11..985bf35af 100644 --- a/src/tools/terrain_analysis/tan_curvature.rs +++ b/src/tools/terrain_analysis/tan_curvature.rs @@ -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 */ @@ -74,7 +74,7 @@ impl TangentialCurvature { "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, }); @@ -148,7 +148,7 @@ impl WhiteboxTool for TangentialCurvature { ) -> 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( @@ -224,13 +224,15 @@ impl WhiteboxTool for TangentialCurvature { let cell_size_sqrd = cell_size * cell_size; let four_times_cell_size_sqrd = cell_size_sqrd * 4.0f64; - 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); diff --git a/src/tools/terrain_analysis/shadow_time.rs b/src/tools/terrain_analysis/time_in_daylight.rs similarity index 99% rename from src/tools/terrain_analysis/shadow_time.rs rename to src/tools/terrain_analysis/time_in_daylight.rs index 73f9968ff..f8dc991ee 100644 --- a/src/tools/terrain_analysis/shadow_time.rs +++ b/src/tools/terrain_analysis/time_in_daylight.rs @@ -2,7 +2,7 @@ This tool is part of the WhiteboxTools geospatial analysis library. Authors: Dr. John Lindsay Created: 29/07/2020 -Last Modified: 21/08/2020 +Last Modified: 03/09/2020 License: MIT */ @@ -22,8 +22,8 @@ use rayon::prelude::*; use chrono::prelude::*; use chrono::{Date, FixedOffset, NaiveTime, TimeZone}; -/// This tool calculates the proportion of time a location is within an area of shadow. -pub struct ShadowTime { +/// This tool calculates the proportion of time a location is within daylight (i.e. outside of an area of shadow cast by a local object). +pub struct TimeInDaylight { name: String, description: String, toolbox: String, @@ -31,10 +31,10 @@ pub struct ShadowTime { example_usage: String, } -impl ShadowTime { +impl TimeInDaylight { /// public constructor - pub fn new() -> ShadowTime { - let name = "ShadowTime".to_string(); + pub fn new() -> TimeInDaylight { + let name = "TimeInDaylight".to_string(); let toolbox = "Geomorphometric Analysis".to_string(); let description = "Calculates the proportion of time a location is within an area of shadow." @@ -154,7 +154,7 @@ impl ShadowTime { } let usage = format!(">>.*{0} -r={1} -v --wd=\"*path*to*data*\" -i='input.tif' -o=output.tif --az_fraction=15.0 --max_dist=100.0 --lat=43.545 --long=-80.248", short_exe, name).replace("*", &sep); - ShadowTime { + TimeInDaylight { name: name, description: description, toolbox: toolbox, @@ -164,7 +164,7 @@ impl ShadowTime { } } -impl WhiteboxTool for ShadowTime { +impl WhiteboxTool for TimeInDaylight { fn get_source_file(&self) -> String { String::from(file!()) } @@ -469,8 +469,8 @@ impl WhiteboxTool for ShadowTime { 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_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()); } } diff --git a/src/tools/terrain_analysis/total_curvature.rs b/src/tools/terrain_analysis/total_curvature.rs index aa85fb106..720e99d5b 100644 --- a/src/tools/terrain_analysis/total_curvature.rs +++ b/src/tools/terrain_analysis/total_curvature.rs @@ -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 */ @@ -76,7 +76,7 @@ impl TotalCurvature { "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, }); @@ -150,7 +150,7 @@ impl WhiteboxTool for TotalCurvature { ) -> 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( @@ -225,13 +225,15 @@ impl WhiteboxTool for TotalCurvature { let cell_size_sqrd = cell_size * cell_size; let four_times_cell_size_sqrd = cell_size_sqrd * 4.0f64; - 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);