Repository navigation
feat(raster): Clip by extent reads only its part of a large tiled GeoTIFF (#2865) - #2881
Conversation
…TIFF (opengeos#2865) The GeoTIFF reader reads a part of an image: the finest level whose part fits the sample limit, decoding only the strips or tiles that hold it, its transparency mask read for the part alike (`raster::read_path_part`). A rotated or unplaced file, or one with a world file beside it, is read whole as before. Clip by extent of a layer read in place from a file reads only the part under the extent, so a small clip of a mosaic too large to hold comes out at the file's full resolution.
…p's share of memory - Every k-th pixel of a file whose size k doesn't divide: the part is found on the image's extent in the grid's pixels, not the grid's size, so no column it covers is left out. - `read_path_part` says where the part lies in the grid it was read from; Clip finds its window on that grid, as a whole read does, and moves it onto the part in whole pixels, so an edge on a pixel's edge isn't rounded into the next pixel. - A file no longer the revision the layer was read from is read whole, and so is one whose part doesn't hold the window. - Clip reads a part within a third of what a run holds (the part, its clip, and the clip's file at once), and a part isn't kept for the run past its clip: only what the run says of it is.
…nned in its turn - `PartRead` gives the bounds of the grid read: every k-th pixel's grid can pass the held overview's, and a box cut to those lost a column. - The file's revision is taken once and compared with the layer's, the same one the read is then checked against. - A part's limit is a share of what a run holds, planned once the read has its turn, with the reads before it counted. - What a run says of a part (an overview, rounded values) is said only once the clip uses it, not for a part put aside for the whole file.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| #[cfg(not(target_arch = "wasm32"))] | ||
| impl ReadNote { | ||
| pub(crate) fn of(name: &str, r: &rustgis_data::raster::Raster) -> ReadNote { | ||
| ReadNote { name: name.to_string(), rounded: r.rounded.iter().sum(), overview: r.overview.map(|full| ((r.width, r.height), full)) } |
There was a problem hiding this comment.
The notice reports the part's size as the raster's size. For a part read at an overview level, read_image stores overview as the part's size in file pixels (geotiff.rs, the file(ow, sx) mapping), not the file's full size. ReadNote::of then builds "… overview of the {fw} × {fh} raster" from that value, so a Clip of a part of an 83517 × 78739 file would say "…overview of the 60000 × 60000 raster" or similar. That is a wrong number in a notice, which breaks the "says what, how much" rule.
file_pixels() needs the part's file size, so the fix is to keep the full file size next to the part (for example a full: (u32, u32) field on PartRead and Place) and have ReadNote::of use it. The overview doc in mod.rs and the file_pixels doc (which says overview "stays the file's own size") also need updating.
The part test in geotiff.rs pins overview to the part's size, and tiled_files.rs never checks the note text for a part read at a coarser level, so neither catches this. A test asserting the notice wording for that case would.
Confidence: high on the mismatch, medium on how often a user hits it (needs a clip large enough to read at an overview level).
Category: bug
There was a problem hiding this comment.
Fixed in c777968. PartRead now carries the file's full size, and a part read from an overview says "at its 500 × 500 overview of the 1000 × 1000 raster, a 62 × 177 part of it". The file_pixels doc is updated, and a_clip_by_extent_reads_only_its_part_of_a_tiled_file asserts that notice.
Code reviewReviewed the whole diff (8 files, +843/−140) against Bugs
Security
Performance
Quality
AGENTS.md
Already raised: 0. There were no prior review threads on this PR. Change sizeCompared: the whole PR against main (merge base 132a81c to PR head 7805b36).
|
…he part's The notice said "at its W × H overview of the P × Q raster", P × Q being the part's size in the file's pixels. `PartRead` now gives the file's full size, and a part's notice names the level, the file and the part: "at its 500 × 500 overview of the 1000 × 1000 raster, a 62 × 177 part of it".
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
| // The pixels kept of the grid read (`w` × `h`): a part's, else all of them. | ||
| // The image's extent in the grid's pixels: every k-th pixel's grid passes its edge when k | ||
| // doesn't divide its size. | ||
| let extent = if decimate_by > 1 { | ||
| (f64::from(full_w) / f64::from(decimate_by), f64::from(full_h) / f64::from(decimate_by)) | ||
| } else { | ||
| (f64::from(w), f64::from(h)) | ||
| }; | ||
| let span = part.map(|p| p.span((w, h), extent)); | ||
| let (ow, oh) = span.map_or((w, h), Span::size); |
There was a problem hiding this comment.
The comment "The pixels kept of the grid read (w × h): a part's, else all of them." sits above the extent block, but it describes span, ow and oh, which come after it. Moving it down next to them reads more clearly. Nothing changes in behaviour.
| // The pixels kept of the grid read (`w` × `h`): a part's, else all of them. | |
| // The image's extent in the grid's pixels: every k-th pixel's grid passes its edge when k | |
| // doesn't divide its size. | |
| let extent = if decimate_by > 1 { | |
| (f64::from(full_w) / f64::from(decimate_by), f64::from(full_h) / f64::from(decimate_by)) | |
| } else { | |
| (f64::from(w), f64::from(h)) | |
| }; | |
| let span = part.map(|p| p.span((w, h), extent)); | |
| let (ow, oh) = span.map_or((w, h), Span::size); | |
| // The image's extent in the grid's pixels: every k-th pixel's grid passes its edge when k | |
| // doesn't divide its size. | |
| let extent = if decimate_by > 1 { | |
| (f64::from(full_w) / f64::from(decimate_by), f64::from(full_h) / f64::from(decimate_by)) | |
| } else { | |
| (f64::from(w), f64::from(h)) | |
| }; | |
| // The pixels kept of the grid read (`w` × `h`): a part's, else all of them. | |
| let span = part.map(|p| p.span((w, h), extent)); | |
| let (ow, oh) = span.map_or((w, h), Span::size); |
Category: quality
There was a problem hiding this comment.
Left for the release quality pass: it moves a comment, with no change in behaviour.
Code reviewI found no bugs, crash paths, security issues or AGENTS.md breaks in the changed code. I checked the part-read path end to end: the chunk and mask span arithmetic, the placement of an overview's pixels, the BugsNone found. SecurityNone found. PerformanceNone found. Quality
AGENTS.mdNone found. Non-test code has no Earlier review threadsOne earlier thread ( Change sizeCompared with the base branch (merge base 132a81c to PR head c777968).
|
Summary
First step of #2865: the GeoTIFF reader can read one area of an image, and Clip by extent uses it.
Before this, Clip by extent of a large tiled GeoTIFF read in place read the finest level of the whole file that fits memory, then clipped. On the #2761 mosaic that's the 1:8 level, so a small clip came out at an eighth of the file's resolution.
The reader.
raster::read_path_part(path, part, max, same_as)reads aPartof the image, given as fractions of its width and height.maxsamples: the full image, an overview, or every k-th pixel of a file without overviews.PartRead::at,grid,bounds). Callers can then find a window on that grid and move it onto the part in whole pixels, without rounding again..aux.xmlas the whole read does.None, so the caller reads the whole file, for:same_aswas read fromWhole reads go through the same chunk loop with the whole image as the span, unchanged.
Clip by extent. For a layer read in place, Clip finds the part from the held overview, one file pixel wider each way. It reads that part within a third of what a run holds (the part, its clip and the clip's file are held at once). It finds the window on the full grid, so the result is the clip of the file held whole, to the pixel. If the part doesn't hold the whole window, Clip reads the whole file as before.
Measured on the #2761 mosaic (10.6 GB, 83517 × 78739, 3 bands), Linux, release
rustgis-cli, one run each. The clip is[-56.07, -12.80, -55.93, -12.70]:mainMemory. A clip holds its part of the layer, not the whole layer: about the clip's own size, at most a third of what a run may hold. The part is let go before the clip is written, and no copy is kept for the run.
Surfaces
workflows::IN_BACKGROUND).Testing
raster::geotiff::tests::a_part_is_the_whole_file_read_at_its_level_then_cut_to_itchecks a part against the whole file read at the same level and cut. It covers:at/grid, coverage of the requested ground, and bytes read (under a quarter of the file)a_turned_or_unplaced_file_is_not_read_by_parttests/tiled_files.rs::a_clip_by_extent_reads_only_its_part_of_a_tiled_fileuses a 0.001° fixture read in place:cargo fmt, the rustgis-data raster tests, and the engine tiled-file, cancellation, process, clip and imagery tests.UI evidence
No visible UI change.
Related issue
Part of #2865. Making the per-cell commands work a block at a time follows in a separate PR.
Summary by CodeRabbit