Skip to content
Merged
Show file tree
Hide file tree
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
98 changes: 92 additions & 6 deletions crates/ui-egui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustgis_engine::analysis::{ParamKind, tools};
use rustgis_engine::cmd::layer::hidden_fill_opacity;
use rustgis_engine::data::GeometryType;
use rustgis_engine::map::fills::FillLayer;
use rustgis_engine::map::raster::{Flats, Normalizer, RasterLegend, RasterStyle, Rock, relief_ambient};
use rustgis_engine::map::raster::{Flats, GENERALIZE_MAX, Normalizer, RasterLegend, RasterStyle, Rock, relief_ambient};
use rustgis_engine::map::symbology::{
ClassRef, ClassStyle, Dash, LegendEntry, LineCap, LineJoin, LineMark, LineMarkers, LineStroke, MAX_EXPRESSION_CLASSES, MAX_LABEL,
MAX_LINE_MARKER_SIZE, MAX_MARKER_INTERVAL, MAX_STROKE_OFFSET, MAX_STROKE_WIDTH, MAX_STROKES, MIN_MARKER_INTERVAL, OPEN_ABOVE,
Expand Down Expand Up @@ -7734,8 +7734,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) {
aerial,
terrain_type,
flats,
// Its pane field comes with #3145's last part.
generalize: _,
generalize,
} => {
use rustgis_engine::map::shadow::{SOFT_EDGE_MAX, SOFT_EDGE_MIN, soft_edge};
let (az, alt, zf, sh, sk, fl) = (*azimuth, *altitude, *z_factor, *shadow, *sky, *fill);
Expand Down Expand Up @@ -7770,17 +7769,18 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) {
("Terrain type", tt, -1.0..=1.0, 0.01, 9),
("Flat-area detail", flats.map_or(0.0, |f| f.amount), 0.0..=1.0, 0.01, 10),
];
// Its neighbourhood, once it is on.
// Its neighbourhood, once it is on, right below it.
if let Some(f) = flats {
rows.push(("Flat-area size", f64::from(f.size), 1.0..=f64::from(Flats::MAX_SIZE), 1.0, 11));
}
rows.push(("Generalise", *generalize, 0.0..=GENERALIZE_MAX, 1.0, 12));
for (label, v, range, speed, which) in rows {
let input_label = ui.label(tl!(label));
let mut x = v;
// Kept across a drag until it is let go (#607).
let drag = Dragged::lend(ui, egui::Id::unique(("relief_drag", l.id, which)), &mut x);
let r = ui
.add(egui::DragValue::new(&mut x).update_while_editing(false).range(range).speed(speed).max_decimals(3))
.add(egui::DragValue::new(&mut x).update_while_editing(false).range(range.clone()).speed(speed).max_decimals(3))
.labelled_by(input_label.id);
let r = match which {
3 => r.on_hover_text(tl!("How dark the shadows the terrain casts are, from 0 (none) to 1, for the sun set above")),
Expand All @@ -7804,9 +7804,16 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) {
"Levees, terraces and shallow channels on ground flatter than 4°, lit by their height above the ground around them, from 0 (none) to 1"
)),
11 => r.on_hover_text(tl!("How many cells around each cell its height is compared with, from 1 to 32")),
12 => r.on_hover_text(tl!(
"Lights the relief from its heights smoothed over this many metres, so gullies fade and valleys and ranges stay; the colours keep each cell's height. 0 (none) to 10 000"
)),
_ => r,
};
if drag.settled(ui, &r, &mut x) && x != v {
let settled = drag.settled(ui, &r, &mut x);
// egui adds an arrow key's step after it clamps to the range: kept in it here,
// so a step past an end sends the end, not a value the command refuses.
let x = x.clamp(*range.start(), *range.end());
if settled && x != v {
let (a, b, c, d) = match which {
0 => (x, alt, zf, sh),
1 => (az, x, zf, sh),
Expand All @@ -7824,6 +7831,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) {
9 => p["terrain"] = json!(x),
10 => p["flats"] = if x > 0.0 { json!({"amount": x}) } else { json!(false) },
11 => p["flats"] = json!({"size": x.round()}),
12 => p["generalize"] = json!(x),
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
_ => {}
}
let _ = app.run("raster.symbology", p);
Expand Down Expand Up @@ -10751,6 +10759,84 @@ pub(crate) mod tests {
assert_eq!(h.state().dialogs.text, "Rivers");
}

/// A Shaded Relief's style pane sets its generalisation (#3145), in metres: a size smooths the
/// heights its light reads, 0 turns it off again, and the field goes no further than the
/// command takes. It comes after flat ground's detail and its size, which stay together.
#[test]
fn the_relief_pane_sets_its_generalisation() {
use egui::accesskit::{Action, ActionData, ActionRequest, Role};
use egui_kittest::kittest::{NodeT, Queryable};
use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster};
let mut app = RustGisApp::with_sample();
let gt = GeoTransform { origin_x: 0.0, origin_y: 1.0, pixel_width: 0.5, pixel_height: -0.5 };
let r = Raster::new("dem", 2, 2, vec![vec![0.0, 1.0, 2.0, 3.0]], gt, Crs::LonLat, None, ColorHint::Gray, "Float32").unwrap();
let id = app.session.map_mut().add_raster("dem", rustgis_engine::map::RasterLayer::from_path(r, "dem.tif"));
app.session.active_layer = Some(id);
app.run("raster.symbology", json!({"layer": id, "type": "shadedRelief"})).unwrap();
let mut fonts = false;
let mut h = egui_kittest::Harness::builder().with_size(vec2(420.0, 900.0)).build_ui_state(
move |ui, app: &mut RustGisApp| {
if !fonts {
crate::theme::install_fonts(ui.ctx(), &[], None);
fonts = true;
return;
}
let layer = app.session.map().layer(id).unwrap().clone();
raster_symbology(app, ui, &layer, &Tokens::light());
},
app,
);
h.run_steps(3);
let generalize = |h: &egui_kittest::Harness<'_, RustGisApp>| match h.state().session.map().layer(id).and_then(|l| l.raster.as_ref())
{
Some(rl) => match rl.style.renderer {
RasterRenderer::ShadedRelief { generalize, .. } => generalize,
ref other => panic!("{other:?}"),
},
None => panic!("no raster"),
};
let set_field = |h: &mut egui_kittest::Harness<'_, RustGisApp>, label: &str, value: f64| {
let (node, tree) = h.get_by_role_and_label(Role::SpinButton, label).accesskit_node().locate();
h.event(egui::Event::AccessKitActionRequest(ActionRequest {
action: Action::SetValue,
target_tree: tree,
target_node: node,
data: Some(ActionData::NumericValue(value)),
}));
h.run_steps(3);
};
let set = |h: &mut egui_kittest::Harness<'_, RustGisApp>, value: f64| set_field(h, "Generalise", value);
assert_eq!(generalize(&h), 0.0);
set(&mut h, 120.0);
assert_eq!(generalize(&h), 120.0);
set(&mut h, 25_000.0);
assert_eq!(generalize(&h), rustgis_engine::map::raster::GENERALIZE_MAX, "no further than the command takes");
set(&mut h, 0.0);
assert_eq!(generalize(&h), 0.0);
// A step of the arrow keys stays in the range: egui clamps before it adds the step (and
// rounds to it), so 0.2 less a metre would ask for -1, which the command refuses.
let step = |h: &mut egui_kittest::Harness<'_, RustGisApp>, action: Action| {
let (node, tree) = h.get_by_role_and_label(Role::SpinButton, "Generalise").accesskit_node().locate();
h.event(egui::Event::AccessKitActionRequest(ActionRequest { action, target_tree: tree, target_node: node, data: None }));
h.run_steps(3);
};
for (from, action, to) in [
(0.2, Action::Decrement, 0.0),
(rustgis_engine::map::raster::GENERALIZE_MAX - 0.4, Action::Increment, rustgis_engine::map::raster::GENERALIZE_MAX),
] {
set(&mut h, from);
assert_eq!(generalize(&h), from);
step(&mut h, action);
assert_eq!(generalize(&h), to, "{action:?} from {from}");
}
set(&mut h, 0.0);
// Flat ground's detail turned on shows its size right below it, then Generalise.
set_field(&mut h, "Flat-area detail", 0.5);
let top = |h: &egui_kittest::Harness<'_, RustGisApp>, label: &str| h.get_by_role_and_label(Role::SpinButton, label).rect().min.y;
let (detail, size, generalise) = (top(&h, "Flat-area detail"), top(&h, "Flat-area size"), top(&h, "Generalise"));
assert!(detail < size && size < generalise, "{detail} {size} {generalise}");
}

/// A Shaded Relief's style pane sets its flat-area detail (#3143): an amount turns it on, with
/// the default size, and shows its size, which is set in whole cells; 0 turns it off again.
#[test]
Expand Down
13 changes: 13 additions & 0 deletions docs/user-guide/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,19 @@ fields, roads and embankments are heights too and show up as relief. In a script
and 6), and `false`, `null` or an amount of 0 removes it; an amount outside 0 to 1 or a size that
isn't a whole number from 1 to 32 is refused. It is saved with the project only when set.

**Generalise**, on a Shaded Relief layer (`raster.symbology` `"generalize"`, in metres, 0 to
10 000), generalises the relief for a smaller scale without a filtered copy of the DEM: the light,
the fill light, rock, cast shadows and the sky are worked out from the heights smoothed with a
Gaussian of that size, so gullies fade and the valleys and ranges stay. The colour ramp keeps each
cell's own height, so hypsometric tints don't move. About two to four cells' worth suits a map at
1:100,000 of a 30 m DEM (60 to 120 m); 0, the default, lights every landform as before. The size is
on the ground, so it means the same at any cell size and zoom. A GeoTIFF read in place reads past
the view as far as the smoothing reaches; when that is more than can be read at the resolution the
view needs (a fine DEM at a large size), the view's edges are smoothed from fewer cells and that is
said, and an export refuses it: a smaller size or view draws it whole. A value outside 0 to 10 000
in a file written by hand is set to the nearest and said as it opens. In a script,
`"generalize": 90` sets it, and `null` or 0 removes it.

With **Resampling** set to bilinear, a Shaded Relief layer's light (its hillshade, cast shadows,
sky visibility and fill light) and its rock tint are blended between the cells' centres, as its
values are, so a cell drawn over many pixels shades smoothly instead of in squares; nearest keeps
Expand Down
Loading