Repository navigation
feat(data): raster readers give loss codes for what they leave out or assume (#2371) #3023
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
Changes from all commits
17bf8c1
cb43cfe
d4fce87
0516f8f
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 |
|---|---|---|
|
|
@@ -258,7 +258,7 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize | |
| if east - west > 1.0 + 1e-9 || north - south > 1.0 + 1e-9 || north > 90.0 + 1e-9 || east > 180.0 + 1e-9 { | ||
| return Err(bad("its posts span more than the one-degree cell a DTED file holds")); | ||
| } | ||
| let mut lost = Vec::new(); | ||
| let mut lost = crate::loss::Notes::new(); | ||
| // What the DSI says differently (3.12 d), and what the spec sets for the level (3.9.2). | ||
| let dsi = [ | ||
| (digits(bytes, DSI + 273, 4), lat_tenths, "latitude interval"), | ||
|
|
@@ -326,10 +326,15 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize | |
| } | ||
| match field(bytes, DSI + 144, 5) { | ||
| Some("WGS84") => {} | ||
| // A datum it names but isn't read: its places are taken on WGS 84, without the shift. | ||
| Some(other) if !other.trim().is_empty() => { | ||
| lost.push(format!("its horizontal datum is {:?}, not WGS84; it is read as WGS 84", other.trim())); | ||
| lost.push(crate::loss::Note::loss( | ||
| crate::loss::LossCode::ApproximatedDatum, | ||
| format!("its horizontal datum is {:?}, not WGS84; it is read as WGS 84", other.trim()), | ||
| )); | ||
| } | ||
| _ => lost.push("it doesn't name its horizontal datum; it is read as WGS 84, as MIL-PRF-89020B sets".into()), | ||
| // None named: the standard sets WGS 84, so nothing is assumed past it. | ||
| _ => lost.push("it doesn't name its horizontal datum; it is read as WGS 84, as MIL-PRF-89020B sets"), | ||
| } | ||
| let surface = match field(bytes, DSI + 141, 3) { | ||
| Some("E96") => "the EGM96 geoid (mean sea level)".to_string(), | ||
|
|
@@ -451,12 +456,19 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize | |
| } | ||
| let count = |n: usize| if n == 1 { format!("1 of its {cols} columns has") } else { format!("{n} of its {cols} columns have") }; | ||
| if present < cols { | ||
| lost.push(format!("the file is cut short: {} no heights, read as no data", count(cols - present))); | ||
| // Heights the file should hold and doesn't: lost. | ||
| lost.push(crate::loss::Note::loss( | ||
| crate::loss::LossCode::DroppedValue, | ||
|
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. The registry's action text for The same gap applies to the other codes this PR puts on reads:
The data is kept correctly. The advice text in Category: quality
Member
Author
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. Left for the release quality pass. |
||
| format!("the file is cut short: {} no heights, read as no data", count(cols - present)), | ||
| )); | ||
| } else if let Some(extra) = body_len.checked_sub((cols * record) as u64).filter(|n| *n > 0) { | ||
| lost.push(format!("{extra} bytes after its last column are ignored")); | ||
| } | ||
| if damaged > 0 { | ||
| lost.push(format!("{} a damaged record header (not the 0xAA sentinel), read as no data", count(damaged))); | ||
| lost.push(crate::loss::Note::loss( | ||
| crate::loss::LossCode::DroppedValue, | ||
| format!("{} a damaged record header (not the 0xAA sentinel), read as no data", count(damaged)), | ||
| )); | ||
| } | ||
| match misnumbered { | ||
| 0 => {} | ||
|
|
@@ -477,8 +489,7 @@ fn read_from_limited(file_name: &str, mut source: impl std::io::Read, max: usize | |
| match twos { | ||
| 0 => {} | ||
| 1 => lost.push( | ||
| "1 of its heights was written in two's complement, not the signed magnitude MIL-PRF-89020B sets; it is read as two's complement" | ||
| .into(), | ||
| "1 of its heights was written in two's complement, not the signed magnitude MIL-PRF-89020B sets; it is read as two's complement", | ||
| ), | ||
| n => lost.push(format!( | ||
| "{n} of its heights were written in two's complement, not the signed magnitude MIL-PRF-89020B sets; they are read as two's complement" | ||
|
|
@@ -604,6 +615,21 @@ mod tests { | |
| assert!(!r.lost.iter().any(|l| l.contains("checksum")), "{:?}", r.lost); | ||
| } | ||
|
|
||
| /// A datum the file names that isn't WGS84 is read as WGS 84, without its shift, and said with | ||
| /// its code; one the file doesn't name is WGS 84 as the standard sets, said plain. | ||
| #[test] | ||
| fn a_datum_named_but_not_read_is_coded() { | ||
| let b = dted("0000000E", "0000000N", (30, 30), (11, 11), |_, _| Some(1)); | ||
| let datum = |name: &[u8; 5]| { | ||
| let mut b = b.clone(); | ||
| b[DSI + 144..DSI + 149].copy_from_slice(name); | ||
| read("x.dt1", &b).unwrap().lost.iter().filter(|l| l.contains("horizontal datum")).map(|l| l.loss).collect::<Vec<_>>() | ||
| }; | ||
| assert_eq!(datum(b"NAD27"), [Some(crate::loss::LossCode::ApproximatedDatum)]); | ||
| assert_eq!(datum(b" "), [None]); | ||
| assert!(datum(b"WGS84").is_empty()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn the_dsi_names_the_level() { | ||
| // 11 × 11 posts of 3″ is no level's spacing: the notice names the level checked against. | ||
|
|
@@ -751,7 +777,12 @@ mod tests { | |
| let cut = &bytes[..at(8, rows) + 7]; | ||
| let r = read("x.dt2", cut).unwrap(); | ||
| assert_eq!(r.value(0, 8, 0), None); | ||
| assert!(r.lost.iter().any(|l| l == "the file is cut short: 3 of its 11 columns have no heights, read as no data"), "{:?}", r.lost); | ||
| assert!( | ||
| r.lost.iter().any(|l| l.text == "the file is cut short: 3 of its 11 columns have no heights, read as no data" | ||
| && l.loss == Some(crate::loss::LossCode::DroppedValue)), | ||
| "{:?}", | ||
| r.lost | ||
| ); | ||
| // Bytes past the last column are said. | ||
| let mut longer = dted("0000000E", "0000000N", (3600, 3600), (11, rows), |_, _| Some(1)); | ||
| longer.extend([0; 5]); | ||
|
|
||
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 is the same case the PR codes as
assumed.crselsewhere: the file gives no system, so it is read as WGS 84 (ASCII grids, GeoTIFF, COG and Zarr all code "doesn't say its coordinate system" asAssumedCrs). Here it's plain text, so a--strictrun, Python's warnings and MCP'slossesaccept a DTED file read on an assumed datum. The PR lists "DTED's datum" under "No code fits these yet", butLossCode::AssumedCrsfits it, and the line above (a datum that is named but not WGS84) has the same problem. Lower confidence than the recursion above: the PR chose this on purpose, so the author should either code both DTED datum notes or say why this case differs.Category: bug
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.
Coded in d31d8ff, half of it. A datum the file names other than WGS84 is read as WGS 84 without its shift, so it carries
approximated.datum. A file that names none is read as WGS 84 because MIL-PRF-89020B sets that, so nothing is assumed past the standard, and it stays plain. A new test covers both, and a file that names WGS84.