Repository navigation
fix(raster): a large local tiled GeoTIFF is read in place, drawn at the level the view needs (#2761) #2772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(raster): a large local tiled GeoTIFF is read in place, drawn at the level the view needs (#2761) #2772
Changes from 4 commits
3089345
117eda9
5719e77
dc10b31
d0fee2f
cf9aaf4
8fa9312
cb2550b
61948da
d3042fc
2455625
8437e3b
c4278f3
d110c71
6927237
76a7672
2c1d10f
628fb51
ad7a034
3b4f70c
36a1f06
037f7d7
019fd96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -395,7 +395,7 @@ pub fn external_start(s: &mut Session, tool: &str, params: &Value) -> Result<Ext | |||||||||||||||
| return Err(format!("no GeoLibre tool '{tool}'")); | ||||||||||||||||
| } | ||||||||||||||||
| let params = params.clone(); | ||||||||||||||||
| let job = preparing(&continuation, || pin.prepare_suite(&map_inputs(s, Some(spec), ¶ms)?, ¶ms))?; | ||||||||||||||||
| let job = preparing(&continuation, || pin.prepare_suite(&map_inputs(s, Some(spec), ¶ms, Tiled::ByPath)?, ¶ms))?; | ||||||||||||||||
| s.next_pending = s.next_pending.wrapping_add(1); | ||||||||||||||||
| let id = s.next_pending; | ||||||||||||||||
| let run = ExternalRun { | ||||||||||||||||
|
|
@@ -534,14 +534,19 @@ pub fn plugin_start(s: &mut Session, tool: &str, params: &Value) -> Result<Plugi | |||||||||||||||
| let spec = pin.spec(); | ||||||||||||||||
| let plugin = pin.plugin().ok_or_else(|| format!("no plugin tool '{tool}'"))?; | ||||||||||||||||
| let (_, tid) = rustgis_plugins::split_id(spec.id).ok_or("invalid plugin tool id")?; | ||||||||||||||||
| let (job, full_ids) = preparing(&continuation, || { | ||||||||||||||||
| let inputs = map_inputs(s, Some(spec), resolved)?; | ||||||||||||||||
| let (job, full_ids, said) = preparing(&continuation, || { | ||||||||||||||||
| let inputs = map_inputs(s, Some(spec), resolved, Tiled::Overview)?; | ||||||||||||||||
| let job = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { | ||||||||||||||||
| rustgis_plugins::tools::prepare_pinned(plugin.plugin(), tid, &inputs, resolved) | ||||||||||||||||
| })) | ||||||||||||||||
| .unwrap_or_else(|_| Err(format!("{} failed unexpectedly", spec.name)))?; | ||||||||||||||||
| Ok((job, full_ids(&inputs.loaded))) | ||||||||||||||||
| Ok((job, full_ids(&inputs.loaded), inputs.messages.clone())) | ||||||||||||||||
| })?; | ||||||||||||||||
| // What reading its inputs approximated (a raster's overview read for a file read in place), | ||||||||||||||||
| // said now: the run's result is the plugin's own. | ||||||||||||||||
| for m in said { | ||||||||||||||||
| s.notify(format!("{}: {m}", spec.name), false); | ||||||||||||||||
| } | ||||||||||||||||
| let read = read_layers(s, spec, resolved); | ||||||||||||||||
| s.next_pending = s.next_pending.wrapping_add(1); | ||||||||||||||||
| let id = s.next_pending; | ||||||||||||||||
|
|
@@ -710,7 +715,7 @@ impl ToolRun { | |||||||||||||||
| // A bug in reading the inputs, like one in a tool, must not take the app down. | ||||||||||||||||
| let mut done = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { | ||||||||||||||||
| crate::render::rustgis_tiles::cache::with_still(still, || { | ||||||||||||||||
| let inputs = match inputs_of(snap, Some(spec), ¶ms) { | ||||||||||||||||
| let inputs = match inputs_of(snap, Some(spec), ¶ms, Tiled::File) { | ||||||||||||||||
| Ok(inputs) => inputs, | ||||||||||||||||
| // A Cancel while the inputs are read names the tool, as one while it runs does. | ||||||||||||||||
| Err(_) if control.is_cancelled() => { | ||||||||||||||||
|
|
@@ -1309,6 +1314,9 @@ struct MapInputs<'a> { | |||||||||||||||
| /// Import warnings from local file inputs, kept in the tool result and history. | ||||||||||||||||
| messages: Vec<String>, | ||||||||||||||||
| losses: Vec<LossMessage>, | ||||||||||||||||
| /// Raster layers read in place from a file on this computer, read again from it for the run | ||||||||||||||||
| /// ([`tiled_inputs`]), by lowercase name. | ||||||||||||||||
| rasters: std::collections::HashMap<String, std::sync::Arc<rustgis_data::raster::Raster>>, | ||||||||||||||||
| /// The flat map's projection (its name, the projection and its unit in metres), built the | ||||||||||||||||
| /// first time a tool asks for it (Tissot's indicatrix does), once for the run; `None` on the | ||||||||||||||||
| /// globe. | ||||||||||||||||
|
|
@@ -1363,14 +1371,40 @@ impl MapInputs<'_> { | |||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn map_inputs<'a>(s: &'a Session, spec: Option<&rustgis_analysis::ToolSpec>, params: &Value) -> Result<MapInputs<'a>, String> { | ||||||||||||||||
| inputs_of(Snapshot::of(s), spec, params) | ||||||||||||||||
| /// How a tool's inputs read a raster layer read in place from a file on this computer | ||||||||||||||||
| /// ([`rustgis_map::raster::RasterLayer::tiled`]). | ||||||||||||||||
| #[derive(Clone, Copy, PartialEq, Eq)] | ||||||||||||||||
| pub(crate) enum Tiled { | ||||||||||||||||
| /// From the file, at the finest level the run can hold ([`tiled_inputs`]): a built-in tool's | ||||||||||||||||
| /// run, on its own thread or where the caller waits. | ||||||||||||||||
| File, | ||||||||||||||||
| /// The overview the layer holds, said: a plugin's run, whose inputs are read on the app's | ||||||||||||||||
| /// thread. | ||||||||||||||||
| Overview, | ||||||||||||||||
| /// By its path: a suite tool stages the file itself. | ||||||||||||||||
| ByPath, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// [`inputs_of`] from the session as it is; `tiled` as there. | ||||||||||||||||
| fn map_inputs<'a>( | ||||||||||||||||
| s: &'a Session, | ||||||||||||||||
| spec: Option<&rustgis_analysis::ToolSpec>, | ||||||||||||||||
| params: &Value, | ||||||||||||||||
| tiled: Tiled, | ||||||||||||||||
| ) -> Result<MapInputs<'a>, String> { | ||||||||||||||||
| inputs_of(Snapshot::of(s), spec, params, tiled) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// A tool's inputs from what it read of the session: the streamed layers and files it names read | ||||||||||||||||
| /// whole, and the rows of each layer it runs on. It reads, so a background run does this on its | ||||||||||||||||
| /// thread. | ||||||||||||||||
| fn inputs_of<'a>(snap: Snapshot<'a>, spec: Option<&rustgis_analysis::ToolSpec>, params: &Value) -> Result<MapInputs<'a>, String> { | ||||||||||||||||
| /// thread. `tiled` says how the raster layers it reads that are read in place from a file on this | ||||||||||||||||
| /// computer are read ([`Tiled`]). | ||||||||||||||||
| fn inputs_of<'a>( | ||||||||||||||||
| snap: Snapshot<'a>, | ||||||||||||||||
| spec: Option<&rustgis_analysis::ToolSpec>, | ||||||||||||||||
| params: &Value, | ||||||||||||||||
| tiled: Tiled, | ||||||||||||||||
| ) -> Result<MapInputs<'a>, String> { | ||||||||||||||||
| let (full, said) = streamed_inputs(&snap.map, spec, params)?; | ||||||||||||||||
| let (mut messages, mut losses) = (Vec::new(), Vec::new()); | ||||||||||||||||
| for m in said { | ||||||||||||||||
|
|
@@ -1401,6 +1435,13 @@ fn inputs_of<'a>(snap: Snapshot<'a>, spec: Option<&rustgis_analysis::ToolSpec>, | |||||||||||||||
| let mut rows = env_inputs(&snap.map, &full, &snap.env, params)?; | ||||||||||||||||
| narrow_to_queries(&snap.map, spec, params, &full, &mut rows, &mut messages)?; | ||||||||||||||||
| let unread = if work == Crs::LonLat { std::collections::HashSet::new() } else { attributes_only(spec, params) }; | ||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| let rasters = tiled_inputs(&snap.map, spec, params, tiled, &mut messages)?; | ||||||||||||||||
| #[cfg(target_arch = "wasm32")] | ||||||||||||||||
| let rasters = { | ||||||||||||||||
| let _ = tiled; | ||||||||||||||||
| std::collections::HashMap::new() | ||||||||||||||||
| }; | ||||||||||||||||
| Ok(MapInputs { | ||||||||||||||||
| snap, | ||||||||||||||||
| rows, | ||||||||||||||||
|
|
@@ -1409,11 +1450,143 @@ fn inputs_of<'a>(snap: Snapshot<'a>, spec: Option<&rustgis_analysis::ToolSpec>, | |||||||||||||||
| unread, | ||||||||||||||||
| messages, | ||||||||||||||||
| losses, | ||||||||||||||||
| rasters, | ||||||||||||||||
| flat: std::cell::OnceCell::new(), | ||||||||||||||||
| view: std::cell::OnceCell::new(), | ||||||||||||||||
| }) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// The raster layers `spec`'s parameters name that are read in place from a file on this | ||||||||||||||||
| /// computer ([`rustgis_map::raster::RasterLayer::tiled`]), each read again from the file for the | ||||||||||||||||
| /// run, by lowercase name: such a layer holds only the small overview the map draws from zoomed | ||||||||||||||||
| /// out, and a tool reads the finest level of the file it can hold, the full image when it fits | ||||||||||||||||
| /// (#2761). Read on the run's thread; one read from an overview is said. The GeoTIFF reader looks | ||||||||||||||||
| /// at Cancel between its chunks through the progress probe, which a run from [`tool_start`] | ||||||||||||||||
| /// installs before reading its inputs; a run made where the caller waits stops there only when | ||||||||||||||||
| /// the caller installed one, else after the read. | ||||||||||||||||
| /// Read only for [`Tiled::File`]: for [`Tiled::Overview`] each such layer's held overview is said, | ||||||||||||||||
| /// and for [`Tiled::ByPath`] nothing is read or said. | ||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| pub(crate) fn tiled_inputs( | ||||||||||||||||
| map: &rustgis_map::Map, | ||||||||||||||||
| spec: Option<&rustgis_analysis::ToolSpec>, | ||||||||||||||||
| params: &Value, | ||||||||||||||||
| tiled: Tiled, | ||||||||||||||||
| messages: &mut Vec<String>, | ||||||||||||||||
| ) -> Result<std::collections::HashMap<String, std::sync::Arc<rustgis_data::raster::Raster>>, String> { | ||||||||||||||||
| use rustgis_analysis::ParamKind; | ||||||||||||||||
| let mut read = std::collections::HashMap::new(); | ||||||||||||||||
| // Raster to PMTiles draws its input as the map does, in place at each zoom's level, and | ||||||||||||||||
| // reads no pixels through the run's inputs. | ||||||||||||||||
| let Some(spec) = spec.filter(|t| tiled != Tiled::ByPath && t.id != "rasterToPmtiles") else { return Ok(read) }; | ||||||||||||||||
| let mut seen = std::collections::HashSet::new(); | ||||||||||||||||
| for parameter in spec.params { | ||||||||||||||||
| let value = params.get(parameter.name).unwrap_or(&Value::Null); | ||||||||||||||||
| let names: Vec<&str> = match parameter.kind { | ||||||||||||||||
| ParamKind::RasterLayer => value.as_str().into_iter().collect(), | ||||||||||||||||
| ParamKind::RasterLayers => rustgis_analysis::layer_list(value).unwrap_or_default(), | ||||||||||||||||
| _ => continue, | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ByPath refusal only covers raster-kinded parameters, so a GeoLibre file/other-kinded parameter can still stage the held overview silently.
Failure: a tiled layer whose file was moved, named in a GeoLibre tool parameter declared as a file. The tool runs on the overview and reports success. Fix: in Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 019fd96. In |
||||||||||||||||
| }; | ||||||||||||||||
| for name in names { | ||||||||||||||||
| let Some(l) = map.layer_by_name(name) else { continue }; | ||||||||||||||||
| let key = l.name.to_ascii_lowercase(); | ||||||||||||||||
| let Some(path) = l.raster.as_ref().filter(|rl| rl.tiled).and_then(|rl| rl.path.as_deref()) else { continue }; | ||||||||||||||||
| if !seen.insert(key.clone()) { | ||||||||||||||||
| continue; | ||||||||||||||||
| } | ||||||||||||||||
| if tiled == Tiled::Overview { | ||||||||||||||||
| if let Some(held) = l.raster.as_ref().and_then(|rl| rl.data.as_ref()) | ||||||||||||||||
| && let Some((fw, fh)) = held.overview | ||||||||||||||||
| { | ||||||||||||||||
| messages.push(format!( | ||||||||||||||||
| "{}: read at the {} × {} overview of the {fw} × {fh} raster the layer holds, as plugin tools don't read a raster read in place from its file", | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pushes one message per tiled layer a plugin names. Confidence: medium. The join in Category: agents-md
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 36a1f06. |
||||||||||||||||
| l.name, held.width, held.height | ||||||||||||||||
| )); | ||||||||||||||||
| } | ||||||||||||||||
| continue; | ||||||||||||||||
| } | ||||||||||||||||
| let r = match BATCH_READS.with(|b| b.borrow().as_ref().and_then(|reads| reads.get(path).cloned())) { | ||||||||||||||||
| Some(r) => r, | ||||||||||||||||
| None => { | ||||||||||||||||
| #[cfg(test)] | ||||||||||||||||
| TILED_READS.with(|n| n.set(n.get() + 1)); | ||||||||||||||||
| let r = std::sync::Arc::new( | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The batch's kept raster is uncounted while the next file decodes, so two decodes can be planned as if there were one. This re-raises the batch-cache thread with new evidence. Keeping one file fixed the number of reads, but not the memory plan the earlier review asked for, since the retained raster still isn't counted. Suggested fix: let the old file go before the decode, and keep a
Suggested change
Confidence: high on the ordering (read at 1530–1533, clear at 1537). Medium on how far the peak exceeds the plan, since I have not measured it. The existing test uses one file, so it wouldn't catch this. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 8fa9312: a batch lets go of the file it kept before it reads a different one. The next decode is planned without it, and nothing is held uncounted meanwhile. |
||||||||||||||||
| rustgis_data::raster::read_path_with(std::path::Path::new(path), None, None) | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concurrent tool runs on one tiled layer can each decode up to Failure: a 10.6 GB mosaic, three zonal-stats runs started at once, each decoding a multi-GB finest level, can exhaust memory. AGENTS.md counts that as a crash. Suggested direction: share one in-flight budget across tiled-file reads (for example a Confidence: medium-low. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in cf9aaf4. Reads of tiled files for tool runs now take turns across runs (a process-wide lock around the decode), and each read is counted as a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A built-in tool run on a tiled layer reads the file as it is now, not the file the layer's overview came from, and nothing says so. The layer's map keeps drawing the overview read when the layer was added or reloaded. This read ( The overview already records the revision it was read at ( Confidence: medium. I traced the code path but did not run the scenario. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended, so I've left it unchanged.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A tool run on a tiled file drops the whole-file reader's rounding count, so its values are rounded with nothing said.
Failure: add a tiled Int32 GeoTIFF with values above 2^24 (large enough to be read in place), run Zonal Statistics on it. The tool computes from rounded values and the result carries no notice. Fix: when a tool reads the file, push a message for Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 019fd96: when a built-in run reads a tiled file, the values |
||||||||||||||||
| .map_err(|e| format!("{}: {e}", l.name))?, | ||||||||||||||||
| ); | ||||||||||||||||
| BATCH_READS.with(|b| { | ||||||||||||||||
| // The last file read alone: a batch over several files holds one. | ||||||||||||||||
| if let Some(reads) = b.borrow_mut().as_mut() { | ||||||||||||||||
| reads.clear(); | ||||||||||||||||
| reads.insert(path.to_string(), r.clone()); | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Batch reads are never evicted, so a batch over several tiled rasters can exhaust memory. Keeping only the last file still gives one read per item when a batch repeats a file:
Suggested change
If interleaved files should also share a read, the cache needs a bound planned with Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in dc10b31 with the suggested eviction: the batch keeps only the last file it read, so a batch over several files holds one decoded raster at a time.
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
| r | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
| if let Some((fw, fh)) = r.overview { | ||||||||||||||||
| messages.push(format!( | ||||||||||||||||
| "{}: read at its {} × {} overview of the {fw} × {fh} raster, the finest it can hold", | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Built-in tool runs add one overview note per tiled input, while plugin runs now join theirs into one notice. With two or more tiled raster inputs, this pushes one message for each layer (the same kind of overview read each time). The plugin path was changed to one joined notice (d0fee2f) for the same reason. Joining these messages here as well would keep the names and counts while saying it once per run. This is a nit; I'm leaving it for the release quality pass if the maintainers prefer, but it is the same pattern as the earlier plugin thread. Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 61948da: a built-in run now gives one note naming every tiled input read at an overview, as the plugin path does. |
||||||||||||||||
| l.name, r.width, r.height | ||||||||||||||||
| )); | ||||||||||||||||
| } | ||||||||||||||||
| read.insert(key, r); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| Ok(read) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| thread_local! { | ||||||||||||||||
| /// The raster file read in place that a batch's items last read ([`tiled_inputs`]), by path, | ||||||||||||||||
| /// kept while the batch runs on this thread ([`BatchReads`]): items reading the same file read | ||||||||||||||||
| /// it once, not once an item, and a batch over several files holds one at a time. `None` | ||||||||||||||||
| /// outside a batch, where nothing is kept past the run. | ||||||||||||||||
| static BATCH_READS: std::cell::RefCell<Option<std::collections::HashMap<String, std::sync::Arc<rustgis_data::raster::Raster>>>> = | ||||||||||||||||
| const { std::cell::RefCell::new(None) }; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(test)] | ||||||||||||||||
| thread_local! { | ||||||||||||||||
| /// How many raster files read in place [`tiled_inputs`] has read from their file on this | ||||||||||||||||
| /// thread, under test. | ||||||||||||||||
| pub(crate) static TILED_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Whether a batch's reads are kept on this thread now ([`BATCH_READS`]), under test. | ||||||||||||||||
| #[cfg(test)] | ||||||||||||||||
| pub(crate) fn batch_reads_kept() -> bool { | ||||||||||||||||
| BATCH_READS.with(|b| b.borrow().is_some()) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Keeps [`BATCH_READS`] while it lives: the outermost batch on this thread starts it and lets | ||||||||||||||||
| /// it go, so a file it read is held only as long as the batch runs. | ||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| struct BatchReads(bool); | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| impl BatchReads { | ||||||||||||||||
| fn start() -> BatchReads { | ||||||||||||||||
| BatchReads(BATCH_READS.with(|b| { | ||||||||||||||||
| let mut b = b.borrow_mut(); | ||||||||||||||||
| let outer = b.is_none(); | ||||||||||||||||
| if outer { | ||||||||||||||||
| *b = Some(std::collections::HashMap::new()); | ||||||||||||||||
| } | ||||||||||||||||
| outer | ||||||||||||||||
| })) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| impl Drop for BatchReads { | ||||||||||||||||
| fn drop(&mut self) { | ||||||||||||||||
| if self.0 { | ||||||||||||||||
| BATCH_READS.with(|b| *b.borrow_mut() = None); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Narrows the rows a tool reads of each layer to the features its definition query keeps, as the | ||||||||||||||||
| /// map draws them (#1995): a selection is cut to its drawn features, and a layer without one (or | ||||||||||||||||
| /// with only the environment's extent) reads the kept features instead of every one. A layer whose | ||||||||||||||||
|
|
@@ -1990,9 +2163,11 @@ impl Inputs for MapInputs<'_> { | |||||||||||||||
| *self.view.get_or_init(|| view_extent(&self.snap)) | ||||||||||||||||
| } | ||||||||||||||||
| fn raster(&self, layer: &str) -> Option<RasterInput<'_>> { | ||||||||||||||||
| let rl = self.snap.map.layer_by_name(layer)?.raster.as_ref()?; | ||||||||||||||||
| let l = self.snap.map.layer_by_name(layer)?; | ||||||||||||||||
| let rl = l.raster.as_ref()?; | ||||||||||||||||
| let read = self.rasters.get(&l.name.to_ascii_lowercase()).map(std::sync::Arc::as_ref); | ||||||||||||||||
| Some(RasterInput { | ||||||||||||||||
| raster: rl.data.as_deref()?, | ||||||||||||||||
| raster: read.or(rl.data.as_deref())?, | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GeoLibre runs can silently stage the held overview of a tiled layer whose file has gone. Failure: add a 1 GB tiled GeoTIFF, move it, run a GeoLibre raster tool on the layer. The tool runs on a 326 × 307 image and reports success. Fix: for Confidence: medium-high on the code path; I did not run it. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in cf9aaf4. In |
||||||||||||||||
| path: rl.path.as_deref(), | ||||||||||||||||
| embedded: rl.embedded.as_deref().map(|b| (rl.file_name.as_deref().unwrap_or("raster.tif"), b.as_slice())), | ||||||||||||||||
| }) | ||||||||||||||||
|
|
@@ -2038,6 +2213,9 @@ fn batch(s: &mut Session, p: &Value) -> CmdResult { | |||||||||||||||
|
|
||||||||||||||||
| /// Runs a geoprocessing tool in batch across multiple layers or files with cancellation and progress reporting. | ||||||||||||||||
| pub fn run_batch_with(s: &mut Session, p: &Value, control: &std::sync::Arc<rustgis_analysis::control::Control>) -> CmdResult { | ||||||||||||||||
| // A raster file read in place is read once for the batch, not once an item. | ||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| let _reads = BatchReads::start(); | ||||||||||||||||
| let tool_name = ps(p, "tool").ok_or("tool is required")?; | ||||||||||||||||
| let tool_id = tool_id(tool_name).ok_or_else(|| format!("no tool '{tool_name}'"))?; | ||||||||||||||||
| let spec = rustgis_analysis::tool(tool_id).ok_or_else(|| format!("no tool '{tool_name}'"))?; | ||||||||||||||||
|
|
@@ -3100,7 +3278,10 @@ pub(crate) fn execute( | |||||||||||||||
| } | ||||||||||||||||
| #[cfg(not(target_arch = "wasm32"))] | ||||||||||||||||
| let read = recording.then(|| Snapshot::owned(s)); | ||||||||||||||||
| let inputs = match map_inputs(s, Some(spec), params) { | ||||||||||||||||
| // A built-in tool run here (the command line, a script on its own thread) reads a | ||||||||||||||||
| // raster file read in place, as one the app starts on a thread does. | ||||||||||||||||
| let tiled = if pin.plugin().is_none() { Tiled::File } else { Tiled::Overview }; | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GeoLibre tools run here read the whole file and then never use it. Suggested direction: give suite pins Confidence: medium on the routing, high on the decode. Category: performance
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d3042fc. |
||||||||||||||||
| let inputs = match map_inputs(s, Some(spec), params, tiled) { | ||||||||||||||||
| Ok(inputs) => inputs, | ||||||||||||||||
| // A batch item that can't read its input is kept in the history as a failed run. | ||||||||||||||||
| Err(e) if opts.record.is_some() => return apply_with(s, run_of(t0), kept(), Err(e), now_ms().saturating_sub(t0), opts), | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With two or more tiled raster inputs, this loop gives one notice per input read (
read at the … overview …), each repeating the same kind of approximation. AGENTS.md's "Never silent" rule asks for one notice per kind with a count, throughSession::notifyorToolResult::messages. Joining the messages into a single notice keeps every name and number, and says it once for the run:Confidence: medium. The rule is stated for kinds of loss, and these notes are about one kind (overview reads), so a reviewer could reasonably read it as allowing per-input notes. Either way the joined form is the one the rule describes.
Category: agents-md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d0fee2f with the suggested join: a plugin run's input notes are one notice. The same commit puts the test-only batch counters under
cfg(all(test, not(target_arch = "wasm32"))), matchingBATCH_READS(CodeRabbit's minor note).