From bd6d4ba950235cdbd8f6be05cbbf7c2517eb2b91 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sun, 29 Nov 2026 03:52:09 -0300 Subject: [PATCH 1/3] feat(engine): Shaded Relief names values outside a land elevation (#3151, part 4) Applying Shaded Relief to a band whose statistics go below -500 or above 9,000 (PLAUSIBLE_ELEVATION, now shared with Check DEM) posts a notice naming them. It says that depths, as in a bathymetry, are real, and that an undeclared no-data is drawn as cliffs; Check DEM finds where they are and raster.mask hides what isn't terrain. Posted when the relief is applied or changes band, not at each change of its light. Co-Authored-By: Claude Opus 5.5 --- crates/analysis/src/lib.rs | 5 +-- crates/analysis/src/tools.rs | 1 + crates/analysis/src/tools/check_dem.rs | 6 ++-- crates/engine/src/cmd/raster.rs | 44 ++++++++++++++++++++++++- crates/engine/src/tests.rs | 45 ++++++++++++++++++++++++++ docs/user-guide/data.md | 6 ++++ 6 files changed, 101 insertions(+), 6 deletions(-) diff --git a/crates/analysis/src/lib.rs b/crates/analysis/src/lib.rs index 3d112a3576..5cce7f9396 100644 --- a/crates/analysis/src/lib.rs +++ b/crates/analysis/src/lib.rs @@ -48,8 +48,9 @@ pub use density::{ pub use parallel::scratch_budget; pub use parameters::StatisticList; pub use tools::{ - SimplifyNotes, TOOLS, find_field_case_insensitive, holds_coordinates, in_its_units, layer_raster_crs, max_buffer_bytes, min_pad, - param_applies, past_pole, points_from, points_in, projected_crs, raster_crs, raster_crs_in, simplify_geometry, zonal_bands, + PLAUSIBLE_ELEVATION, SimplifyNotes, TOOLS, find_field_case_insensitive, holds_coordinates, in_its_units, layer_raster_crs, + max_buffer_bytes, min_pad, param_applies, past_pole, points_from, points_in, projected_crs, raster_crs, raster_crs_in, + simplify_geometry, zonal_bands, }; use rustgis_data::Dataset; diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 97f3ab4462..0f61e7547f 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -1,6 +1,7 @@ //! The tools. mod check_dem; +pub use check_dem::PLAUSIBLE_ELEVATION; mod check_geometry; mod geometry; mod network_analysis; diff --git a/crates/analysis/src/tools/check_dem.rs b/crates/analysis/src/tools/check_dem.rs index 9b0711383d..101fc4701b 100644 --- a/crates/analysis/src/tools/check_dem.rs +++ b/crates/analysis/src/tools/check_dem.rs @@ -31,9 +31,9 @@ const MAX_POINTS: usize = 100_000; /// About how many cells one item of the scan reads: enough to share out on threads, few enough /// items that a small model is checked in a few looks at Cancel. const BLOCK_CELLS: usize = 1 << 16; -/// The lowest and highest values an elevation model can hold, in metres: below the Dead Sea's -/// shore and the deepest mine, above Everest. -pub(crate) const PLAUSIBLE_ELEVATION: (f64, f64) = (-500.0, 9000.0); +/// The lowest and highest values an elevation model of the land can hold, in metres: below the +/// Dead Sea's shore and the deepest mine, above Everest. A bathymetry goes deeper. +pub const PLAUSIBLE_ELEVATION: (f64, f64) = (-500.0, 9000.0); /// The eight neighbours, as (column, row) steps. const AROUND: [(i64, i64); 8] = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]; diff --git a/crates/engine/src/cmd/raster.rs b/crates/engine/src/cmd/raster.rs index 15d9fa658f..41a36e8f69 100644 --- a/crates/engine/src/cmd/raster.rs +++ b/crates/engine/src/cmd/raster.rs @@ -990,6 +990,7 @@ fn symbology(s: &mut Session, p: &Value) -> CmdResult { }) .transpose()?; let bnd = band(p, "band", &r)?; + let was = relief_band(s, id); with(s, p, |rl, r| { let cur_band = rl.style.renderer.bands().first().copied().unwrap_or(0); let bi = bnd.unwrap_or(cur_band).min(r.band_count().saturating_sub(1)); @@ -1094,7 +1095,48 @@ fn symbology(s: &mut Session, p: &Value) -> CmdResult { rl.style.stretch = Stretch::default(); } Ok(()) - }) + })?; + if relief_band(s, id) != was { + relief_notice(s, id, &r); + } + Ok(Value::Null) +} + +/// The band a layer's Shaded Relief is drawn from, if it is drawn as one. +fn relief_band(s: &Session, id: u32) -> Option { + match s.map().layer(id)?.raster.as_ref()?.style.renderer { + RasterRenderer::ShadedRelief { band, .. } => Some(band), + _ => None, + } +} + +/// Says when a Shaded Relief is drawn from a band holding values outside +/// [`rustgis_analysis::PLAUSIBLE_ELEVATION`] (#3151). They may be real depths, as in a bathymetry +/// such as GEBCO, or a no-data the file doesn't declare, such as -32768, which the relief draws as +/// cliffs: the notice names both and leaves the choice to the user. A look at the band's +/// statistics, when the relief is applied or moves to another band, not at each change of its +/// light; Check DEM says where the values are. +fn relief_notice(s: &mut Session, id: u32, r: &Raster) { + let (lowest, highest) = rustgis_analysis::PLAUSIBLE_ELEVATION; + let Some(l) = s.map().layer(id) else { return }; + let Some(RasterRenderer::ShadedRelief { band, .. }) = l.raster.as_ref().map(|rl| &rl.style.renderer) else { return }; + let Some(stats) = r.bands.get(*band).map(|b| &b.stats).filter(|st| st.count > 0) else { return }; + let mut odd = Vec::new(); + if stats.min < lowest { + odd.push(format!("as low as {}", stats.min)); + } + if stats.max > highest { + odd.push(format!("as high as {}", stats.max)); + } + if odd.is_empty() { + return; + } + let text = format!( + "'{}' holds values outside {lowest} to {highest} ({}). Depths, as in a bathymetry, are real and drawn as they are; a no-data the file doesn't declare, such as -32768, is drawn as cliffs. Check DEM (checkDem) finds where the values are, and raster.mask hides those that aren't terrain", + l.name, + odd.join(" and ") + ); + s.notify(text, false); } /// `raster.symbology`'s `"type"` as the command matches it: lower case, without spaces, `_` or `-`; diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 35af0bfbad..8bab6eaade 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -7737,6 +7737,51 @@ fn custom_projections_switch_keep_scale_query_and_render() { } } +/// A Shaded Relief drawn from a band holding values outside the range of a land elevation (an +/// undeclared no-data of -32768, a height of 65535, a depth of a bathymetry) says so and names +/// them, without calling a depth a no-data, once: not again at a change of its light. A clean band, +/// or one whose no-data is declared, says nothing (#3151). +#[test] +fn shaded_relief_names_values_outside_a_land_elevation() { + let dir = std::env::temp_dir().join(format!("rustgis-engine-relief-values-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let mut s = Session::new(Project::default()); + for (name, head, corner, said) in [ + ("hole.asc", "", "-32768", Some("as low as -32768")), + ("high.asc", "", "65535", Some("as high as 65535")), + ("deep.asc", "", "-10900", Some("as low as -10900")), + ("clean.asc", "", "818", None), + ("declared.asc", "NODATA_value -32768\n", "-32768", None), + ] { + let path = dir.join(name); + let grid = + format!("ncols 3\nnrows 3\nxllcorner 10\nyllcorner 40\ncellsize 0.001\n{head}812 815 {corner}\n809 811 814\n806 808 810\n"); + std::fs::write(&path, grid).unwrap(); + let id = s.run("layer.addData", &json!({"path": path})).unwrap()["layer"].as_u64().unwrap(); + let mark = s.notice_mark(); + s.run("raster.symbology", &json!({"layer": id, "type": "shadedRelief"})).unwrap(); + let notice = s.notices_since(mark).iter().find(|n| n.text.contains("holds values outside")).map(|n| n.text.clone()); + match said { + Some(values) => { + let notice = notice.unwrap_or_else(|| panic!("{name}: {:?}", s.notices_since(mark))); + assert!(notice.contains(values) && notice.contains("Check DEM (checkDem)"), "{notice}"); + // A depth is real: the notice names it as one, and doesn't ask for it to be no-data. + assert!(notice.contains("Depths, as in a bathymetry, are real") && !notice.contains("declare them"), "{notice}"); + } + None => assert_eq!(notice, None, "{name}"), + } + // A change of the relief's light says nothing again. + let mark = s.notice_mark(); + s.run("raster.symbology", &json!({"layer": id, "type": "shadedRelief", "azimuth": 270})).unwrap(); + assert!(!s.notices_since(mark).iter().any(|n| n.text.contains("holds values outside")), "{name}"); + // Another symbology says nothing of it. + let mark = s.notice_mark(); + s.run("raster.symbology", &json!({"layer": id, "type": "stretch"})).unwrap(); + assert!(!s.notices_since(mark).iter().any(|n| n.text.contains("holds values outside")), "{name}"); + } + std::fs::remove_dir_all(dir).unwrap(); +} + /// Shaded Relief's cast shadows: set, kept when left out, clamped, a new one without; saved with /// the project only when there are some, and drawn in an export (waited for). #[test] diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index ddd3e58480..9c60329055 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -1733,6 +1733,12 @@ stretch, and an opaque black cell still counts. The alpha band's own statistics alpha with a value, see-through ones included. **Change Detection** gives no-data where either image is see-through. +**Shaded Relief** names the values its band holds outside −500 to 9,000 (from the band's +statistics). They may be real depths, as in a bathymetry such as GEBCO, which are drawn as they +are, or a no-data the file doesn't declare, such as −32768, which the relief draws as cliffs. Check +DEM (`checkDem`, see [Checking an elevation model](analysis.md#checking-an-elevation-model)) finds +where they are, and `raster.mask` hides those that aren't terrain. + **Cast shadows**, on a Shaded Relief layer (`raster.symbology` `"shadow"`, 0 to 1), darkens the slopes the terrain hides from the sun as well as those facing away from it: a valley behind a ridge is in shadow, with a soft edge. Only the direct light is darkened: a slope in full shadow keeps the From cc5798426e53012c2858d124fcc728230230670d Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sun, 29 Nov 2026 04:03:03 -0300 Subject: [PATCH 2/3] docs(engine): say when the Shaded Relief notice is posted and what it names (#3151, part 4) The guide says the notice gives the band's lowest and highest values outside the range, from statistics that leave out a declared no-data, and that it is posted when the relief is applied or changes band. The test's assertion that could never fail now checks that the notice names depths and an undeclared no-data apart. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 7 +++++-- docs/user-guide/data.md | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 8bab6eaade..ebca733592 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -7765,8 +7765,11 @@ fn shaded_relief_names_values_outside_a_land_elevation() { Some(values) => { let notice = notice.unwrap_or_else(|| panic!("{name}: {:?}", s.notices_since(mark))); assert!(notice.contains(values) && notice.contains("Check DEM (checkDem)"), "{notice}"); - // A depth is real: the notice names it as one, and doesn't ask for it to be no-data. - assert!(notice.contains("Depths, as in a bathymetry, are real") && !notice.contains("declare them"), "{notice}"); + // A depth is real: the notice names it as one, and the undeclared no-data apart from it. + assert!( + notice.contains("Depths, as in a bathymetry, are real") && notice.contains("a no-data the file doesn't declare"), + "{notice}" + ); } None => assert_eq!(notice, None, "{name}"), } diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index 9c60329055..063c037c37 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -1733,11 +1733,15 @@ stretch, and an opaque black cell still counts. The alpha band's own statistics alpha with a value, see-through ones included. **Change Detection** gives no-data where either image is see-through. -**Shaded Relief** names the values its band holds outside −500 to 9,000 (from the band's -statistics). They may be real depths, as in a bathymetry such as GEBCO, which are drawn as they -are, or a no-data the file doesn't declare, such as −32768, which the relief draws as cliffs. Check -DEM (`checkDem`, see [Checking an elevation model](analysis.md#checking-an-elevation-model)) finds -where they are, and `raster.mask` hides those that aren't terrain. +When **Shaded Relief** is applied, or moved to another band, it posts a notice if the band's lowest +or highest value lies outside −500 to 9,000. The notice gives those two extremes, not each such +value. They come from the band's statistics, which leave out a no-data the file declares, so only +the values it doesn't declare are named. They may be real depths, as in a bathymetry such as GEBCO, +which are drawn as they are, or a no-data the file doesn't declare, such as −32768, which the +relief draws as cliffs. Check DEM (`checkDem`, see [Checking an elevation +model](analysis.md#checking-an-elevation-model)) finds where they are, and `raster.mask` hides +those that aren't terrain. A change of the relief's light, such as its azimuth or shadow, posts no +notice again. **Cast shadows**, on a Shaded Relief layer (`raster.symbology` `"shadow"`, 0 to 1), darkens the slopes the terrain hides from the sun as well as those facing away from it: a valley behind a ridge From 204043b532b35931e333a23b3657b53c275c1e23 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sun, 29 Nov 2026 04:07:26 -0300 Subject: [PATCH 3/3] docs(engine): the Shaded Relief notice reads an overview's statistics on a layer held as one (#3151, part 4) On a layer held as an overview of its file with no stored statistics, the band's extremes are the overview's, so a lone cell of a value outside the range may not show in them. The guide says so, and that Check DEM runs on the same cells and says when they are an overview's. Co-Authored-By: Claude Opus 5.5 --- docs/user-guide/data.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index 063c037c37..c5c0071784 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -1736,9 +1736,12 @@ alpha with a value, see-through ones included. When **Shaded Relief** is applied, or moved to another band, it posts a notice if the band's lowest or highest value lies outside −500 to 9,000. The notice gives those two extremes, not each such value. They come from the band's statistics, which leave out a no-data the file declares, so only -the values it doesn't declare are named. They may be real depths, as in a bathymetry such as GEBCO, -which are drawn as they are, or a no-data the file doesn't declare, such as −32768, which the -relief draws as cliffs. Check DEM (`checkDem`, see [Checking an elevation +the values it doesn't declare are named. On a layer held as an overview of its file, such as a +large cloud-optimised GeoTIFF, they are the overview's unless the file stores its own, so a lone +cell of such a value may not show in them; Check DEM runs on the same cells and says when they are +an overview's. The values named may be real depths, as in a bathymetry such as GEBCO, which are +drawn as they are, or a no-data the file doesn't declare, such as −32768, which the relief draws as +cliffs. Check DEM (`checkDem`, see [Checking an elevation model](analysis.md#checking-an-elevation-model)) finds where they are, and `raster.mask` hides those that aren't terrain. A change of the relief's light, such as its azimuth or shadow, posts no notice again.