Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3089345
fix(raster): a large local tiled GeoTIFF is read in place, drawn at t…
Mavrick-F Nov 23, 2026
117eda9
fix(raster): say a plugin reads a tiled file's overview, reread on Re…
Mavrick-F Nov 23, 2026
5719e77
perf(raster): a batch reads a tiled file once for its items
Mavrick-F Nov 23, 2026
dc10b31
fix(raster): a batch keeps only the last tiled file it read
Mavrick-F Nov 23, 2026
d0fee2f
fix(raster): one notice for a plugin run's input notes; native-only t…
Mavrick-F Nov 23, 2026
cf9aaf4
fix(raster): suite tools refuse a moved tiled file; tool reads of til…
Mavrick-F Nov 23, 2026
8fa9312
fix(raster): a batch lets its kept file go before reading another; a …
Mavrick-F Nov 23, 2026
cb2550b
fix(raster): a tiled read stays counted as held while a batch keeps it
Mavrick-F Nov 23, 2026
61948da
fix(raster): Reload and Repair stop waiting for a tiled read asked to…
Mavrick-F Nov 23, 2026
d3042fc
fix(raster): grids of tiled files, suite tools by path, no whole read…
Mavrick-F Nov 23, 2026
2455625
fix(raster): a tiled file written while its overview is read is refus…
Mavrick-F Nov 23, 2026
8437e3b
fix(raster): a local tiled file written again while open is read again
Mavrick-F Nov 23, 2026
c4278f3
fix(raster): a local tiled file's revision travels with its header; s…
Mavrick-F Nov 23, 2026
d110c71
fix(raster): an in-place overview counts the values f32 rounded; a re…
Mavrick-F Nov 23, 2026
6927237
fix(raster): a tile read in flight across a rewrite isn't joined; rou…
Mavrick-F Nov 23, 2026
76a7672
docs(raster): the tiled probe's waits don't look at Cancel, and why
Mavrick-F Nov 23, 2026
2c1d10f
fix(raster): the tiled probe keeps an unchanged file's tiles
Mavrick-F Nov 23, 2026
628fb51
fix(raster): a tile's header is checked under the tiles' lock; the no…
Mavrick-F Nov 24, 2026
ad7a034
fix(raster): a sparse tile is kept only under its file's current header
Mavrick-F Nov 24, 2026
3b4f70c
fix(raster): the rounding notice of a raster read in place says it co…
Mavrick-F Nov 24, 2026
36a1f06
fix(raster): one note for a plugin run's held overviews; a file's nam…
Mavrick-F Nov 24, 2026
037f7d7
fix(raster): a GeoTIFF read in place says an assumed datum and keeps …
Mavrick-F Nov 24, 2026
019fd96
fix(raster): an in-place header asks for its Copyright bytes; a tool …
Mavrick-F Nov 24, 2026
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
18 changes: 16 additions & 2 deletions crates/data/src/raster/file_revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::{fs::Metadata, path::Path};

#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct FileRevision {
pub struct FileRevision {
len: u64,
modified: std::time::SystemTime,
#[cfg(unix)]
Expand All @@ -16,7 +16,7 @@ pub(super) struct FileRevision {
impl FileRevision {
/// The path a revision was read from is not part of it: the callers check the path they hold,
/// so a changed working directory never looks like a changed file.
pub(super) fn capture(metadata: &Metadata) -> std::io::Result<Self> {
pub fn capture(metadata: &Metadata) -> std::io::Result<Self> {
#[cfg(unix)]
use std::os::unix::fs::MetadataExt;
#[cfg(windows)]
Expand All @@ -41,7 +41,21 @@ impl FileRevision {
}
}

impl FileRevision {
/// The revision of the file at `path` as it is now, or `None` when its metadata can't be read.
pub fn of(path: &Path) -> Option<Self> {
std::fs::metadata(path).ok().and_then(|m| Self::capture(&m).ok())
}
}

impl super::Raster {
/// Records `revision` as that of the file its pixels came from: for pixels another reader
/// assembled from the file (a GeoTIFF on this computer read in place), checked against it as
/// they were read, so the checks that pair later reads of the file with them can be made.
pub fn set_source_revision(&mut self, revision: FileRevision) {
self.source_file = Some(Ok(revision));
}

fn original_revision(&self) -> std::result::Result<&FileRevision, String> {
match &self.source_file {
Some(Ok(original)) => Ok(original),
Expand Down
2 changes: 2 additions & 0 deletions crates/data/src/raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod dted;
#[cfg(not(target_arch = "wasm32"))]
mod file_revision;
#[cfg(not(target_arch = "wasm32"))]
pub use file_revision::FileRevision;
#[cfg(not(target_arch = "wasm32"))]
pub mod gdal;
pub mod geotiff;
pub mod grib;
Expand Down
272 changes: 260 additions & 12 deletions crates/engine/src/cmd/gp.rs

Large diffs are not rendered by default.

102 changes: 93 additions & 9 deletions crates/engine/src/cmd/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,32 @@ pub(super) fn read_notices(s: &mut Session, name: &str, layer: &mut RasterLayer)
let lost = layer.lost_unsaid();
let pixels = layer.pixels_unsaid();
if let Some(r) = pixels.as_deref()
&& let Some((fw, fh)) = r.overview.filter(|_| !layer.in_place)
&& let Some((fw, fh)) = r.overview.filter(|_| !layer.reads_in_place())
{
s.notify(format!("{name}: showing a {} × {} overview of the {fw} × {fh} raster", r.width, r.height), false);
}
for loss in lost {
s.notify(format!("{name}: {loss}"), false);
}
if let Some(r) = pixels.as_deref() {
if let Some(held) = layer.in_place.then(|| crate::in_place_overview(r)).flatten() {
if let Some(held) = layer.reads_in_place().then(|| crate::in_place_overview(r, layer.tiled)).flatten() {
s.notify(format!("{name}: {held}"), false);
}
if let Some(count) = rounded_count(r) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a tiled layer read in place, pixels is the held overview, so rounded_count(r) counts rounded values in the overview's pixels only. The text says "rounded as the file was read ... so an export writes the rounded values", but the export draws the file's finer tiles, which can round more values than this count. The count is still accurate for what the layer holds, so the fix is wording rather than a new count. The same wording already applies to web-address COGs, so this predates the PR. Confidence: medium that the number and the sentence disagree; low that anyone is misled in practice.

Category: agents-md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3b4f70c. For a raster read in place, the notice now says the count is of its W × H overview as it was read, and that the map and an export read finer levels and so show rounded values in more places. A raster held whole keeps the old wording.

let held = "pixels are held as 32-bit floats, exact for whole numbers up to 16,777,216 and to about 7 significant digits";
s.notify(format!("{name}: {count} rounded as the file was read: {held}, so an export writes the rounded values"), false);
// Read in place, the count is of the overview held; the finer levels the map and an
// export draw round their own values too, not counted.
if layer.reads_in_place() {
s.notify(
format!(
"{name}: {count} rounded in its {} × {} overview as it was read: {held}, so the map and an export, which read finer levels too, show rounded values there and in more places",
r.width, r.height
),
false,
);
} else {
s.notify(format!("{name}: {count} rounded as the file was read: {held}, so an export writes the rounded values"), false);
}
}
}
}
Expand Down Expand Up @@ -567,7 +579,7 @@ pub(crate) fn say_losses(s: &mut Session, losses: Vec<(String, String)>) {
/// Opens a raster file by path; `ignored` is said with what reading it lost (options given that
/// don't apply to it).
pub fn add_path(s: &mut Session, path: &str, name: Option<&str>, page: Option<&str>, scan: bool, ignored: Option<String>) -> CmdResult {
let mut r = match super::reads::take(s, &read_key(path, page, scan)) {
let (mut r, tiled) = match super::reads::take::<RasterRead>(s, &read_key(path, page, scan)) {
Some(r) => r,
None => read_raster_as(path, page, scan),
}?;
Expand All @@ -580,7 +592,7 @@ pub fn add_path(s: &mut Session, path: &str, name: Option<&str>, page: Option<&s
// gives plain paths on Windows rather than `\\?\` ones).
let full = std::path::absolute(path).map(|p| p.display().to_string()).unwrap_or_else(|_| path.to_string());
// A scan is laid over the view as it is added, and that placement makes it reopen as one.
let mut rl = RasterLayer::from_path(r, full);
let mut rl = if tiled { RasterLayer::tiled_file(r, full) } else { RasterLayer::from_path(r, full) };
// A PDF's page, kept so the project opens the same page again.
rl.subdataset = page.map(str::to_string);
add_raster(s, &name, rl)
Expand Down Expand Up @@ -637,12 +649,84 @@ pub fn read_download_shared_page(name: &str, bytes: std::sync::Arc<Vec<u8>>, pag
raster::read_shared_page(name, bytes, page, place).map_err(|e| format!("{name}: {e}"))
}

/// The raster at `path` (a PDF's `page`), read whole; for a `scan`, as the file holds it, without
/// the world file beside it (#2075).
pub(crate) fn read_raster_as(path: &str, page: Option<&str>, scan: bool) -> Result<Raster, String> {
/// The raster at `path` (a PDF's `page`), read whole, or for a large tiled GeoTIFF on this
/// computer its overview, read in place ([`tiled_in_place`]); for a `scan`, as the file holds it,
/// without the world file beside it (#2075).
pub(crate) fn read_raster_as(path: &str, page: Option<&str>, scan: bool) -> RasterRead {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible AGENTS.md gap: a project is now read differently, with no fixture.

A project's local tiled GeoTIFF layer is now read in place when it opens (through reload and repair, using the probe). That is a change to how a project is read, and "a change to how a project is read adds or updates a fixture in schema/fixtures/". The PR adds no fixture; its coverage is tiled_files::a_project_keeps_a_tiled_file_as_a_file_and_reads_it_in_place_again, which is a unit test. I am not certain the rule means this case, so I am raising it as a question for the maintainers, not a definite break.

Category: agents-md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this and don't think the fixture rule applies, so no fixture is added.

  • What changes: how a raster layer's pixels are read once the file is opened.
  • What doesn't: how a project document is read. A project keeps such a layer exactly as before (path, no in_place, and tiled is never saved). tiled_files::a_project_keeps_a_tiled_file_as_a_file_and_reads_it_in_place_again checks that the saved text has no new key.
  • Why the fixtures don't fit: the fixtures in schema/fixtures/ hold project documents checked against the schema, and nothing in a document decides this. Whether a layer is read in place depends only on the file at its path when it opens, which a document fixture can't hold.

// A large tiled GeoTIFF: its overview, the part in view read as the map draws. Read whole
// as before when its overview can't be read after all.
#[cfg(not(target_arch = "wasm32"))]
if !scan && page.is_none() {
let full = std::path::absolute(path).map(|p| p.display().to_string()).unwrap_or_else(|_| path.to_string());
if tiled_in_place(&full)
&& let Ok(mut r) = crate::render::rustgis_tiles::cog::raster::overview_blocking(&full)
{
r.name = Path::new(path).file_stem().and_then(|s| s.to_str()).unwrap_or("raster").to_string();
return Ok((r, true));
}
}
let p = Path::new(path);
let read = if scan { raster::read_path_unplaced(p, page, None) } else { raster::read_path_with(p, page, None) };
read.map_err(|e| format!("{path}: {e}"))
read.map(|r| (r, false)).map_err(|e| format!("{path}: {e}"))
}

/// The most samples a raster file is held whole with: [`raster::max_samples`], or under test what
/// [`HELD_WHOLE`] sets on this thread, as no small fixture reaches the real limit.
#[cfg(not(target_arch = "wasm32"))]
fn held_whole() -> usize {
#[cfg(test)]
if let Some(max) = HELD_WHOLE.with(std::cell::Cell::get) {
return max;
}
raster::max_samples()
}

#[cfg(test)]
thread_local! {
/// [`held_whole`]'s limit on this thread, under test.
pub(crate) static HELD_WHOLE: std::cell::Cell<Option<usize>> = const { std::cell::Cell::new(None) };
}

/// A raster file read for [`add_path`]: its pixels, and whether they are the overview of a large
/// tiled GeoTIFF read in place ([`tiled_in_place`]).
pub(crate) type RasterRead = Result<(Raster, bool), String>;

/// Whether the GeoTIFF at `path` (a full path on this computer) is read in place rather than
/// held, as a cloud-optimised GeoTIFF's web address is (#2761): the map then reads the part in
/// view at the level the view needs, where holding it means one overview at every zoom. It is
/// when the file is tiled with overviews, too large to hold whole ([`raster::max_samples`]), and
/// reading it in place loses nothing reading it whole keeps: its header reports no loss (a
/// transparency mask, metadata that can't be read) and no `.aux.xml` or world file is beside it.
/// Reads the file's header (a few reads of the file, on the fetch workers), or takes the one kept
/// while the file hasn't changed since; forgotten when it isn't read in place. The wait for the
/// header, and [`read_raster_as`]'s for the overview, don't look at Cancel: a local file answers
/// in milliseconds, and a hung one (an unreachable mount) is given up after two minutes.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn tiled_in_place(path: &str) -> bool {
use crate::render::rustgis_tiles::cog;
use crate::render::rustgis_tiles::{address::Reach, cache};
// A `#` would be taken for a look's start by the in-place reader. A document that may reach
// only public addresses reads no file in place, and nothing of it is looked at here.
if !cog::is_local_file(path) || path.contains('#') || cache::ceiling_for(path) != Reach::Local {
return false;
}
let p = Path::new(path);
if !p.is_file() || raster::pam::read(p).is_some() || raster::world::beside(p).is_some() {
return false;
}
// A header kept for the file is read again only when the file has changed since (see
// `cog::with_info`), so its tiles stay while it hasn't.
let tiled = cog::info_blocking(path).is_ok_and(|info| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiled_in_place waits on the header with cog::info_blocking(path), and read_raster_as (line 649) waits on the overview with overview_blocking. Both use a fresh stop flag that is never set and no progress check, so a Cancel or a replaced project can't end the wait. The wait is up to two minutes, and it runs before relinked or reload looks at the still. cog::info_until(url, &stop) already gives a stoppable wait. This is a long step without a check, and the doc comment on tiled_in_place (line 687) doesn't say so, which AGENTS.md asks for. Either pass a stop flag set from the run's control, or state in the doc comment that the header read ignores Cancel and is bounded by the two-minute wait. Confidence: medium-low. The wait is on a local file, so it is normally milliseconds and only long on a hung mount. I have not run it.

Category: agents-md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 76a7672 by documenting it, the second option: tiled_in_place's doc comment now says the header wait, and read_raster_as's overview wait, don't look at Cancel. A local file answers in milliseconds, and a hung one (an unreachable mount) is given up after two minutes.

let l = &info.layout;
let full = l.levels.first().map_or(0, |f| u64::from(f.width) * u64::from(f.height));
let samples = full.saturating_mul(l.bands.max(1) as u64);
let lossless = l.lost.is_empty() && l.described.as_ref().is_none_or(|d| d.lost.is_empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lossless says a file is read in place only when the in-place reader loses nothing the whole-file reader keeps, but the in-place header parse drops one note the whole-file reader gives: the assumed datum.

For a geographic GeoTIFF with no EPSG code, geotiff::cog_geo returns Crs::LonLat with no note (crates/data/src/raster/geotiff.rs, None if geo.geographic_model => Crs::LonLat). The whole-file reader (geotiff.rs, around line 1845) notes "its geographic coordinate system has no EPSG code, so its datum isn't read; its coordinates are read as longitude/latitude on WGS 84" and sets crs_assumed. crates/data/src/raster/cog.rs adds only the planetary note to lost, and read_overview copies layout.lost. So a large local file of this kind is now read as WGS 84 with nothing said, where main said so.

Fix: have cog_geo return the note with the CRS, push it into the layout's lost the way planetary::note_of is, so lossless sends such files to the whole-file reader. Add a test that the header carries the note, and that a clean file doesn't.

Confidence: high on the code path (read, not run).

Category: agents-md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 037f7d7, as suggested.

  • The note: cog_geo now reports when it assumed the datum, and the layout puts the whole-file reader's note (now one shared constant, NO_EPSG_GEOGRAPHIC) into its lost.
  • Effect on local files: lossless is then false, so such a file is read whole, and says it.
  • Web addresses: a web-address COG of this kind now says it too.
  • Test: cog::tests::a_layout_says_an_assumed_datum_and_keeps_the_copyright covers a file without an EPSG code against a clean one.

samples > held_whole() as u64 && lossless && cog::raster::overview_level(&info).is_some()
});
if !tiled {
cog::forget_local_file(path);
}
tiled
}

/// The key [`add_path`]'s read of `path` (a PDF's `page`) is taken by (see [`super::reads`]): a
Expand Down
28 changes: 19 additions & 9 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,20 @@ fn names_said(names: &[String]) -> String {
}

/// What a raster layer read in place holds for its statistics and tools, when it holds an
/// overview of the image the map draws.
pub(crate) fn in_place_overview(d: &rustgis_data::raster::Raster) -> Option<String> {
/// overview of the image the map draws. A file on this computer (`tools_read_file`) is read again
/// by each geoprocessing tool, at the finest level it can hold ([`crate::cmd::gp`]).
pub(crate) fn in_place_overview(d: &rustgis_data::raster::Raster, tools_read_file: bool) -> Option<String> {
let (fw, fh) = d.overview?;
Some(format!(
"read in place: the map draws its {fw} × {fh} pixels as it needs them, while statistics, histograms and raster tools read a {} × {} overview",
d.width, d.height
))
let (w, h) = (d.width, d.height);
Some(if tools_read_file {
format!(
"read in place: the map draws its {fw} × {fh} pixels as it needs them, and geoprocessing tools read the file (built-in ones at the finest level they can hold, GeoLibre ones whole), while statistics, histograms, plugin tools and other raster commands read a {w} × {h} overview"
)
} else {
format!(
"read in place: the map draws its {fw} × {fh} pixels as it needs them, while statistics, histograms and raster tools read a {w} × {h} overview"
)
})
}

pub struct Registry {
Expand Down Expand Up @@ -1416,6 +1423,9 @@ impl Session {
// cloud-optimised GeoTIFFs' overviews for raster layers read in place.
render::rustgis_tiles::remote::install();
map::raster::set_in_place_reader(render::rustgis_tiles::cog::raster::overview);
// A large tiled GeoTIFF on this computer is read in place too, on the desktop (#2761).
#[cfg(not(target_arch = "wasm32"))]
map::raster::set_tiled_probe(crate::cmd::raster::tiled_in_place);
rustgis_data::diagnostics::set_clock(|| {
web_time::SystemTime::now().duration_since(web_time::UNIX_EPOCH).map(|d| d.as_millis() as u64).unwrap_or(0)
});
Expand Down Expand Up @@ -2832,10 +2842,10 @@ impl Session {
if !dropped_here.is_empty() {
dropped.push((l.name.clone(), dropped_here));
}
let in_place = rl.in_place;
let (in_place, tiled) = (rl.reads_in_place(), rl.tiled);
lost.extend(rl.lost_unsaid().into_iter().map(|what| (l.name.clone(), what)));
let Some(d) = rl.pixels_unsaid() else { continue };
if let Some(what) = in_place.then(|| in_place_overview(&d)).flatten() {
if let Some(what) = in_place.then(|| in_place_overview(&d, tiled)).flatten() {
held.push((l.name.clone(), what));
}
}
Expand Down Expand Up @@ -2977,7 +2987,7 @@ impl Session {
.filter_map(|l| {
let name = l.name.clone();
let rl = l.raster.as_mut()?;
rl.in_place.then_some((name, rl))
rl.reads_in_place().then_some((name, rl))
})
.collect();
let mut layers: Vec<&mut rustgis_map::raster::RasterLayer> = named.iter_mut().map(|(_, rl)| &mut **rl).collect();
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ mod service_logins;
#[path = "tests/scopes_and_redaction.rs"]
mod scopes_and_redaction;

#[path = "tests/tiled_files.rs"]
mod tiled_files;

#[path = "tests/elevation_tiles.rs"]
mod elevation_tiles;

Expand Down
Loading
Loading