Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b439e28
feat(raster): read SRTM .hgt and DTED elevation natively (#2076)
flight1973 Nov 16, 2026
177fd18
fix(dted): read columns with wrong checksums, two's complement height…
flight1973 Nov 16, 2026
13a9243
fix(hgt): read 0.5 arc-second tiles, center stepped cells on their posts
flight1973 Nov 16, 2026
543d5df
fix(raster): say when a crs or layer given for SRTM or DTED is ignored
flight1973 Nov 16, 2026
cd12374
fix(python): embed only the elevation files that fit under the limit
flight1973 Nov 16, 2026
d7eef62
refactor(raster): pictures take their read step from step_within
flight1973 Nov 16, 2026
79aeb68
chore: remove the review notes
flight1973 Nov 16, 2026
77a17ea
refactor(raster): move the shared elevation helpers into raster/mod.rs
flight1973 Nov 16, 2026
a94c9b8
refactor(raster): one list of the elevation file extensions
flight1973 Nov 16, 2026
bc8f75c
refactor(raster): check an SRTM tile's name and size once
flight1973 Nov 16, 2026
244f1e5
fix(dted): read records by place when their counts are numbered diffe…
flight1973 Nov 16, 2026
5d7a0de
fix(raster): an elevation file read at a step keeps its scale exact
flight1973 Nov 16, 2026
4f79aee
fix(hgt): give the nearest tile sizes for a file of the wrong size
flight1973 Nov 16, 2026
3b186fc
fix(raster): say what an ignored crs or layer means for SRTM and DTED
flight1973 Nov 16, 2026
742343b
perf(raster): count skipped elevation posts without decoding them
flight1973 Nov 16, 2026
b575914
chore: remove the review notes
flight1973 Nov 16, 2026
be09ac9
fix(raster): an elevation file read at a step says its own size; the …
flight1973 Nov 17, 2026
9df129d
test(raster): pin the warp at a step, a fixture for elevation layers
flight1973 Nov 17, 2026
7d6b6cc
fix(raster): cap elevation reads; refuse DTED tape-layout partial cells
flight1973 Nov 17, 2026
91353c2
fix(dted): find a tape-layout partial cell by its DSI counts
flight1973 Nov 17, 2026
de15147
fix(raster): a turned picture read at a step says its true size
flight1973 Nov 18, 2026
f447594
docs(raster): say why the SRTM and DTED decode stays on one thread
flight1973 Nov 18, 2026
b63db11
fix(data): the capped read sizes its buffer once, when the file's siz…
flight1973 Nov 18, 2026
cf99f27
fix(dted): refuse a partial cell whose file is shorter than its full …
flight1973 Nov 18, 2026
c3b1058
fix(dted): refuse record counts that place heights in another column;…
flight1973 Nov 19, 2026
dec400f
fix(dted): refuse a record whose latitude count isn't 0; the notice s…
flight1973 Nov 19, 2026
0485943
fix(raster): refuse DTED records whose counts would place heights in …
flight1973 Nov 19, 2026
828b5df
Merge remote-tracking branch 'origin/main' into sync/2320
flight1973 Nov 19, 2026
994cba0
fix(analysis): warp a stepped SRTM or DTED grid with each cell on its…
flight1973 Nov 20, 2026
c201e76
Merge remote-tracking branch 'fork/srtm-dted-2076' into sync2/2320
flight1973 Nov 20, 2026
ad4aec6
Merge remote-tracking branch 'origin/main' into sync3/2320
flight1973 Nov 21, 2026
d01e952
fix(raster): stream SRTM and DTED tiles from the file instead of hold…
flight1973 Nov 21, 2026
ed05aeb
fix(raster): an SRTM or DTED layer drops the crs it ignores, so reope…
flight1973 Nov 21, 2026
b1d5252
docs(raster): the read-step comment in the picture reader says what i…
flight1973 Nov 21, 2026
753925d
docs(raster): state what the SRTM and DTED readers hold as a multiple…
flight1973 Nov 21, 2026
f64ae8f
Merge remote-tracking branch 'origin/main' into sync4/2320
flight1973 Nov 22, 2026
be4f9c1
fix(raster): a DTED file read by path counts bytes added after its si…
flight1973 Nov 22, 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
9 changes: 5 additions & 4 deletions apps/rustgis-python/python/rustgis/_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
#: each change, and some setups cap a message near 10 MB, so this stays small.
EMBED_LIMIT = 2 << 20

# The extensions `layer.addDataBytes` reads from a file's contents.
# The extensions `layer.addDataBytes` reads from a file's contents. (Not `.hgt` or `.dt2`, never
# under EMBED_LIMIT; a `.dt1` cell is under it from 50° of latitude, where its spacing widens.)
_EMBEDDABLE = {
".tif", ".tiff", ".asc", ".geojson", ".json", ".csv", ".tsv", ".txt", ".zip", ".kml", ".kmz",
".gpx", ".parquet", ".geoparquet", ".fgb", ".gpkg", ".mbtiles", ".xlsx", ".xls", ".ods",
".grb", ".grib", ".grb2", ".grib2",
".tif", ".tiff", ".asc", ".dt0", ".dt1", ".geojson", ".json", ".csv", ".tsv", ".txt", ".zip",
".kml", ".kmz", ".gpx", ".parquet", ".geoparquet", ".fgb", ".gpkg", ".mbtiles", ".xlsx",
".xls", ".ods", ".grb", ".grib", ".grb2", ".grib2",
}

#: The page script that frames the app: an anywidget module, also run by the Qt host page.
Expand Down
6 changes: 5 additions & 1 deletion apps/rustgis-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const DATA_EXTS: &[&str] = &[
"grib",
"grb2",
"grib2",
// SRTM height tiles and DTED are added below (`ELEVATION_EXTENSIONS`).
];
const CANVAS_ID: &str = "rustgis_canvas";
const LOADING_ID: &str = "rustgis_loading";
Expand Down Expand Up @@ -1373,7 +1374,10 @@ fn services(inbox: Inbox, font_inbox: Inbox, notes: Notes, ctx: egui::Context, e
} else if purpose == "picture" || marker.is_some() {
rfd::AsyncFileDialog::new().add_filter(rustgis_ui_egui::tl!("Pictures"), &["png", "jpg", "jpeg"])
} else {
rfd::AsyncFileDialog::new().add_filter("Vector and raster data", DATA_EXTS)
rfd::AsyncFileDialog::new().add_filter(
"Vector and raster data",
&[DATA_EXTS, &rustgis_ui_egui::rustgis_engine::data::raster::ELEVATION_EXTENSIONS[..]].concat(),
)
};
// Data may come several files at once (photos gather in one layer).
let many = matches!(purpose, "data" | "shapefile");
Expand Down
66 changes: 62 additions & 4 deletions crates/analysis/src/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ impl Sampler<'_> {
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 place = |c: f64, row: f64| fit.to_map(c * sx, row * sy).and_then(|(x, y)| re.forward(x, y));
// An overview's pixels are bigger than the full image's, which the fit is in; a grid of
// posts read at a step also starts before the file's corner (each cell centered on its post).
let (sx, sy) = r.file_pixels();
Comment thread
flight1973 marked this conversation as resolved.
Resolved
Comment thread
flight1973 marked this conversation as resolved.
Resolved
Comment thread
flight1973 marked this conversation as resolved.
Resolved
Comment thread
flight1973 marked this conversation as resolved.
Resolved
let (ox, oy) = r.file_origin();
let place = |c: f64, row: f64| fit.to_map(c * sx + ox, row * sy + oy).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")?;
if o.crs.is_geographic() && max_x - min_x > 180.0 {
Expand Down Expand Up @@ -275,7 +277,7 @@ pub fn warp(r: &Raster, fit: &Fit, o: &Options) -> Result<Raster, String> {
let source = |x: f64, y: f64| -> Option<(f64, f64)> {
let (px, py) = re.back(x, y)?;
let (c, row) = fit.to_pixel(px, py)?;
let (c, row) = (c / sx, row / sy);
let (c, row) = ((c - ox) / sx, (row - oy) / sy);
(c.is_finite() && row.is_finite()).then_some((c, row))
};
sampled(None, r, &g, canvas, o.resampling, &source, o.name.clone())
Expand Down Expand Up @@ -1206,6 +1208,62 @@ 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 an_elevation_grid_read_at_a_step_is_warped_with_each_cell_on_its_post() {
// A 61-post-wide SRTM or DTED grid read at every fourth post: 16 cells, each centered on
// the post it was read from (file position 4k + 0.5), not starting at it, which put every
// height 1.5 file pixels off. Each cell holds the file column it was read from.
let (w, h) = (16u32, 4u32);
let data: Vec<f32> = (0..w * h).map(|i| 4.0 * (i % w) as f32).collect();
let r = scan(w, h, vec![data], ColorHint::Gray, "Float32").posts_read_at_step(4, (61, 13));
assert_eq!(r.file_origin(), (-1.5, -1.5));
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, 13.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, 5.5);
let Some((c, _)) = fit.to_pixel(p.x, p.y) else { continue };
// The nearest post kept, away from the cells' edges (halfway between two of them).
let k = (c - 0.5) / 4.0;
if !(0.0..60.5).contains(&c) || (k - k.floor() - 0.5).abs() < 0.05 {
continue;
}
let v = out.value(0, col, 5).unwrap();
assert_eq!(f64::from(v), 4.0 * k.round(), "file column {c}");
checked += 1;
}
assert!(checked > 100, "{checked}");
}

#[test]
fn hostile_fits_and_options_are_refused() {
let r = scan(4, 4, vec![vec![1.0; 16]], ColorHint::Gray, "Float32");
Expand Down
Loading
Loading