Repository navigation
fix(raster): Project Raster and Georeference convert between two datums by their transformation - #2968
fix(raster): Project Raster and Georeference convert between two datums by their transformation#2968Mavrick-F wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| }) | ||
| }; | ||
| 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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Outdated: the adaptive stretches and the POLAR guard were dropped from this PR; the fixed 8-cell interpolation from main is unchanged.
| //! 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Outdated: this module-doc text came with the adaptive interpolation, which was dropped; the current doc is main's.
| 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 |
There was a problem hiding this comment.
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.
| // 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
There was a problem hiding this comment.
Outdated: the comment and the test it sat in were dropped with the adaptive interpolation. The description now describes the old STEP of 8.
Code reviewScope: one file, Bugs
Security
Performance
Quality
AGENTS.md
Checked, not raised
Prior reviews: the review-thread file was empty, so no earlier concerns were skipped. Change sizeCompared with the base branch (merge base ced7c3d to PR head cd5507a).
|
📖 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 |
…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.
cd5507a to
0f5f76c
Compare
|
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 |
| 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 |
There was a problem hiding this comment.
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:
| /// `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
There was a problem hiding this comment.
Fixed in f896d7d: convert is replaced by Route::point, whose doc names the parameters it takes.
| /// 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` |
There was a problem hiding this comment.
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):
| /// 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
There was a problem hiding this comment.
Fixed in f896d7d: rewrapped at about 100 columns.
Code reviewI read the full diff (3 files, +73/−21 in Bugs
Security
Performance
Quality
AGENTS.md
Earlier concernsI left 3 earlier concerns alone. All three are on threads marked outdated. They point at the Change sizeCompared with the base branch (merge base def0c5c to PR head 0f5f76c).
|
… 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)?; |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
Code reviewReviewed the 5 changed files (warp.rs, crs.rs, reproject.rs, imagery.rs, analysis.md). I checked the forward and back routes in Bugs
Security
Performance
Quality
AGENTS.md
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 Change sizeCompared 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).
|
|
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:
I'm happy to send a PR for either if you'd like them done separately. |
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 throughCrs::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::tofalls 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: 1andorigin: [-9684795.699014802, 0]came out 41 × 31 instead of main's 42 × 31.Reprojection::shifts_datumtells 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
Crs::toand sizes its grid on the same route with the newprojected_footprint, so sizing and sampling agree.Crs::to. Both happen insidewarp.footprint_in,bounds_inand 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:gdalwarp -et 0on the same grid it stays within 0.0004 m, as before.gdalwarp -et 0with 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.projectof the same DEM (the benchmark'sraster_reprojectcommand), 6 interleaved runs each through hq:def0c5ce0There 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,
crsequal topointsCrs, 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
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 incrs.rs, which every conversion uses, so this PR leaves it alone.Memory
Nothing new is held per layer.
Surfaces
raster.projectandraster.georeferencereach 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 withprojected_footprintalone put back onfootprint_in, and withproject_onput 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.UI evidence
No visible UI change.
Related issue
Follows the direct-operation route agreed on #2032.
Summary by CodeRabbit