Skip to content
Open
Show file tree
Hide file tree
Changes from 22 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
53 changes: 52 additions & 1 deletion crates/data/src/raster/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ pub struct Layout {
/// a colour table too short for its pixels. One line each, for a window to say (AGENTS.md,
/// Never silent); drawing in place shows the file grey without them, as before.
pub lost: Vec<String>,
/// Who holds the rights to the picture (its Copyright tag), as [`super::Raster::copyright`].
pub copyright: Option<String>,
}

impl Layout {
Expand Down Expand Up @@ -393,6 +395,17 @@ fn read_layout(r: Sparse) -> Result<Parse> {
};
// Another body's system is said, as when the file is read whole.
let mut lost: Vec<String> = super::planetary::note_of(geo.0).into_iter().collect();
// A datum assumed, and the file's copyright, as when it is read whole.
if geo.3 {
lost.push(super::geotiff::NO_EPSG_GEOGRAPHIC.to_string());
}
let copyright = match super::geotiff::copyright_tag(&mut dec) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Ok(c) => c,
Err(e) => {
lost.push(e);
None
}
};
let palette = match color {
ColorHint::Gray if palette_image => match tag(&mut dec, Tag::ColorMap)? {
Ok(None) => {
Expand Down Expand Up @@ -623,6 +636,7 @@ fn read_layout(r: Sparse) -> Result<Parse> {
palette,
described,
lost,
copyright,
})))
}

Expand Down Expand Up @@ -794,6 +808,8 @@ pub struct Example {
/// Overviews half the size before them rounded down (500 of 1001), as terrio 0.8 writes
/// them; GDAL rounds up (501).
pub rounded_down: bool,
/// Geographic without an EPSG code (no GeographicTypeGeoKey): read as WGS 84, said.
pub no_epsg: bool,
}

impl Default for Example {
Expand All @@ -818,6 +834,7 @@ impl Default for Example {
no_overviews: false,
wavelengths: false,
rounded_down: false,
no_epsg: false,
}
}
}
Expand Down Expand Up @@ -950,7 +967,11 @@ pub fn example_with(e: &Example) -> Vec<u8> {
t.push((33550, V::D(vec![px, px, 0.0])));
t.push((33922, V::D(vec![0.0, 0.0, 0.0, 10.0, 46.0, 0.0])));
}
t.push((34735, V::S(vec![1, 1, 0, 2, 1024, 0, 1, 2, 2048, 0, 1, 4326])));
if e.no_epsg {
t.push((34735, V::S(vec![1, 1, 0, 1, 1024, 0, 1, 2])));
} else {
t.push((34735, V::S(vec![1, 1, 0, 2, 1024, 0, 1, 2, 2048, 0, 1, 4326])));
}
if e.classes {
let xml = if e.lossy {
r#"<GDALMetadata><Item name="CLASS_3">Forest Formation</Item><Item name="CLASS_70000">Far</Item></GDALMetadata>"#
Expand Down Expand Up @@ -1110,6 +1131,36 @@ pub(crate) mod tests {
assert!(take_tiles(&mut allowance, 1).is_err());
}

/// What reading the file whole says of its header, reading it in place says too: a datum
/// assumed for a geographic file without an EPSG code; a clean file says nothing and has no
/// copyright, and one written with a copyright keeps it.
#[test]
fn a_layout_says_an_assumed_datum_and_keeps_the_copyright() {
let layout_of = |file: Vec<u8>| match layout(&Sparse::default().with(0, file)) {
Ok(Parse::Done(l)) => l,
_ => panic!("not a COG"),
};
let clean = layout_of(example(64, 32));
assert!(clean.lost.is_empty() && clean.copyright.is_none(), "{:?}", clean.lost);
let assumed = layout_of(example_with(&Example { size: 64, tile: 32, no_epsg: true, ..Example::default() }));
assert_eq!(assumed.lost, vec![super::super::geotiff::NO_EPSG_GEOGRAPHIC.to_string()]);
let mut r = crate::raster::Raster::new(
"credited",
64,
64,
vec![vec![1.0; 64 * 64]],
crate::raster::GeoTransform { origin_x: 10.0, origin_y: 46.0, pixel_width: 0.01, pixel_height: -0.01 },
crate::raster::Crs::LonLat,
None,
crate::raster::ColorHint::Gray,
"UInt8",
)
.unwrap();
r.copyright = Some("Example Survey".into());
let credited = layout_of(super::super::cogwrite::write(&r, 0).unwrap());
assert_eq!(credited.copyright.as_deref(), Some("Example Survey"));
}

#[test]
fn layout_from_the_header_then_tiles_one_by_one() {
let file = example(1024, 256);
Expand Down
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
34 changes: 22 additions & 12 deletions crates/data/src/raster/geotiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ fn geo_tags_with_keys<R: Read + Seek>(dec: &mut Decoder<R>, keys: &[u16]) -> Res
/// A cloud-optimised GeoTIFF's coordinate system, georeferencing and no-data value, from its first
/// image (as [`read`] finds them); `None` for a rotated or skewed image, or one with no GeoTIFF
/// tags (a scan), which is read whole.
pub(crate) fn cog_geo<R: Read + Seek>(dec: &mut Decoder<R>) -> Result<Option<(Crs, GeoTransform, Option<Exact>)>> {
pub(crate) fn cog_geo<R: Read + Seek>(dec: &mut Decoder<R>) -> Result<Option<(Crs, GeoTransform, Option<Exact>, bool)>> {
let geo = geo_tags(dec)?;
if geo.affine.is_some() || !geo.referenced {
return Ok(None);
}
let assumed = geo.crs.is_none() && geo.geographic_model;
let crs = match geo.crs {
Some(c) => c,
None if geo.geographic_model => Crs::LonLat,
Expand All @@ -333,7 +334,22 @@ pub(crate) fn cog_geo<R: Read + Seek>(dec: &mut Decoder<R>) -> Result<Option<(Cr
}
},
};
Ok(Some((crs, geo.transform, geo.nodata_exact)))
Ok(Some((crs, geo.transform, geo.nodata_exact, assumed)))
}

/// What reading a geographic GeoTIFF without an EPSG code assumes, said whether it is read whole or
/// in place.
pub(crate) const NO_EPSG_GEOGRAPHIC: &str =
"its geographic coordinate system has no EPSG code, so its datum isn't read; its coordinates are read as longitude/latitude on WGS 84";

/// The file's Copyright tag, trimmed, or why it is left out (`Err`); `Ok(None)` without one.
pub(crate) fn copyright_tag<R: Read + Seek>(dec: &mut Decoder<R>) -> std::result::Result<Option<String>, String> {
match dec.find_tag(Tag::Copyright).map(|v| v.map(|v| v.into_string())) {
Ok(None) => Ok(None),
Ok(Some(Ok(c))) => Ok(Some(c.trim().to_string())),
Ok(Some(Err(e))) => Err(format!("its Copyright tag: it isn't ASCII text ({e}), so it is left out")),
Err(e) => Err(format!("its Copyright tag: it can't be read ({e}), so it is left out")),
}
}

#[cfg(test)]
Expand Down Expand Up @@ -1527,11 +1543,9 @@ pub(super) fn read_limited_with_nodata(
// Who holds the rights to the picture, kept as it reads so an export of it says so too (the
// writers make it the ASCII a tag holds, and the exports say what that changed); one that
// doesn't read as text is left out, and said.
let (copyright, copyright_lost) = match dec.find_tag(Tag::Copyright).map(|v| v.map(|v| v.into_string())) {
Ok(None) => (None, None),
Ok(Some(Ok(c))) => (Some(c.trim().to_string()), None),
Ok(Some(Err(e))) => (None, Some(format!("its Copyright tag: it isn't ASCII text ({e}), so it is left out"))),
Err(e) => (None, Some(format!("its Copyright tag: it can't be read ({e}), so it is left out"))),
let (copyright, copyright_lost) = match copyright_tag(&mut dec) {
Ok(c) => (c, None),
Err(e) => (None, Some(e)),
};
let spp = samples(&mut dec);
let full_alpha = extra_alpha(&mut dec);
Expand Down Expand Up @@ -1842,11 +1856,7 @@ pub(super) fn read_limited_with_nodata(
"its own coordinate system can't be read ({})",
e.strip_prefix("GeoTIFF: ").unwrap_or(e)
)),
None if geo.geographic_model => {
"its geographic coordinate system has no EPSG code, so its datum isn't read; its coordinates are \
read as longitude/latitude on WGS 84"
.to_string()
}
None if geo.geographic_model => NO_EPSG_GEOGRAPHIC.to_string(),
None => super::assumed_wgs84_note("it doesn't say its coordinate system"),
});
Crs::LonLat
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
Loading
Loading