Skip to content

fix(raster): Project Raster and Georeference convert between two datums by their transformation - #2968

Closed
Mavrick-F wants to merge 2 commits into
opengeos:mainfrom
Mavrick-F:perf/warp-interpolated
Closed

Mavrick-F wants to merge 2 commits into
opengeos:mainfrom
Mavrick-F:perf/warp-interpolated

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Project Raster (raster.project) and Georeference (raster.georeference) converted every position through WGS 84 longitude/latitude. Between two datums that applies each datum's own shift to WGS 84 and then back. For DHDN to ETRS89 the result is about 0.44 m from the transformation PROJ picks for the pair. Between two datums both now convert through Crs::to, the direct operation between the two systems that pick2510 asked for on #2032. The map, exports and Polygons to Raster already use it. Where the datums have no transformation between them, or it can't place a point, Crs::to falls back through WGS 84.

On one datum the route is unchanged. Between two systems on the same datum (any two WGS 84-based systems, for example), both commands size and sample through longitude/latitude exactly as main does, so their output there is byte-identical to main's. The direct operation's rounding could otherwise move a grid's edge across a snapped cell boundary: a 40 × 30 m raster in UTM 16N projected to World Mercator (EPSG:3395) with cellSize: 1 and origin: [-9684795.699014802, 0] came out 41 × 31 instead of main's 42 × 31. Reprojection::shifts_datum tells the two cases apart. It is true when the direct operation runs a datum transformation at the middle of the source's area of use.

This PR changes only the route. The interpolation along each row is unchanged: positions were already computed exactly at every 8th cell and interpolated between, with an exact stretch wherever the midpoint check misses. An earlier version of this PR replaced that with adaptive spans and was dropped after review (see the comment below).

Which commands change

  • Project Raster: between two datums, samples through Crs::to and sizes its grid on the same route with the new projected_footprint, so sizing and sampling agree.
  • Georeference: between two datums, sizes and samples through Crs::to. Both happen inside warp.
  • Unchanged: Mosaic Rasters, footprint_in, bounds_in and the other raster commands that size a grid by them keep the route through WGS 84.

Accuracy

Cell-by-cell comparisons, release builds of def0c5ce0 (main) and this branch:

  • UTM 16N to Web Mercator (the benchmark's 115-million-cell DEM at 12 m, bilinear): the output is byte-identical to main's. Web Mercator has no direct operation, so the route is the same. Against gdalwarp -et 0 on the same grid it stays within 0.0004 m, as before.
  • DHDN Gauss-Krüger 3 to ETRS89 UTM 32N (a synthetic 2000 × 2000 grid of 1 m cells near 9°E 48.7°N): against gdalwarp -et 0 with PROJ's grid-less transformation for the pair, the same one RustGIS uses without the BETA2007 grid, this branch is within 7.6e-6 (float rounding). Main differs on 99.9% of cells, because its positions are 0.44 m off. Against PROJ with the BETA2007 grid, the mean difference falls from 4.74 to 1.19 (values ±100 with a 31–44 m period). The rest is the grid's 0.16 m, and the existing missing-grid notice reports it.

Timings

raster.project of the same DEM (the benchmark's raster_reproject command), 6 interleaved runs each through hq:

build median wall median user CPU
main def0c5ce0 19.4 s 53.0 s
this PR 19.5 s 53.5 s

There is no speed change (+1% CPU, within noise). Wall times varied with the box's load. That DEM is on one datum, so after the latest change its route is main's anyway.

Georeference isn't timed: there is no Georeference benchmark. On one datum (the default, crs equal to pointsCrs, or WGS 84 to a UTM zone) it now runs main's code. Between two datums it makes the same direct-operation call per exact point as Project Raster.

Datum grids arriving mid-run

Both commands size forward and sample backward, and a conversion is built again when the grid generation changes, for example when a grid downloaded for a read on another thread arrives. Main's route through WGS 84 already had this, through each system's transformer. The direct route widens it to pair-only grids (CHENyx06 for CH1903 to CH1903+), which main's route never used. So both commands now note the grid generation before sizing. If it has changed by the time sampling ends, they refuse with "datum grids arrived while … ran, so its cells may be placed by two transformations: run it again", before any layer or file is kept. No test covers this: no hook runs between sizing and sampling, and bumping the process-wide generation in the shared test binary would make the other projection tests running alongside refuse.

Notices, threads, Cancel

  • Missing grids: the missing-grid notice still fires and now names the pair (EPSG:31467 to EPSG:25832, EPSG:25832 to EPSG:31467), from sizing and sampling. Only the operations each step uses are built. Its count ("2 coordinate systems") counts the two directions of one pair. That wording comes from the shared notice in crs.rs, which every conversion uses, so this PR leaves it alone.
  • Threads: a row's positions depend only on that row, so the output is the same bit for bit on any number of threads. The new test checks this between two datums too. The browser runs on one thread, and Cancel is checked between rows as before.

Memory

Nothing new is held per layer.

Surfaces

raster.project and raster.georeference reach the desktop, browser, command line, Python, phone, the Assistant, MCP and plugins, which all dispatch the same commands. No command, parameter, saved format or interface text changes. The user guide's Project Raster and Georeference entries say which route each pair takes, and that a run is refused when a grid arrives part way.

Testing

  • cargo test -p rustgis-analysis --lib warp::: all pass.
    • a_projection_between_datums_takes_their_transformation: a GK3 raster whose bands hold each place's column and row, projected bilinear to UTM 32N, gives back the direct operation's position within 0.001 pixel, while the route through WGS 84 is over 0.4 pixel away. It also pins the grid's bounds to the direct operation's corners. It fails with projected_footprint alone put back on footprint_in, and with project_on put back on the old route. It checks one thread against four.
    • a_projection_on_one_datum_is_sized_as_before: pins the UTM 16N to World Mercator case above at 42 × 31 with its corner. It fails (41 × 31) when every pair takes the direct route.
  • cargo test -p rustgis-engine --lib raster_project: passes.
  • The fork's CI on this head.
  • The benchmark timings and comparisons above.

UI evidence

No visible UI change.

Related issue

Follows the direct-operation route agreed on #2032.

Summary by CodeRabbit

  • Bug Fixes
    • Improved raster reprojection by using the selected direct coordinate transformation when it changes the datum, while retaining the existing conversion route when appropriate.
    • Aligned output grid bounds and pixel size with the transformation used for reprojection.
    • Raster operations now stop with an error if datum grids change during processing, preventing inconsistent results.
  • Documentation
    • Clarified how datum transformations affect cell placement, when conversion falls back through WGS 84, and the possible half-metre difference illustrated by the existing example.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Raster projection uses direct CRS transformations when they shift datums. Footprint sizing and coordinate mapping use the selected route. Warp and projection operations reject runs if datum-grid generation changes during processing.

Changes: Raster projection transformations

Layer / File(s) Summary
Datum-shift detection
crates/data/src/raster/crs.rs, crates/data/src/raster/reproject.rs
Direct CRS operations record whether they shift datums. Reprojection::shifts_datum reports that status for direct and intermediate-system conversions.
Transformation routes and footprint sizing
crates/analysis/src/warp.rs
warp and project_on use Route for coordinate mapping. Route uses a direct transformation when it shifts datums and otherwise uses the longitude/latitude route. projected_footprint uses Route; footprint_in retains longitude/latitude conversion. Warp and projection operations check for datum-grid changes.
Engine integration and validation
crates/engine/src/cmd/imagery.rs, crates/analysis/src/warp.rs, docs/user-guide/analysis.md
project_raster uses projected_footprint for bounds and pixel size and checks grid stability across sizing and projection. Tests cover direct datum transformation, same-datum sizing, and thread-count consistency. The guide describes datum-dependent transformations and grid-change behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • opengeos/RustGIS#2568: The issue describes WGS 84-mediated raster warping and the DHDN-to-ETRS89 offset. This change uses the direct datum-pair transformation for raster projection.
  • opengeos/RustGIS#2032: The issue tracks direct Crs::to conversion for raster transformations. This change uses that operation for projection and footprint sizing.

Possibly related PRs

  • opengeos/RustGIS#953: This change modifies the raster projection coordinate mapping and footprint behavior introduced by that PR.
  • opengeos/RustGIS#2448: This change uses the Crs::to transformation contract added by that PR.

Suggested reviewers: ryanjshields, elpidioassinaturas, giswqs

Merge Risk: Minimal · up to f896d

Project Raster and Georeference now use the direct transformation between different datums. This removes the roughly half-metre discrepancy reported for DHDN to ETRS89, while same-datum runs keep the previous WGS 84 route. No merge-blocking issue was found. Two narrow edge cases remain: a datum grid published exactly mid-run, and unusual custom CRS pairs without a known area. Both are low-impact and can be handled later.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Project Raster and Georeference now convert between two datums through their direct transformation. The changeset matches this. It routes Project Raster and Georeferen…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template: it has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change, the reason for it (about 0.44 m DHDN to ETRS89 discr…
Full details: Title check

Explanation

The title names the main change: Project Raster and Georeference now convert between two datums through their direct transformation. The changeset matches this. It routes Project Raster and Georeference through Crs::to when the datum shifts, and adds projected_footprint for grid sizing. The title is specific and accurate, though it is long (95 characters) and uses a 'fix' prefix.

Full details: Description check

Explanation

The description follows the repository template: it has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change, the reason for it (about 0.44 m DHDN to ETRS89 discrepancy), the affected commands, and the same-datum behavior. Testing lists specific test commands, comparisons, and benchmark timings. UI evidence correctly states 'No visible UI change.' Related issue links the agreed direct-operation route on #2032. The description is detailed and substantively complete. Minor gaps: the related issue line does not use a closing keyword such as 'Closes' or 'Part of', and the 'Testing' section cites CI on a fork without a link. These do not block the check.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the map at dawn
Direct paths guide each pixel on
Grid lines settle, bounds align
Datum shifts take their proper line
The warp completes; the hare hops home

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 0fb37a14-0a75-4e11-8097-669786646899
Commits

Reviewing files that changed from the base of the PR and between 0f5f76c and f896d7d.

Files selected for processing: 5

  • crates/analysis/src/warp.rs
  • crates/data/src/raster/crs.rs
  • crates/data/src/raster/reproject.rs
  • crates/engine/src/cmd/imagery.rs
  • docs/user-guide/analysis.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

Comment thread crates/analysis/src/warp.rs Outdated
})
};
let straight = line.as_ref().is_some_and(|line| {
[pm, q1, q3].into_iter().all(|e| near(e, line)) && [i, j, m, q1.0, q3.0].into_iter().all(|k| smooth(x_at(k), y))

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.

The polar guard is only tested at the five sampled points (i, q1, m, q3, j). A stretch whose interior passes POLAR between two of them is still interpolated, so the doc on POLAR ("a stretch is never interpolated") overstates what the code does. This can happen for a row that passes close to a pole in a polar output (the latitude peaks between two checks, where the way back bends most). The tolerance test can pass there when all five checked points happen to sit on the line. Either check the stretch's latitude range (for example, refuse to interpolate when the row's closest approach to a pole falls inside the stretch), or reword the claim to say only the sampled points are tested. I have not reproduced this numerically, so my confidence is medium.

Category: bug

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.

Outdated: the adaptive stretches and the POLAR guard were dropped from this PR; the fixed 8-cell interpolation from main is unchanged.

Comment thread crates/analysis/src/warp.rs Outdated
//! code): a stretch of the row is interpolated where its midpoint and quarter points are within
//! [`TOLERANCE`] image pixels of exact, and is halved and tried again where they aren't, so exact
//! computations gather where the way back bends ([`row_positions`]). Near a pole, and where a
//! place doesn't convert (a projection's edge), every cell is computed exactly.

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.

This says that near a pole, and where a place doesn't convert, "every cell is computed exactly". The code doesn't do that. A stretch is only halved when one of its sampled points fails, so cells in an untested stretch are still interpolated, and only the cells next to a non-converting place are closed in on (as the row_positions doc and the PR text say). Suggest rewording to "and where a place doesn't convert, the cells beside it are computed exactly".

Category: quality

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.

Outdated: this module-doc text came with the adaptive interpolation, which was dropped; the current doc is main's.

Comment thread crates/analysis/src/warp.rs Outdated
let (want, got) = (bent(i as f64, 0.0).unwrap(), p.unwrap());
assert!((want.0 - got.0).abs().max((want.1 - got.1).abs()) <= TOLERANCE, "{i}: {got:?} against {want:?}");
}
// Four a stretch of 256 cells (an end, the middle and two quarters), where one every eight

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.

This comment reads as garbled ("Four a stretch of 256 cells"). Also, the PR description says the old code converted once every four cells, but the old STEP was 8 and this comment says eight. The description should be corrected to match.

Suggested change
// Four a stretch of 256 cells (an end, the middle and two quarters), where one every eight
// About four exact conversions a stretch of 256 cells (an end, the middle and two quarters), where one every eight

Category: quality

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.

Outdated: the comment and the test it sat in were dropped with the adaptive interpolation. The description now describes the old STEP of 8.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: one file, crates/analysis/src/warp.rs (+186/−67). The PR replaces the fixed every-8-cells exact conversion with adaptive stretches for the way back in row_positions, and routes Reproject through Crs::to. I checked the new row_positions logic by hand (index bounds, stack handling, the reuse of midpoints, and the cost in the worst case). I could not compile or run the tests, since I have no shell here.

Bugs

  • Polar guard checked only at sample points (warp.rs:818, medium confidence, about 40%). The POLAR check looks at five points per stretch, but the doc says a stretch past 89° is never interpolated. An interior that passes 89° between two checked points can still be interpolated. This matters for polar-projected outputs where a row passes close to a pole. Posted inline.

Security

  • None found. No new input parsing, I/O, or command surface.

Performance

  • None raised. The worst case (every cell exact, for example past an edge) is still about one exact conversion per cell, with no repeats, which matches the old cost. The stack depth is bounded (about 12 entries).

Quality

  • Doc overclaims near edges and poles (warp.rs:15, confidence high). The module doc says every cell is computed exactly there. The code only closes in on cells beside a non-converting place. Posted inline.
  • Garbled test comment and wrong figure (warp.rs:1157, confidence high). "Four a stretch of 256 cells" is hard to read. The PR body says the old code converted every four cells, but STEP was 8. Posted inline with a suggestion. The PR body needs correcting too.
  • Doc line wrapping (warp.rs:469, nit). The doc comment on project_on is wider than the lines around it. Left for the release quality pass.

AGENTS.md

  • None found. I checked the non-test diff for unwrap, expect, panic, unsafe, and direct available_parallelism, and found none. Line lengths fit the 140-column rustfmt.toml. Nothing new is held per layer. The change is in analysis and is not platform specific. The threads still come from the existing helpers, and output stays identical across thread counts by design.

Checked, not raised

  • Reproject behaviour for the same CRS: point still returns the input only when it is finite, so this matches the removed same shortcut.
  • footprint_in and bounds_in now use the direct operation. This is a deliberate change of grid placement, described in the PR. It only matters where the datums differ.
  • Interpolation across a stretch whose ends use different transformation paths (direct versus through WGS 84) could be slightly off. I could not confirm this from the code, so I did not raise it.

Prior reviews: the review-thread file was empty, so no earlier concerns were skipped.

Change size

Compared with the base branch (merge base ced7c3d to PR head cd5507a).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 87.8 KB
Size after 94.4 KB
Total size change +6.7 KB
Path Before After Change
crates/analysis/src/warp.rs 87.8 KB 94.4 KB +6.7 KB

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2968/
Web app https://preview.rustgis.app/pr-2968/app/
Commit f896d7d

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 preview label (once per commit).

…ms by their transformation

raster.project and the georeference warp converted every position
through WGS 84 longitude/latitude, so between two datums they took each
datum's own shift to WGS 84 and back: about 0.44 m off for DHDN to
ETRS89. They now use Crs::to, the direct operation the map, exports and
burns already use. Project Raster sizes its grid on the same route
(projected_footprint), so sizing and sampling agree. footprint_in,
bounds_in and Mosaic Rasters keep their route. The interpolation along
each row is unchanged.
@Mavrick-F
Mavrick-F force-pushed the perf/warp-interpolated branch from cd5507a to 0f5f76c Compare November 25, 2026 21:50
@Mavrick-F Mavrick-F changed the title perf(raster): Project Raster places each row from a few exact conversions fix(raster): Project Raster and Georeference convert between two datums by their transformation Nov 25, 2026
@Mavrick-F

Copy link
Copy Markdown
Member Author

I dropped the adaptive interpolation after review. It could interpolate values past a projection's edge (an orthographic limb), it approximated without a notice, interpolated positions decided which edge cells had data, and Mosaic Rasters would have sized its grid by the changed footprint while sampling through WGS 84. The PR now keeps the old fixed 8-cell interpolation and changes only the route, to Crs::to, in Project Raster and Georeference. Numbers are in the description.

Comment thread crates/analysis/src/warp.rs Outdated
let c = self.from.from_lonlat(self.to.to_lonlat(Coord::new(x, y))?)?;
Some((c.x, c.y))
}
/// `c` converted by `re` ([`Crs::to`]: between two datums, the registry's transformation rather

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.

The doc names c, but the function takes x and y and the converter is re. Suggest saying what it does with the parameters that exist:

Suggested change
/// `c` converted by `re` ([`Crs::to`]: between two datums, the registry's transformation rather
/// The place `(x, y)` converted by `re` ([`Crs::to`]: between two datums, the registry's
/// transformation rather than each datum's shift to WGS 84 and back), as an `(x, y)` pair.

Category: quality

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 f896d7d: convert is replaced by Route::point, whose doc names the parameters it takes.

Comment thread crates/analysis/src/warp.rs Outdated
/// Projects `r` onto the grid `g`, through longitude/latitude when their coordinate systems
/// differ: each cell sampled at its centre, or (average, mode) taken from every pixel of `r`
/// Projects `r` onto the grid `g`, through the direct operation between their coordinate systems
/// when they differ ([`Crs::to`]; size the grid with [`projected_footprint`]): each cell sampled at its centre, or (average, mode) taken from every pixel of `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.

This doc line runs to about 190 columns, while the lines around it wrap at about 100. Suggest rewrapping the two lines it sits in (the rest of the paragraph is unchanged):

Suggested change
/// when they differ ([`Crs::to`]; size the grid with [`projected_footprint`]): each cell sampled at its centre, or (average, mode) taken from every pixel of `r`
/// when they differ ([`Crs::to`]; size the grid with [`projected_footprint`]): each cell sampled
/// at its centre, or (average, mode) taken from every pixel of `r`

Category: quality

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 f896d7d: rewrapped at about 100 columns.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff (3 files, +73/−21 in warp.rs, plus imagery.rs and the user guide), the Crs::to / Reprojection code it relies on in crates/data/src/raster/reproject.rs and crs.rs, and every caller of warp, project_on, footprint_in, projected_footprint and bounds_in. I found no correctness bugs. The new route is consistent: project_on samples through g.crs.to(r.crs), projected_footprint sizes through r.crs.to(crs), and warp uses a forward/back pair. Same-system conversions are identity, and the removed Reproject::back has no remaining callers. I could not compile or run the tests here, so the new test and the timings are unverified.

Bugs

  • None found.

Security

  • None found.

Performance

  • Georeference (warp) timing is not measured. convert now runs Reprojection::point, which adds a direct-operation call per sampled point. The PR's timings cover only Project Raster. Low confidence that this matters, since the cost looks small. Worth a timing run before merge.

Quality

  • Inline on warp.rs:104: the convert doc refers to a parameter c that doesn't exist.
  • Inline on warp.rs:470: the project_on doc line is about 190 columns and the paragraph wraps unevenly.
  • The footprint_by signature (warp.rs:407) is about 125 columns. Within rustfmt's 140, so it's a readability nit only.

AGENTS.md

  • None found in the changed code. No new commands, so command_surface is unaffected. Nothing new is stored per layer. The per-row cancel and thread behaviour is unchanged.
  • Note, not a finding: where no direct operation exists between two datums, Crs::to silently falls back to the route through WGS 84. The rule is "Never silent", and this path is now used by Project Raster. The fallback is existing design in crs.rs (about 1079), so it's outside this diff, and the notice only covers missing grids. Confidence: low.

Earlier concerns

I left 3 earlier concerns alone. All three are on threads marked outdated. They point at the POLAR guard, the row_positions doc, and a garbled comment near line 1157 from an earlier head. None of that text is in the current file.

Change size

Compared with the base branch (merge base def0c5c to PR head 0f5f76c).

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 450.2 KB
Size after 454.1 KB
Total size change +3.7 KB
File Before After Change
crates/analysis/src/warp.rs 87.8 KB 91.4 KB +3.6 KB
docs/user-guide/analysis.md 193.3 KB 193.4 KB +151 B
crates/engine/src/cmd/imagery.rs 169.1 KB 169.1 KB +7 B

… run that grids arrive in

Project Raster and Georeference take the direct operation only between two
datums. On one datum they size and sample through longitude/latitude as
before, so their output there is unchanged: the direct operation's rounding
moved a UTM 16N to World Mercator grid's edge across a snapped cell boundary.

A datum grid arriving while either runs rebuilds its conversions part way,
so the run is refused with a request to run it again.
/// The route from `from` to `to`: direct when [`Crs::to`] shifts datum between them. Fails as
/// either system's transformer does.
fn new(from: Crs, to: Crs) -> Result<Route, String> {
let re = from.to(to)?;

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.

Crs::to builds a DirectPair for every pair of two non-WGS 84 systems (crates/data/src/raster/reproject.rs, DirectPair::new), and DirectPair::new calls wait_for_grids and note_used before it returns. So Route::new does that work even when it then picks Route::Lonlat for a one-datum pair, and the PR text says "Only the operations each step uses are built". For a one-datum projection that is new work versus main: a possible wait on grid downloads, and the pair is noted as used. The output is unchanged, but the "as before" claim in the PR and in the Route doc is not exact. Consider deciding shifts_datum before building the direct pair, or saying in the PR that the pair is still built and noted.

Category: performance

let grids = at.and_then(|c| op.best_operation_grids_at(c.x, c.y, 0.0).ok()).unwrap_or_default();
// No operation there only between two systems on one datum; a place it can't convert, or none
// known, counts as a shift.
let shifts = at.is_none_or(|c| !matches!(op.operation_at(c.x, c.y, 0.0), Ok(None)));

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.

shifts is true when at is None. at is None when neither system has a known area of use (area_of_use returns None for Crs::Custom without a geographic code, and for a place that can't be converted). In that case a one-datum pair, for example two custom proj4 systems on WGS 84, takes the direct route in Route::new. Its sampling and sizing then differ from main's by rounding, which is the case the PR says it keeps unchanged ("byte-identical" for one datum). The doc on DirectOperation::shifts also says the check is at the source's area of use, but the code falls back to the target's. Confidence on the output change is low (about 35%), since it needs two systems without area of use. A check at a point both systems can convert, or a clear default for None, would settle it.

Category: bug

/// Runs `f`, refusing its result when datum grids arrived meanwhile ([`grid_generation`]): its
/// conversions, built again for them, may then have placed one raster by two transformations.
/// Nothing is kept from a refused run.
pub fn on_unchanged_grids<T>(what: &str, f: impl FnOnce() -> Result<T, String>) -> Result<T, String> {

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.

The refusal branch (datum grids arrived while … ran) has no test. The PR explains why: bumping the process-wide generation in the shared test binary would make other projection tests refuse. A test that stays on this function could still cover it: pass a closure that changes the generation (through a test hook, or by a grid folder change under a lock the other projection tests also take), then check that it returns Err and that a closure with no change returns Ok. Without this, the "Test both ways" rule for refusals is only covered by the description.

Category: quality

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the 5 changed files (warp.rs, crs.rs, reproject.rs, imagery.rs, analysis.md). I checked the forward and back routes in warp_now and project_on for direction consistency, the call sites of warp::project (the only non-test caller, imagery.rs:526, now sizes with projected_footprint), the Route::Direct/Lonlat choice, the mid-run generation check, and the unwrap/expect rule (new unwraps are in tests only). I found no crash, security or silent-loss problem.

Bugs

  • crs.rs:1281: shifts is true when neither system has a known area of use, so a one-datum pair with no area of use (e.g. two custom proj4 systems) takes the direct route and its output can differ from main by rounding, against the PR's "byte-identical on one datum" claim. Confidence: low (~35%).

Security

  • None found.

Performance

  • warp.rs:121: Route::new calls Crs::to, which builds a DirectPair (with wait_for_grids and note_used) even for one-datum pairs whose route is then Lonlat. The PR's "only the operations each step uses are built" is therefore not exact. Confidence: medium (~60%).

Quality

  • warp.rs:137: the refusal branch of on_unchanged_grids has no test. The PR explains why, but a test on this function could still cover it. Confidence: high that it is untested.
  • crs.rs:1281 doc: it says the check is at the source's area of use, but the code falls back to the target's. Nit.

AGENTS.md

  • No rule break found. The refusal path has no test, but the rule covers notices and crashes, so I filed that under quality.

Prior reviews: 5 threads on this PR. All are outdated or already answered by the author, and none is re-raised here. I left them alone, including the long doc line near warp.rs:512, which is partly rewrapped but still runs past 100 columns.

Change size

Compared with the base branch: the whole PR against main (merge base def0c5c to PR head f896d7d). Files: 5 changed (0 added, 5 modified, 0 removed, 0 renamed).

Measure Value
Files changed 5 (added 0, modified 5, removed 0, renamed 0)
Size before 654.8 KB
Size after 664.4 KB
Total size change +9.6 KB
Path Before After Change
crates/analysis/src/warp.rs 87.8 KB 95.3 KB +7.6 KB
docs/user-guide/analysis.md 193.3 KB 193.9 KB +677 B
crates/data/src/raster/crs.rs 179.9 KB 180.5 KB +671 B
crates/data/src/raster/reproject.rs 24.8 KB 25.2 KB +492 B
crates/engine/src/cmd/imagery.rs 169.1 KB 169.4 KB +236 B

@Mavrick-F

Copy link
Copy Markdown
Member Author

Closing this. The direct route gave no speed gain (CPU time unchanged), and doing it right turned out to need changes to how datum grids are published and how a pair's datum is checked, which is #2032's territory.

@pick2510, two things the reviews turned up that you may want for #2032:

  • Project Raster and Georeference convert between two datums through WGS 84, so on a DHDN → ETRS89 grid their cells sit about 0.44 m from where the direct transformation puts them.
  • A downloaded grid becomes usable before GRID_GENERATION changes, so a warp running at that moment can use it in one direction and not the other. Reproduced with BETA2007, a 0.16 m round-trip error.

I'm happy to send a PR for either if you'd like them done separately.

@Mavrick-F Mavrick-F closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant