From 4be86263485869d5b9561cc72744c060b3aeb325 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 26 Nov 2026 14:56:02 -0300 Subject: [PATCH 1/5] feat(workflows): a Mosaic Rasters section that runs raster.mosaic on a thread (#2907) The Workflows pane's Mosaic Rasters section lists the rasters to join in order (layers, and on the desktop files not on the map), a name, and on the desktop a GeoTIFF to write or none. It runs through the pane's run, so the desktop app starts raster.mosaic on a thread of its own with its progress and Cancel in the pane (the path from #2936). It is listed in the Workflows menu, and Command Search now opens it instead of greying raster.mosaic. Closes #2907 Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/analysispane.rs | 203 +++++++++++++++++++++++++++++ crates/ui-egui/src/chrome.rs | 9 ++ docs/user-guide/analysis.md | 14 +- 3 files changed, 223 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index bddb2fe3f5..27946da236 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -95,6 +95,7 @@ pub struct Workflow { /// The cell size typed for the environment, apart from the Wizard's, which is the run's own. pub env_cell: String, pub zonal_stats: ZonalStatsForm, + pub mosaic: MosaicForm, /// A workflow running on a thread of its own: its progress and Cancel show, and what it made /// lands through [`land_job`]. #[cfg(not(target_arch = "wasm32"))] @@ -187,6 +188,20 @@ pub struct ZonalStatsForm { pub output: String, } +/// The Mosaic Rasters section's inputs (#2907). +#[derive(Default)] +pub struct MosaicForm { + /// The rasters to join, in order (the first with data wins where they overlap): a layer's name, + /// or a file's path (`true`), read as the mosaic runs and not added to the map. + pub inputs: Vec<(String, bool)>, + /// The layer Add puts at the end of the list. + pub add: String, + /// The result's name; empty: the command's own, the first input's with `_mosaic`. + pub name: String, + /// The GeoTIFF to write; empty: none. + pub path: String, +} + /// A Script pane run, as the line above its results tells it: its number since the project opened /// (so a run made again by mistake shows), how long it took and when it started (seconds since /// 1970; 0 for a clock that can't tell). Its lines' whole results, or why it didn't run, for its @@ -626,6 +641,7 @@ pub const SECTIONS: &[(&str, &str)] = &[ ("functionEditor", "Function Editor"), ("suitability", "Suitability Modeler"), ("zonalStats", "Zonal Statistics"), + ("mosaic", "Mosaic Rasters"), ("visibility", "Visibility Analysis"), ("lineOfSight", "Exploratory 3D Analysis"), ("interpolate", "Geostatistical Wizard"), @@ -937,6 +953,7 @@ pub fn workflows(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { run(app, "gp.zonalStats", params); } } + "mosaic" => mosaic_section(app, ui, &rasters), "visibility" => { heading(ui, "Viewshed from a point"); combo(ui, "wf_v", "Layer", &mut app.workflow.layer, &rasters); @@ -1628,6 +1645,104 @@ pub fn workflows(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } } +/// The Mosaic Rasters section (#2907): the rasters to join, in order, the result's name, and on the +/// desktop a GeoTIFF to write or none. There it runs on a thread of its own ([`run`]), its progress +/// and Cancel below. +fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { + heading(ui, "Join tiles of one grid into one raster"); + ui.label(egui::RichText::new(tl!("Where tiles overlap, the first in the list with data wins.")).small().weak()); + let m = &mut app.workflow.mosaic; + // A layer removed, or another project opened, leaves the list; a file stays. + m.inputs.retain(|(name, file)| *file || rasters.contains(name)); + let (count, mut change) = (m.inputs.len(), None); + for (i, (name, file)) in m.inputs.iter().enumerate() { + ui.horizontal(|ui| { + let shown = if *file { std::path::Path::new(name).file_name().and_then(|f| f.to_str()).unwrap_or(name) } else { name }; + ui.label(format!("{}. {shown}", i + 1)).on_hover_text(name.as_str()); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if ui.small_button("×").on_hover_text(tl!("Remove")).clicked() { + change = Some((i, None)); + } + if ui.add_enabled(i + 1 < count, egui::Button::new("↓").small()).on_hover_text(tl!("Move down")).clicked() { + change = Some((i, Some(i + 1))); + } + if ui.add_enabled(i > 0, egui::Button::new("↑").small()).on_hover_text(tl!("Move up")).clicked() { + change = Some((i, Some(i - 1))); + } + }); + }); + } + match change { + Some((i, Some(j))) => m.inputs.swap(i, j), + Some((i, None)) => drop(m.inputs.remove(i)), + None => {} + } + let left: Vec = rasters.iter().filter(|r| !m.inputs.iter().any(|(n, f)| !f && n == *r)).cloned().collect(); + if !left.contains(&m.add) { + m.add = left.first().cloned().unwrap_or_default(); + } + // Wrapped: Add File… goes below in a narrow pane rather than past its edge. + ui.horizontal_wrapped(|ui| { + combo(ui, "wf_mosaic_add", "Raster layer", &mut m.add, &left); + if ui.add_enabled(!m.add.is_empty(), egui::Button::new(tl!("Add"))).clicked() { + m.inputs.push((std::mem::take(&mut m.add), false)); + } + #[cfg(not(target_arch = "wasm32"))] + if ui.button(tl!("Add File…")).on_hover_text(tl!("A raster file, read as the mosaic runs: it isn't added to the map")).clicked() + && let Some(path) = crate::dialogs::pick_open(rustgis_engine::data::raster::READ_EXTENSIONS, tl!("Rasters")) + && !m.inputs.iter().any(|(n, f)| *f && *n == path) + { + m.inputs.push((path, true)); + } + }); + // The command's own name, unless one is typed: its first raster's (a layer renamed keeps its + // raster's name), or a file's name. + let map = app.session.map(); + let named = m.inputs.first().map_or_else(String::new, |(n, file)| { + let n = if *file { + std::path::Path::new(n).file_stem().and_then(|f| f.to_str()).unwrap_or(n) + } else { + map.layer_by_name(n).and_then(|l| l.raster.as_ref()?.data.as_ref()).map_or(n.as_str(), |r| r.name.as_str()) + }; + format!("{n}_mosaic") + }); + ui.horizontal(|ui| { + let label = ui.label(tl!("Name")); + ui.add(egui::TextEdit::singleline(&mut m.name).hint_text(named.as_str()).desired_width(160.0)).labelled_by(label.id); + }); + #[cfg(not(target_arch = "wasm32"))] + ui.horizontal(|ui| { + let label = ui.label(tl!("GeoTIFF")); + let shown = std::path::Path::new(&m.path).file_name().and_then(|f| f.to_str()).unwrap_or(&m.path); + if m.path.is_empty() { + ui.label(egui::RichText::new(tl!("None")).weak()); + } else { + ui.label(shown).on_hover_text(m.path.as_str()); + } + let file = format!("{}.tif", [m.name.trim(), &named].into_iter().find(|n| !n.is_empty()).unwrap_or("mosaic")); + if ui.button(tl!("Choose…")).on_hover_text(tl!("Write the mosaic to a GeoTIFF too")).labelled_by(label.id).clicked() + && let Some(path) = crate::dialogs::pick_save(&file, &["tif", "tiff"], tl!("GeoTIFF")) + { + m.path = path; + } + if !m.path.is_empty() && ui.small_button("×").on_hover_text(tl!("Write no file")).clicked() { + m.path.clear(); + } + }); + let ready = m.inputs.len() >= 2; + let button = ui.add_enabled(ready, egui::Button::new(tl!("Mosaic"))); + if button.on_disabled_hover_text(tl!("Add two or more rasters")).clicked() { + let mut p = json!({"inputs": m.inputs.iter().map(|(n, _)| n.as_str()).collect::>()}); + if !m.name.trim().is_empty() { + p["name"] = json!(m.name.trim()); + } + if !m.path.is_empty() { + p["path"] = json!(m.path); + } + run(app, "raster.mosaic", p); + } +} + /// Whether the catalog's cube `id` is a STAC collection, read where the map is (a Zarr variable is /// read whole). fn stac_cube(id: &str) -> bool { @@ -3624,6 +3739,91 @@ mod tests { std::fs::remove_dir_all(dir).unwrap(); } + /// The Mosaic Rasters section (#2907) joins its list in order on a thread of its own, from its + /// button: a layer and a file not on the map, named, written to a GeoTIFF. A layer gone from + /// the map leaves the list, and fewer than two inputs can't run. + #[cfg(not(target_arch = "wasm32"))] + #[test] + fn a_mosaic_from_its_section_runs_on_a_thread_and_lands() { + use base64::Engine; + use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster, geotiff}; + let dir = std::env::temp_dir().join(format!("rustgis-mosaic-pane-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + // 10 × 10 cells of one value; east starts half way across west. + let tile = |name: &str, x0: f64, v: f32| { + let gt = GeoTransform { origin_x: x0, origin_y: 1.0, pixel_width: 0.1, pixel_height: -0.1 }; + Raster::new(name, 10, 10, vec![vec![v; 100]], gt, Crs::LonLat, Some(-9999.0), ColorHint::Gray, "Float32").unwrap() + }; + let mut app = RustGisApp::with_sample(); + let data = base64::engine::general_purpose::STANDARD.encode(geotiff::write(&tile("west", 0.0, 1.0), 0).unwrap()); + app.session.run("layer.addDataBytes", &json!({"fileName": "west.tif", "data": data})).unwrap(); + let west = app.session.map().layers.iter().rev().find(|l| l.is_raster()).unwrap().name.clone(); + let east = dir.join("east.tif"); + std::fs::write(&east, geotiff::write(&tile("east", 0.5, 2.0), 0).unwrap()).unwrap(); + let out = dir.join("joined.tif"); + let layers = app.session.map().layers.len(); + app.workflow.section = "mosaic"; + let m = &mut app.workflow.mosaic; + m.inputs = vec![("gone".into(), false), (west.clone(), false), (east.display().to_string(), true)]; + m.name = "joined".into(); + m.path = out.display().to_string(); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(500.0, 900.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + workflows(app, ui, &Tokens::light()); + }, + app, + ); + h.run(); + assert_eq!(h.state().workflow.mosaic.inputs.len(), 2, "a layer gone from the map leaves the list"); + h.get_by_label("Mosaic").click(); + // A few frames, not until it settles: its spinner keeps drawing while it runs. + h.run_steps(2); + assert!(h.state().workflow.job.as_ref().is_some_and(|j| j.name == "Mosaic Rasters"), "{:?}", h.state().workflow.error); + let end = std::time::Instant::now() + std::time::Duration::from_secs(60); + while land_job(h.state_mut()) { + assert!(std::time::Instant::now() < end, "the run never landed"); + std::thread::sleep(std::time::Duration::from_millis(5)); // test-wait: polling for the mosaic to land + } + let app = h.state(); + assert!(app.workflow.error.is_none(), "{:?}", app.workflow.error); + // One layer more (east was read, not added), 15 cells across, west's cells where they overlap. + assert_eq!(app.session.map().layers.len(), layers + 1); + let r = app.session.map().layer_by_name("joined").and_then(|l| l.raster.as_ref()?.data.clone()).expect("the mosaic"); + assert_eq!((r.width, r.height), (15, 10)); + assert_eq!((r.bands[0].data[7], r.bands[0].data[12]), (1.0, 2.0)); + assert!(out.is_file()); + drop(h); + // With one input left, the button is off. + let mut app = RustGisApp::with_sample(); + app.workflow.section = "mosaic"; + app.workflow.mosaic.inputs = vec![(east.display().to_string(), true)]; + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(500.0, 900.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + workflows(app, ui, &Tokens::light()); + }, + app, + ); + h.run(); + h.get_by_label("Mosaic").click(); + h.run(); + assert!(h.state().workflow.job.is_none()); + drop(h); + std::fs::remove_dir_all(dir).unwrap(); + } + /// Interpolate runs on a thread of its own from the pane (#1291 step 3): the pane goes on while /// it works, a second run waits for the first, and its layer lands through its command, which /// Record Task takes without the raster it handed over (a replay works it out again). @@ -3747,6 +3947,9 @@ mod tests { assert!(h.query_by_role_and_label(egui::accesskit::Role::ComboBox, label).is_some()); } } + if section == "mosaic" { + assert!(h.query_by_role_and_label(egui::accesskit::Role::TextInput, "Name").is_some()); + } if section == "zonalStats" { for label in ["Band", "Prefix", "Output"] { assert!(h.query_by_role_and_label(egui::accesskit::Role::TextInput, label).is_some()); diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index ab4f70631f..e3f81192ef 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -1223,6 +1223,7 @@ fn search_action(id: &str) -> Option { "raster.process" => Workflow("process"), "raster.editPixels" => Workflow("pixels"), "raster.measure" => Workflow("mensuration"), + "raster.mosaic" => Workflow("mosaic"), "analysis.suitability" => Workflow("suitability"), "analysis.viewshed" => Workflow("visibility"), "analysis.lineOfSight" => Workflow("lineOfSight"), @@ -1936,6 +1937,14 @@ mod tests { assert!(super::search_disabled(&app, "layer.definitionQuery").is_none(), "offered for a feature layer"); } + /// Command Search's Mosaic Rasters opens its Workflows section (#2907) rather than being greyed + /// for the inputs it needs. + #[test] + fn mosaic_rasters_opens_its_section() { + assert!(matches!(search_action("raster.mosaic"), Some(SearchAction::Workflow("mosaic")))); + assert!(super::search_disabled(&RustGisApp::with_sample(), "raster.mosaic").is_none()); + } + /// Past the 200 notices the session keeps, each new notice it holds still makes one toast (#1755). #[test] fn each_kept_notice_makes_one_toast_past_the_200th() { diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index 4d200e285c..d38927e36c 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1613,6 +1613,7 @@ click them on the map: | Raster Functions | Slope in degrees or percent, aspect, hillshade (8-bit shades from 1 to 255, with 0 for no data), NDVI, band math (`(b4-b3)/(b4+b3)`), remapping, thresholds, resampling | | Function Editor | Chains raster functions, each on the previous output | | Process | Clips a raster to the view or to a polygon layer, or resamples it ([below](#zonal-statistics-and-polygon-clipping)) | +| Mosaic Rasters | Joins tiles of one grid into one raster, in the order listed, and can write it to a GeoTIFF ([under Imagery](#imagery)) | | Suitability Modeler | Scores rasters 1–10 and adds them with weights | | Visibility Analysis | A viewshed from a point on an elevation raster, with the Earth's curvature and the refraction of visible light (1/7, as `gdal_viewshed`). The ground along each ray is the cell each point falls in by default; `heights: "bilinear"` (**Ground heights › Between cells (bilinear)** in the Workflows pane) reads it between the cells' centres instead. Both are estimates of the ground between cell centres; between cells is closer on ground that bulges (a hill seen from its top), where the nearest cell can hide cells just inside the horizon. With no radius, or one longer than the raster's diagonal, the viewshed covers the whole raster. The map's **Viewshed N km Here** reads the ground as the Workflows pane's **Ground heights** says. On a raster round the whole Earth the rays don't cross its east–west edge, which the analysis says when the radius reaches it and the way across is shorter: the ground just across the edge is left out, worked out the long way round where the radius reaches the far edge through the raster too (always with no radius), or partly both, near the observer's row and not farther from it. The observer's height must be from 0 to 10,000 m. Ground with no data hides nothing, and next to it bilinear heights take the nearest cell's height; the analysis says how many cells this touched, in a notice. The answer gives both counts (0 when there is nothing to say): `acrossNoData` counts the visible cells whose rays crossed ground with no data (a hidden cell stays hidden whatever that ground is, so it isn't counted, and 0 doesn't mean no ray crossed any); `readNearest` counts every cell, visible or hidden, whose ray took a nearest height next to no data in bilinear mode | | Exploratory 3D Analysis | A line of sight between two points, split into seen and hidden parts, with the same curvature and refraction | @@ -2066,9 +2067,16 @@ commands described here aren't on the tab or part of the extension, and run whet EVI) and the **Pixel Editor** (set the pixels inside a polygon). - **Mosaic Rasters** (`raster.mosaic`) merges tiles of one grid, such as the 1 km tiles of a state elevation model, into one raster in their own coordinate system and cell size, optionally - written to a GeoTIFF: `{"inputs": ["dgm_1.tif", "dgm_2.tif", …], "path": "dem.tif"}`. It has no - pane yet: run it from the Script pane, the AI Assistant, the command line or Python. Inputs - are layers or file paths; where they overlap, the first one with data wins. Tiles in different + written to a GeoTIFF: `{"inputs": ["dgm_1.tif", "dgm_2.tif", …], "path": "dem.tif"}`. Inputs + are layers or file paths; where they overlap, the first one with data wins. Its section in the + Workflows pane (Analyze › Workflows, or Command Search) lists them in that order: **Add** puts a + raster layer at the end, **Add File…** a file read as the mosaic runs and not added to the map, + and ↑ and ↓ move one. **Name** is the new layer's (by default the first input's, with + `_mosaic`), and **GeoTIFF › Choose…** writes the file too (none by default). In the desktop app + it runs on a thread of its own, its progress and Cancel in the pane, and a GeoTIFF it writes + replaces the file only once it is done (Cancel leaves the file as it was). The web app's section + joins layers only. From the Script pane, the AI Assistant, the command line or Python it runs in + place. Tiles in different coordinate systems or cell sizes, or opened from an overview, are refused rather than quietly resampled, as are tiles whose cells don't line up; the mosaic has to fit in memory (120 million values, cells times bands, or more on a computer with more memory: see Environments). From d9b6589fa16a166ec08a0d4e47b8ea0a221a5ef2 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 26 Nov 2026 23:08:28 -0300 Subject: [PATCH 2/5] fix(workflows): another project opening empties the Mosaic list of its layers (#2907) The list's layers were dropped by name only, so a raster of the same name in the newly opened project kept its row and Mosaic joined that layer instead. The section now remembers the project its layers are from (Session::opened) and drops them, files kept, when another one opens. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/analysispane.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 27946da236..561b55d409 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -200,6 +200,8 @@ pub struct MosaicForm { pub name: String, /// The GeoTIFF to write; empty: none. pub path: String, + /// The project ([`rustgis_engine::Session::opened`]) the list's layers are from. + pub project: Option, } /// A Script pane run, as the line above its results tells it: its number since the project opened @@ -1651,8 +1653,14 @@ pub fn workflows(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { heading(ui, "Join tiles of one grid into one raster"); ui.label(egui::RichText::new(tl!("Where tiles overlap, the first in the list with data wins.")).small().weak()); + let opened = app.session.opened; let m = &mut app.workflow.mosaic; - // A layer removed, or another project opened, leaves the list; a file stays. + // Another project opened, however it came: the list's layers were the old project's, a + // same-named one too, so they leave it. A layer removed leaves it too. A file stays. + if m.project.is_some_and(|p| p != opened) { + m.inputs.retain(|(_, file)| *file); + } + m.project = Some(opened); m.inputs.retain(|(name, file)| *file || rasters.contains(name)); let (count, mut change) = (m.inputs.len(), None); for (i, (name, file)) in m.inputs.iter().enumerate() { @@ -3824,6 +3832,24 @@ mod tests { std::fs::remove_dir_all(dir).unwrap(); } + /// Another project opening leaves the Mosaic list's layers, a same-named one there too: they + /// were the old project's. Its files stay, as they are on no map. + #[test] + fn another_project_leaves_the_mosaic_list_layers() { + let mut app = RustGisApp::with_sample(); + app.workflow.mosaic.inputs = vec![("west".to_string(), false), ("tiles/east.tif".to_string(), true)]; + let rasters = ["west".to_string()]; + let ctx = egui::Context::default(); + let draw = |app: &mut RustGisApp| { + ctx.run_ui(egui::RawInput::default(), |ui| mosaic_section(app, ui, &rasters)).textures_delta.clear(); + }; + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs.len(), 2, "kept in its own project"); + app.session.run("project.new", &Value::Null).unwrap(); + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); + } + /// Interpolate runs on a thread of its own from the pane (#1291 step 3): the pane goes on while /// it works, a second run waits for the first, and its layer lands through its command, which /// Record Task takes without the raster it handed over (a replay works it out again). From 773fe2b593adcccfd5e376da9e02ab7b8c0c0025 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 26 Nov 2026 23:18:56 -0300 Subject: [PATCH 3/5] fix(workflows): the Mosaic list offers a name two layers share once, and says so (#2907) Commands find a raster by its name, case aside (layer_by_name), so with "DEM" listed the section offered "dem", which the mosaic read as "DEM" again. Names are now compared case aside, a name an earlier layer has is offered once, and the section says only the first can be joined. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/analysispane.rs | 32 +++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 561b55d409..c777ff1d3d 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -1685,7 +1685,18 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { Some((i, None)) => drop(m.inputs.remove(i)), None => {} } - let left: Vec = rasters.iter().filter(|r| !m.inputs.iter().any(|(n, f)| !f && n == *r)).cloned().collect(); + // Commands find a raster by its name, case aside (`layer_by_name`): a layer whose name a + // listed or an earlier one has would be read as that one, so it isn't offered, and the + // section says so. + let mut left: Vec = Vec::new(); + let mut shared = None; + for (i, r) in rasters.iter().enumerate() { + if rasters[..i].iter().any(|o| o.eq_ignore_ascii_case(r)) { + shared.get_or_insert(r); + } else if !m.inputs.iter().any(|(n, f)| !f && n.eq_ignore_ascii_case(r)) { + left.push(r.clone()); + } + } if !left.contains(&m.add) { m.add = left.first().cloned().unwrap_or_default(); } @@ -1703,6 +1714,13 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { m.inputs.push((path, true)); } }); + if let Some(name) = shared { + let text = crate::i18n::fmt( + "{name}: another layer has this name, so only the first can be joined: rename one of them", + &[("name", name.as_str())], + ); + ui.label(egui::RichText::new(text).small().weak()); + } // The command's own name, unless one is typed: its first raster's (a layer renamed keeps its // raster's name), or a file's name. let map = app.session.map(); @@ -3850,6 +3868,18 @@ mod tests { assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); } + /// Commands find a raster by its name, case aside: a layer whose name another listed one has + /// isn't offered, as it would be read as that one, and the section says so. + #[test] + fn a_name_two_layers_share_is_offered_once() { + let mut app = RustGisApp::with_sample(); + app.workflow.mosaic.inputs = vec![("DEM".to_string(), false)]; + let rasters = ["DEM".to_string(), "dem".to_string(), "west".to_string()]; + let ctx = egui::Context::default(); + ctx.run_ui(egui::RawInput::default(), |ui| mosaic_section(&mut app, ui, &rasters)).textures_delta.clear(); + assert_eq!(app.workflow.mosaic.add, "west", "\"dem\" would be read as \"DEM\""); + } + /// Interpolate runs on a thread of its own from the pane (#1291 step 3): the pane goes on while /// it works, a second run waits for the first, and its layer lands through its command, which /// Record Task takes without the raster it handed over (a replay works it out again). From 9ffa7fe5364fbffa4127dcdcb4b1c98b77301c1e Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Fri, 27 Nov 2026 00:36:26 -0300 Subject: [PATCH 4/5] fix(workflows): the Mosaic list follows the map shown, and leaves out rasters named as a vector layer (#2907) The list's layers stayed when another map of the project was shown, so a same-named raster there was joined instead; the list is now tied to the project and its active map. A raster named, case aside, as a vector layer before it was offered and then refused by the command (layer_by_name finds the vector layer); it is now left out with the shared-name notice. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/analysispane.rs | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index c777ff1d3d..7aba161616 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -200,8 +200,9 @@ pub struct MosaicForm { pub name: String, /// The GeoTIFF to write; empty: none. pub path: String, - /// The project ([`rustgis_engine::Session::opened`]) the list's layers are from. - pub project: Option, + /// The project ([`rustgis_engine::Session::opened`]) and the map in it the list's layers are + /// from. + pub project: Option<(u64, usize)>, } /// A Script pane run, as the line above its results tells it: its number since the project opened @@ -1653,10 +1654,11 @@ pub fn workflows(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { heading(ui, "Join tiles of one grid into one raster"); ui.label(egui::RichText::new(tl!("Where tiles overlap, the first in the list with data wins.")).small().weak()); - let opened = app.session.opened; + let opened = (app.session.opened, app.session.project.active_map); let m = &mut app.workflow.mosaic; - // Another project opened, however it came: the list's layers were the old project's, a - // same-named one too, so they leave it. A layer removed leaves it too. A file stays. + // Another project opened, however it came, or another map shown: the list's layers were the + // old map's, a same-named one too, so they leave it. A layer removed leaves it too. A file + // stays. if m.project.is_some_and(|p| p != opened) { m.inputs.retain(|(_, file)| *file); } @@ -1685,13 +1687,14 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { Some((i, None)) => drop(m.inputs.remove(i)), None => {} } - // Commands find a raster by its name, case aside (`layer_by_name`): a layer whose name a - // listed or an earlier one has would be read as that one, so it isn't offered, and the - // section says so. + // Commands find a layer by its name, case aside (`layer_by_name`), of any kind: a raster whose + // name a listed raster, an earlier one or a vector layer before it has would be read as that + // one, so it isn't offered, and the section says so. + let map = app.session.map(); let mut left: Vec = Vec::new(); let mut shared = None; for (i, r) in rasters.iter().enumerate() { - if rasters[..i].iter().any(|o| o.eq_ignore_ascii_case(r)) { + if rasters[..i].iter().any(|o| o.eq_ignore_ascii_case(r)) || map.layer_by_name(r).is_some_and(|l| !l.is_raster()) { shared.get_or_insert(r); } else if !m.inputs.iter().any(|(n, f)| !f && n.eq_ignore_ascii_case(r)) { left.push(r.clone()); @@ -1716,14 +1719,13 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { }); if let Some(name) = shared { let text = crate::i18n::fmt( - "{name}: another layer has this name, so only the first can be joined: rename one of them", + "{name}: another layer has this name, and the mosaic reads the first layer with it: rename one of them", &[("name", name.as_str())], ); ui.label(egui::RichText::new(text).small().weak()); } // The command's own name, unless one is typed: its first raster's (a layer renamed keeps its // raster's name), or a file's name. - let map = app.session.map(); let named = m.inputs.first().map_or_else(String::new, |(n, file)| { let n = if *file { std::path::Path::new(n).file_stem().and_then(|f| f.to_str()).unwrap_or(n) @@ -3850,8 +3852,8 @@ mod tests { std::fs::remove_dir_all(dir).unwrap(); } - /// Another project opening leaves the Mosaic list's layers, a same-named one there too: they - /// were the old project's. Its files stay, as they are on no map. + /// Another project opening, or another map shown, leaves the Mosaic list's layers, a + /// same-named one there too: they were the old map's. Its files stay, as they are on no map. #[test] fn another_project_leaves_the_mosaic_list_layers() { let mut app = RustGisApp::with_sample(); @@ -3866,6 +3868,13 @@ mod tests { app.session.run("project.new", &Value::Null).unwrap(); draw(&mut app); assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); + // Another map of the same project. + app.workflow.mosaic.inputs.insert(0, ("west".to_string(), false)); + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs.len(), 2, "kept on its own map"); + app.session.run("map.new", &json!({"name": "Other"})).unwrap(); + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); } /// Commands find a raster by its name, case aside: a layer whose name another listed one has @@ -3878,6 +3887,12 @@ mod tests { let ctx = egui::Context::default(); ctx.run_ui(egui::RawInput::default(), |ui| mosaic_section(&mut app, ui, &rasters)).textures_delta.clear(); assert_eq!(app.workflow.mosaic.add, "west", "\"dem\" would be read as \"DEM\""); + // A raster named as a vector layer before it ("Cities", case aside) is read as that one. + app.workflow.mosaic.inputs.clear(); + app.workflow.mosaic.add.clear(); + let rasters = ["cities".to_string(), "west".to_string()]; + ctx.run_ui(egui::RawInput::default(), |ui| mosaic_section(&mut app, ui, &rasters)).textures_delta.clear(); + assert_eq!(app.workflow.mosaic.add, "west", "\"cities\" would be read as the vector layer \"Cities\""); } /// Interpolate runs on a thread of its own from the pane (#1291 step 3): the pane goes on while From afcf7d23cc587225c8894d8316135ad3a29ddcf5 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Fri, 27 Nov 2026 08:00:15 -0300 Subject: [PATCH 5/5] fix(workflows): the Mosaic list knows its map by name, and waits while a listed name is shared (#2907) Deleting the map shown moved the next one to its index, so the list's layers stayed and a same-named raster there was joined; maps have names of their own, so the list is now tied to the shown map's name. A listed layer whose name another layer comes to have (renamed, or moved before it) would be read as the first one; Mosaic is now off until one is renamed, and the shared-name notice names it. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/analysispane.rs | 74 ++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 7aba161616..ee21eb77c6 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -201,8 +201,9 @@ pub struct MosaicForm { /// The GeoTIFF to write; empty: none. pub path: String, /// The project ([`rustgis_engine::Session::opened`]) and the map in it the list's layers are - /// from. - pub project: Option<(u64, usize)>, + /// from, by its name (a project's maps have names of their own, case aside, as commands find + /// them by it): a map's place changes when another one is deleted. + pub project: Option<(u64, String)>, } /// A Script pane run, as the line above its results tells it: its number since the project opened @@ -1654,12 +1655,12 @@ pub fn workflows(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { heading(ui, "Join tiles of one grid into one raster"); ui.label(egui::RichText::new(tl!("Where tiles overlap, the first in the list with data wins.")).small().weak()); - let opened = (app.session.opened, app.session.project.active_map); + let opened = (app.session.opened, app.session.map().name.to_ascii_lowercase()); let m = &mut app.workflow.mosaic; - // Another project opened, however it came, or another map shown: the list's layers were the - // old map's, a same-named one too, so they leave it. A layer removed leaves it too. A file - // stays. - if m.project.is_some_and(|p| p != opened) { + // Another project opened, however it came, or another map shown (the one shown deleted, or + // renamed, too): the list's layers were the old map's, a same-named one too, so they leave + // it. A layer removed leaves it too. A file stays. + if m.project.as_ref().is_some_and(|p| *p != opened) { m.inputs.retain(|(_, file)| *file); } m.project = Some(opened); @@ -1717,7 +1718,14 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { m.inputs.push((path, true)); } }); - if let Some(name) = shared { + // A listed layer whose name another layer has too (renamed, or moved before it, since it was + // added) can't be told apart by the command, which reads the first: Mosaic waits for a rename. + let clash = m + .inputs + .iter() + .find(|(n, file)| !file && map.layers.iter().filter(|l| l.name.eq_ignore_ascii_case(n)).count() > 1) + .map(|(n, _)| n.clone()); + if let Some(name) = clash.as_ref().or(shared) { let text = crate::i18n::fmt( "{name}: another layer has this name, and the mosaic reads the first layer with it: rename one of them", &[("name", name.as_str())], @@ -1757,9 +1765,11 @@ fn mosaic_section(app: &mut RustGisApp, ui: &mut Ui, rasters: &[String]) { m.path.clear(); } }); - let ready = m.inputs.len() >= 2; + let ready = m.inputs.len() >= 2 && clash.is_none(); let button = ui.add_enabled(ready, egui::Button::new(tl!("Mosaic"))); - if button.on_disabled_hover_text(tl!("Add two or more rasters")).clicked() { + let why = + if clash.is_some() { tl!("Another layer has a listed layer's name: rename one of them") } else { tl!("Add two or more rasters") }; + if button.on_disabled_hover_text(why).clicked() { let mut p = json!({"inputs": m.inputs.iter().map(|(n, _)| n.as_str()).collect::>()}); if !m.name.trim().is_empty() { p["name"] = json!(m.name.trim()); @@ -3875,6 +3885,17 @@ mod tests { app.session.run("map.new", &json!({"name": "Other"})).unwrap(); draw(&mut app); assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); + // The map shown deleted: the next one takes its place (index 0) and is another map. + let first = app.session.project.maps[0].name.clone(); + app.session.run("map.activate", &json!({"name": first})).unwrap(); + draw(&mut app); + app.workflow.mosaic.inputs.insert(0, ("west".to_string(), false)); + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs.len(), 2, "kept on its own map"); + app.session.run("map.remove", &json!({"name": first})).unwrap(); + assert_eq!(app.session.project.active_map, 0); + draw(&mut app); + assert_eq!(app.workflow.mosaic.inputs, vec![("tiles/east.tif".to_string(), true)]); } /// Commands find a raster by its name, case aside: a layer whose name another listed one has @@ -3895,6 +3916,39 @@ mod tests { assert_eq!(app.workflow.mosaic.add, "west", "\"cities\" would be read as the vector layer \"Cities\""); } + /// A listed layer whose name another layer comes to have (renamed, or moved before it) can't be + /// told apart by the command, so Mosaic waits until one of them is renamed. + #[test] + fn a_listed_name_another_layer_comes_to_share_holds_the_mosaic() { + let mut app = RustGisApp::with_sample(); + let (listed, other) = { + let layers = &app.session.map().layers; + (layers[0].name.clone(), layers[1].id) + }; + app.workflow.mosaic.inputs = vec![(listed.clone(), false), ("tiles/east.tif".to_string(), true)]; + let rasters = [listed.clone()]; + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(500.0, 600.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + mosaic_section(app, ui, &rasters); + }, + app, + ); + h.run(); + let off = |h: &egui_kittest::Harness<'_, RustGisApp>| { + egui_kittest::kittest::NodeT::accesskit_node(&h.get_by_label("Mosaic")).is_disabled() + }; + assert!(!off(&h), "two inputs, each its own"); + h.state_mut().session.run("layer.rename", &json!({"layer": other, "name": listed.to_lowercase()})).unwrap(); + h.run(); + assert!(off(&h), "{listed} is now two layers' name"); + } + /// Interpolate runs on a thread of its own from the pane (#1291 step 3): the pane goes on while /// it works, a second run waits for the first, and its layer lands through its command, which /// Record Task takes without the raster it handed over (a replay works it out again).