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
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/imagery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pub fn commands() -> Vec<C> {
C::new("raster.index", "Indices", "Imagery › Imagery Tools", index).inputs(raster_inputs).roles(&[]).effects(crate::policy::Effects::NONE).params(
r#"{"layer": raster, "index": "ndvi"|"ndwi"|"savi"|"nbr"|"ndbi"|"evi", "red"?, "green"?, "blue"?, "nir"?, "swir"?: band numbers, "name"?: output, "ran"?: (internal: a raster the app has worked out)}"#,
),
C::new("raster.process", "Process", "Imagery › Imagery Tools", process).inputs(process_inputs).roles(&[]).effects(crate::policy::Effects::NONE)
C::new("raster.process", "Process", "Analyze › Raster", process).inputs(process_inputs).roles(&[]).effects(crate::policy::Effects::NONE)
.params(r#"{"layer": raster, "operation": "clip"|"resample", "extent"?: [minLon, minLat, maxLon, maxLat] (clip; the view when omitted), "polygon"?: polygon layer (clip to its selected or all polygons; cells outside become no-data, or see-through in a raster with alpha or a three-band colour one without no-data), "selectedOnly"?: bool (clip to selected polygons when true, all when false), "factor"?: n (resample: n×n pixels become one), "name"?: output, "ran"?: (internal: a raster the app has worked out)}"#),
C::new("raster.mosaic", "Mosaic Rasters", "Imagery › Imagery Tools", raster_mosaic).inputs(mosaic_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).params(
C::new("raster.mosaic", "Mosaic Rasters", "Analyze › Raster", raster_mosaic).inputs(mosaic_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).params(
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
r#"{"inputs": [raster layer or file path, …] (two or more, in one coordinate system and cell size; where they overlap the first wins), "name"?: output, "path"?: GeoTIFF to write the mosaic to}"#,
),
C::new("raster.editPixels", "Pixel Editor", "Imagery › Imagery Tools", edit_pixels).inputs(raster_inputs).roles(&[]).effects(crate::policy::Effects::NONE)
Expand Down
20 changes: 17 additions & 3 deletions crates/engine/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub struct Extension {
}

/// Imagery: orthomosaics, surface models, georeferencing, image analysis and classification,
/// deep learning, mensuration and hosted imagery, on a tab of its own.
/// deep learning, mensuration and hosted imagery, on a tab of its own. Clip, resample, mosaic, project
/// and rasterize serve any raster, so no extension owns them (#2823).
pub const IMAGERY: Extension = Extension {
id: "imagery",
name: "Imagery",
Expand All @@ -55,8 +56,6 @@ pub const IMAGERY: Extension = Extension {
"raster.classify",
"raster.classifySupervised",
"raster.index",
"raster.process",
"raster.mosaic",
"raster.editPixels",
"raster.measure",
"raster.measurements",
Expand Down Expand Up @@ -241,6 +240,21 @@ mod tests {
assert!(chosen.is_on("imagery"));
}

/// Clip, resample, mosaic, project and rasterize serve any raster (#2823): no extension owns them.
#[test]
fn general_raster_commands_are_in_no_extension() {
let (apps, _) = State::from_setting(None);
let registry = crate::cmd::all();
for c in ["raster.process", "raster.mosaic", "raster.project", "raster.rasterize"] {
assert_eq!(owner(c).map(|e| e.id), None, "{c}");
assert_eq!(apps.blocks(c), None);
assert_eq!(registry.iter().find(|s| s.id == c).map(|s| s.location), Some("Analyze › Raster"), "{c}");
}
for c in IMAGERY.commands {
assert!(apps.blocks(c).is_some_and(|w| w.starts_with(c)), "{c}");
}
}

#[test]
fn defaults_choices_and_unknown_ids() {
let mut st = State::default();
Expand Down
80 changes: 80 additions & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20178,6 +20178,86 @@ fn plugin_mosaics_of_project_layers_need_no_files() {
rustgis_plugins::unload("eng-mosaic");
}

/// Clip, resample and mosaic run while the Imagery extension is off (#2823), whoever asks: the user,
/// a script, a saved task, or a plugin, which can't turn the extension on. Imagery's own commands
/// stay refused.
#[test]
fn clip_resample_and_mosaic_run_with_imagery_off() {
use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster, geotiff};
let mut s = world();
for (name, x0) in [("west", 0.0), ("east", 1.0)] {
let gt = GeoTransform { origin_x: x0, origin_y: 1.0, pixel_width: 0.1, pixel_height: -0.1 };
let r = Raster::new(name, 10, 10, vec![vec![1.0; 100]], gt, Crs::LonLat, None, ColorHint::Gray, "Float32").unwrap();
let bytes = geotiff::write(&r, 0).unwrap();
crate::cmd::raster::add_raster(&mut s, name, rustgis_map::RasterLayer::from_bytes(r, format!("{name}.tif"), bytes)).unwrap();
}
s.run("layer.template", &json!({"template": "polygons", "name": "Area"})).unwrap();
// Around the cell centres of 4 columns and 5 rows.
let ring = json!([[0.2, 0.3], [0.6, 0.3], [0.6, 0.8], [0.2, 0.8], [0.2, 0.3]]);
s.run("edit.addFeature", &json!({"layer": "Area", "geometry": {"type": "Polygon", "coordinates": [ring]}})).unwrap();
s.run("extension.disable", &json!({"id": "imagery"})).unwrap();

let commands = |by: &str| {
[
("raster.process", json!({"layer": "west", "operation": "clip", "polygon": "Area", "name": format!("{by} clip")})),
("raster.process", json!({"layer": "west", "operation": "resample", "factor": 2, "name": format!("{by} half")})),
("raster.mosaic", json!({"inputs": ["west", "east"], "name": format!("{by} both")})),
]
};
let check = |s: &Session, by: &str| {
for (kind, size, cells) in [("clip", (4, 5), 20), ("half", (5, 5), 25), ("both", (20, 10), 200)] {
let name = format!("{by} {kind}");
let layer = s.map().layer_by_name(&name).unwrap_or_else(|| panic!("no {name}"));
let r = layer.raster.as_ref().unwrap().data.as_ref().unwrap();
assert_eq!(((r.width, r.height), r.bands[0].stats.count), (size, cells), "{name}");
}
};
for (id, p) in commands("user") {
s.run(id, &p).unwrap();
}
check(&s, "user");
let script = commands("script").map(|(id, p)| format!("{id} {p}")).join("\n");
s.run("script.run", &json!({"script": script})).unwrap();
check(&s, "script");
let steps = commands("task").map(|(id, p)| json!({"title": id, "command": id, "params": p}));
s.run("task.new", &json!({"name": "Raster steps", "steps": steps})).unwrap();
s.run("task.run", &json!({"task": "Raster steps"})).unwrap();
check(&s, "task");
plugin("eng-imagery-off", &["edit"]);
for (id, p) in commands("plugin") {
forward(&mut s, "eng-imagery-off", id, p).unwrap();
}
check(&s, "plugin");
// As the desktop app runs clip and resample: worked out on a thread, landed, then added by the
// command. A mosaic has no such run.
#[cfg(not(target_arch = "wasm32"))]
{
use crate::cmd::workflows::{raster_land, raster_start};
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
for (id, p) in commands("app") {
if id == "raster.mosaic" {
s.run(id, &p).unwrap();
continue;
}
let run = raster_start(&mut s, id, &p).unwrap();
let ran = run.id;
let made = std::thread::spawn(move || run.run(&rustgis_analysis::control::Control::new())).join().unwrap().unwrap();
assert_eq!(raster_land(&mut s, ran, made), Ok(true));
s.finish_raster(id, ran, &p).unwrap();
}
check(&s, "app");
}

for id in ["raster.classify", "raster.index", "raster.change", "raster.editPixels"] {
let p = json!({"layer": "west"});
for e in [s.run(id, &p).unwrap_err(), forward(&mut s, "eng-imagery-off", id, p).unwrap_err()] {
assert!(e.contains("Imagery extension, which is off"), "{id}: {e}");
}
}
forward(&mut s, "eng-imagery-off", "extension.enable", json!({"id": "imagery"})).unwrap_err();
assert!(!s.extensions().is_on("imagery"), "a plugin can't turn it on");
rustgis_plugins::unload("eng-imagery-off");
}

#[test]
fn plugin_tile_layers_need_network() {
let mut s = world();
Expand Down
4 changes: 2 additions & 2 deletions crates/ui-egui/src/analysispane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ pub const SECTIONS: &[(&str, &str)] = &[
/// extension is off.
pub fn section_extension(section: &str) -> Option<&'static str> {
match section {
"georeference" | "change" | "spectral" | "classify" | "supervised" | "deepLearning" | "hosted" | "indices" | "process"
| "pixels" | "mensuration" | "ortho" | "reality" => Some(rustgis_engine::extensions::IMAGERY.id),
"georeference" | "change" | "spectral" | "classify" | "supervised" | "deepLearning" | "hosted" | "indices" | "pixels"
| "mensuration" | "ortho" | "reality" => Some(rustgis_engine::extensions::IMAGERY.id),
_ => None,
}
}
Expand Down
15 changes: 15 additions & 0 deletions crates/ui-egui/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,21 @@ pub fn notices(app: &mut RustGisApp, ctx: &egui::Context) {
mod tests {
use super::*;

/// A command and the Workflows section it opens are one extension's or no extension's, so
/// Command Search never offers a command whose section is refused, nor hides one whose isn't.
#[test]
fn a_command_and_its_workflows_section_are_in_one_extension() {
let app = RustGisApp::with_sample();
let mut seen = 0;
for c in &app.session.registry.commands {
let Some(SearchAction::Workflow(section)) = search_action(c.id) else { continue };
let owner = rustgis_engine::extensions::owner(c.id).map(|e| e.id);
assert_eq!(owner, crate::analysispane::section_extension(section), "{} and {section}", c.id);
seen += 1;
}
assert!(seen > 20, "{seen}");
}

#[test]
fn command_search_matches_localized_labels_and_locations() {
let app = RustGisApp::with_sample();
Expand Down
10 changes: 10 additions & 0 deletions crates/ui-egui/src/extensionsui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ mod tests {
assert!(crate::analysispane::section_shown(&app.session, "rasterFunctions"));
let why = app.run("raster.classify", json!({})).unwrap_err();
assert!(why.contains("Imagery extension, which is off"), "{why}");
// Clip and resample are no extension's (#2823).
app.run("ui.pane.workflows", json!({"section": "process"})).unwrap();
assert_eq!(app.workflow.section, "process");

// Saved with what a newer version wrote, and read again at the next start.
persist(&mut app);
Expand Down Expand Up @@ -251,6 +254,13 @@ mod tests {
assert_eq!(app.ui.tab, "Home");
assert!(said.contains("Imagery extension, which is off"), "{said}");
assert!(app.ui.show_me.is_none());
// Clip, resample and mosaic are Analyze's (#2823), with the extension off too.
for id in ["raster.process", "raster.mosaic"] {
app.run("ui.tab", json!({"tab": "Home"})).unwrap();
let said = crate::showme::start(&mut app, &step(id));
assert_eq!(app.ui.tab, "Analyze", "{said}");
assert!(app.ui.show_me.is_some(), "{said}");
}
}

#[test]
Expand Down
13 changes: 11 additions & 2 deletions crates/ui-egui/src/ribbon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ fn analysis_groups(app: &mut RustGisApp, ui: &mut Ui) {
let shown: Vec<&(&str, &str)> = crate::analysispane::SECTIONS
.iter()
.filter(|s| {
!matches!(s.0, "rasterFunctions" | "functionEditor" | "environments" | "models")
!matches!(s.0, "rasterFunctions" | "functionEditor" | "process" | "environments" | "models")
&& crate::analysispane::section_shown(&app.session, s.0)
})
.collect();
Expand Down Expand Up @@ -1889,6 +1889,16 @@ fn analysis_groups(app: &mut RustGisApp, ui: &mut Ui) {
json!({"section": "functionEditor"}),
false,
);
small(
ui,
app,
"resample",
"Process",
"Clip a raster to polygons or the view, or resample it.",
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
"ui.pane.workflows",
json!({"section": "process"}),
false,
);
});
});
group(ui, "Tools", |ui| {
Expand Down Expand Up @@ -4852,7 +4862,6 @@ fn imagery_groups(app: &mut RustGisApp, ui: &mut Ui) {
});
group(ui, "Imagery Tools", |ui| {
col(ui, |ui| {
small(ui, app, "resample", "Process", "Clip a raster to the view, or resample it.", "ui.pane.workflows", wf("process"), false);
small(ui, app, "stretch", "Indices", "NDVI, NDWI, SAVI, NBR, NDBI, EVI.", "ui.pane.workflows", wf("indices"), false);
small(ui, app, "edit", "Pixel Editor", "Set the pixels inside a polygon.", "ui.pane.workflows", wf("pixels"), false);
});
Expand Down
32 changes: 32 additions & 0 deletions crates/ui-egui/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,38 @@ fn polygon_clip_defaults_to_selection_and_honors_opt_out() {
assert_eq!(h.state().workflow.selected_only, Some(true));
}

/// Process (clip and resample) is on the Analyze tab and in the Workflows pane whether or not the
/// Imagery extension is on (#2823), and not on its tab.
#[test]
fn process_is_on_the_analyze_tab_with_imagery_off_and_on() {
for (on, command) in [(false, "extension.disable"), (true, "extension.enable")] {
let mut h = harness();
h.set_size(egui::vec2(2400.0, 860.0));
h.state_mut().run(command, json!({"id": "imagery"})).unwrap();
h.state_mut().run("ui.tab", json!({"tab": "Analyze"})).unwrap();
h.run_steps(4);
h.get_by_label("Process").click();
h.run_steps(4);
assert_eq!((h.state().workflow.section, h.state().ui.right), ("process", Some(rustgis_ui_egui::RightPane::Workflows)));
// The pane's list of sections.
let rows = |h: &egui_kittest::Harness<'_, RustGisApp>, label| h.query_all_by_label(label).count();
let (process, indices) = (rows(&h, "Process"), rows(&h, "Indices"));
h.query_all_by_role(egui::accesskit::Role::ComboBox).find(|n| n.value().as_deref() == Some("Process")).unwrap().click();
h.run_steps(4);
assert_eq!(rows(&h, "Process"), process + 1, "Imagery {on}");
assert_eq!(rows(&h, "Indices"), indices + usize::from(on), "Imagery {on}");
if on {
h.key_press(egui::Key::Escape);
h.run_steps(2);
h.state_mut().ui.right = None;
h.state_mut().run("ui.tab", json!({"tab": "extension:imagery"})).unwrap();
h.run_steps(4);
assert!(h.query_by_label("Pixel Editor").is_some());
assert!(h.query_by_label("Process").is_none(), "the button is on Analyze alone");
}
}
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
fn mcp_relay_early_start_wakes_queued_request_and_updates_ui() {
Expand Down
Loading
Loading