Repository navigation
feat(raster): read SRTM .hgt and DTED elevation natively (#2076) #2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b439e28
177fd18
13a9243
543d5df
cd12374
d7eef62
79aeb68
77a17ea
a94c9b8
bc8f75c
244f1e5
5d7a0de
4f79aee
3b186fc
742343b
b575914
be09ac9
9df129d
7d6b6cc
91353c2
de15147
f447594
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,7 +223,7 @@ pub fn warp(r: &Raster, fit: &Fit, o: &Options) -> Result<Raster, String> { | |
| let re = Reproject::new(o.points_crs, o.crs)?; | ||
| let (w, h) = (f64::from(r.width), f64::from(r.height)); | ||
| // An overview's pixels are bigger than the full image's, which the fit is in. | ||
| let (sx, sy) = r.overview.map_or((1.0, 1.0), |(fw, fh)| (f64::from(fw) / w, f64::from(fh) / h)); | ||
| let (sx, sy) = r.file_pixels(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the post-grid origin when scaling a control-point fit. For a 7201-square HGT read at step 2, the first retained post represents original pixel centre This path is reachable: Carry a pixel-origin offset with the scale for stepped post grids. Apply the inverse offset in
|
||
| let place = |c: f64, row: f64| fit.to_map(c * sx, row * sy).and_then(|(x, y)| re.forward(x, y)); | ||
|
|
||
| let [min_x, min_y, max_x, max_y] = footprint(w, h, &place).ok_or("the image's edge can't be placed in the output coordinate system")?; | ||
|
|
@@ -1206,6 +1206,34 @@ mod tests { | |
| assert!(out.bands[0].data.iter().all(|v| *v == 10.0 || *v == -9999.0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_picture_read_at_a_step_is_warped_by_the_step_exactly() { | ||
| // A 61-pixel-wide file read at every second pixel: 31 cells, each exactly two of the | ||
| // file's pixels from the corner (61 isn't a multiple of 2, so 61/31 ≈ 1.968 would put | ||
| // the far cells about one cell off). The fit is in the file's pixels; each cell holds | ||
| // the file column it was read from. | ||
| let (w, h) = (31u32, 4u32); | ||
| let data: Vec<f32> = (0..w * h).map(|i| 2.0 * (i % w) as f32).collect(); | ||
| let r = scan(w, h, vec![data], ColorHint::Gray, "Float32").read_at_step(2, (61, 7)); | ||
| assert_eq!(r.file_pixels(), (2.0, 2.0)); | ||
| let map = |c: f64, rw: f64| (500_000.0 + 10.0 * c, 4_000_000.0 - 10.0 * rw); | ||
| let fit = georef::fit(Kind::Affine, &gcps(61.0, 7.0, map)).unwrap(); | ||
| let out = warp(&r, &fit, &opts(Some(5.0), Resampling::Nearest)).unwrap(); | ||
| let mut checked = 0; | ||
| for col in 0..i64::from(out.width) { | ||
| let p = out.transform.to_world(col as f64 + 0.5, 1.5); | ||
| let Some((c, _)) = fit.to_pixel(p.x, p.y) else { continue }; | ||
| // Away from the cells' edges, where nearest could go either way. | ||
| if !(0.2..61.8).contains(&c) || (c % 2.0 - 1.0).abs() < 0.2 || c % 2.0 < 0.2 { | ||
| continue; | ||
| } | ||
| let v = out.value(0, col, 1).unwrap(); | ||
| assert_eq!(f64::from(v), 2.0 * (c / 2.0).floor(), "file column {c}"); | ||
| checked += 1; | ||
| } | ||
| assert!(checked > 40, "{checked}"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn hostile_fits_and_options_are_refused() { | ||
| let r = scan(4, 4, vec![vec![1.0; 16]], ColorHint::Gray, "Float32"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the warp of every GeoTIFF or picture read at a step, not only SRTM/DTED. The old
overviewratio is file size over the reduced size, which isn't the step when the size doesn't divide by it. For example, 1201 columns at step 2 gives 1201/601 ≈ 1.9983, so a warp drifts about one file pixel by the far edge. Usingstepis the correct fix, but the PR description doesn't mention it and no test pins it. Please add a warp test for a decimated GeoTIFF whose size isn't a multiple of its step, and note the output change in the PR.Confidence: medium-high (about 75%). I reasoned through the arithmetic but didn't run it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 9df129d:
a_picture_read_at_a_step_is_warped_by_the_step_exactlypins it (it fails under the old ratio), and the description now says the warp changed.