Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions apps/rustgis-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ impl Engine {
if !selected && found.is_streamed() {
// Source metadata was reported when this layer opened. A fresh whole read may
// discover further notes, which must survive this boundary without replaying those.
let opened_notes: Vec<String> = found
let opened_notes: Vec<rustgis_engine::data::loss::Note> = found
.source
.as_ref()
.and_then(|source| source.info())
.map(|info| info.notes.iter().map(|note| format!("{}: {note}", info.name)).collect())
.map(|info| info.notes.iter().map(|note| note.clone().prefixed(&info.name)).collect())
.unwrap_or_default();
let (ds, report) = found.load_all_reported().map_err(|e| format!("{}: {e}", found.name))?;
let name = found.name.clone();
Expand All @@ -183,7 +183,7 @@ impl Engine {
n => session.warn(format!("{name}: {n} rows couldn't be read and were left out")),
}
for message in report.messages.into_iter().filter(|message| !opened_notes.contains(message)) {
session.notify(message, false);
session.say(message);
}
if let Some(note) = rustgis_engine::data::zm_export_note([&ds], &format!("{name} as GeoJSON")) {
session.notify(note, false);
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/citygml/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn building(id: &str, inner: &str) -> String {
}

fn messages_of(out: &[(Dataset, ReadReport)]) -> Vec<String> {
out.iter().flat_map(|(_, r)| r.messages.clone()).collect()
out.iter().flat_map(|(_, r)| r.messages.texts().map(str::to_string).collect::<Vec<_>>()).collect()
}

fn says(out: &[(Dataset, ReadReport)], text: &str) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/cityjson/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn box_shell() -> Json {
}

fn messages_of(out: &[(Dataset, ReadReport)]) -> Vec<String> {
out.iter().flat_map(|(_, r)| r.messages.clone()).collect()
out.iter().flat_map(|(_, r)| r.messages.texts().map(str::to_string).collect::<Vec<_>>()).collect()
}

fn says(out: &[(Dataset, ReadReport)], text: &str) -> bool {
Expand Down
23 changes: 15 additions & 8 deletions crates/data/src/dxf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,9 @@ pub fn read(file_name: &str, bytes: &[u8], opts: &Options) -> Result<Vec<(Datase
report.messages.push(why);
}
if opts.crs.is_none() {
report.messages.push(
"a DXF drawing doesn't say its coordinate system (give \"crs\", such as EPSG:2263): coordinates are kept as they are".into(),
);
report
.messages
.push("a DXF drawing doesn't say its coordinate system (give \"crs\", such as EPSG:2263): coordinates are kept as they are");
}
if out.capped {
report.messages.push(format!("the drawing makes more than {MAX_FEATURES} features: the rest are left out"));
Expand Down Expand Up @@ -2056,7 +2056,7 @@ mod tests {
.collect::<Vec<_>>()
.join("\n");
let layers = read("a.dxf", text.as_bytes(), &Options { crs: Some(Crs::from_epsg(4269).unwrap()), ..Options::default() }).unwrap();
let messages: Vec<&str> = layers.iter().flat_map(|(_, report)| &report.messages).map(String::as_str).collect();
let messages: Vec<&str> = layers.iter().flat_map(|(_, report)| &report.messages).map(|m| m.as_str()).collect();
assert_eq!(messages.len(), 1);
assert!(messages[0].starts_with("1 features couldn't be converted from "));
assert!(!messages[0].contains("without Y"));
Expand Down Expand Up @@ -2461,7 +2461,14 @@ mod tests {
e.max_y,
kinds.join(" "),
t.elapsed(),
layers[0].1.messages.iter().filter(|m| !m.contains("coordinate system")).cloned().collect::<Vec<_>>().join(" | ")
layers[0]
.1
.messages
.iter()
.filter(|m| !m.contains("coordinate system"))
.map(|m| m.as_str())
.collect::<Vec<_>>()
.join(" | ")
);
}
Err(e) => println!("{name}\tERR\t{e}"),
Expand Down Expand Up @@ -2918,7 +2925,7 @@ mod tests {
);
}
let notes: Vec<&str> =
layers.iter().flat_map(|(_, r)| &r.messages).filter(|m| m.contains("POLYLINE")).map(String::as_str).collect();
layers.iter().flat_map(|(_, r)| &r.messages).filter(|m| m.contains("POLYLINE")).map(|m| m.as_str()).collect();
assert_eq!(notes, ["4 unreadable POLYLINE vertices were left out of their lines"]);
let no_blocks = read("placed.dxf", text.as_bytes(), &Options { blocks: false, ..opts }).unwrap();
assert_eq!(no_blocks.len(), 1);
Expand Down Expand Up @@ -2980,7 +2987,7 @@ mod tests {
assert_eq!(lines.value(i, 8), &Value::Float(z));
}
let notes: Vec<&str> =
layers.iter().flat_map(|(_, r)| &r.messages).filter(|m| m.contains("varying Z")).map(String::as_str).collect();
layers.iter().flat_map(|(_, r)| &r.messages).filter(|m| m.contains("varying Z")).map(|m| m.as_str()).collect();
assert_eq!(notes, ["2 features lost varying Z coordinates; only the elevation attribute is kept"]);
let no_blocks = read("placed.dxf", text.as_bytes(), &Options { blocks: false, ..opts }).unwrap();
assert_eq!(no_blocks.len(), 1);
Expand Down Expand Up @@ -3299,7 +3306,7 @@ mod tests {
assert_eq!(layers.iter().map(|(ds, _)| ds.features.len()).sum::<usize>(), 1);
assert_eq!(layers[0].0.features[0].geometry, Some(Geometry::Point(Coord::new(0.0, 0.0))));
assert!(layers.iter().all(|(ds, r)| !ds.zm_dropped && r.messages.iter().all(|m| !m.contains("varying Z"))));
let messages: Vec<&str> = layers.iter().flat_map(|(_, r)| &r.messages).map(String::as_str).collect();
let messages: Vec<&str> = layers.iter().flat_map(|(_, r)| &r.messages).map(|m| m.as_str()).collect();
assert_eq!(messages.len(), 1);
assert!(messages[0].starts_with("1 features couldn't be converted from "), "{messages:?}");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/esripbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub fn read_page_within(bytes: &[u8], name: &str, limit: usize) -> Result<Page>
|| esri_wkt_over_code(code, wkt.as_deref()).is_some()
|| !wkt.as_deref().is_some_and(crate::raster::wkt::parses))
{
report.messages.push("the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD".into());
report.messages.push("the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD");
}
let (crs, to_lonlat) = crate::filegdb::esri_crs(code, wkt.as_deref(), &mut report)?;
if crs.is_none()
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/esripbf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn a_wkt_that_isnt_utf8_is_said() {
let bytes = answer(&[message(8, &message(5, wkt)), transform(false, 1.0, 0.0, 0.0), feature(&[geometry(&[], &[1, 2])])]);
let (_, report) = read(&bytes, "t").unwrap();
assert_eq!(
report.messages.first().map(String::as_str),
report.messages.first().map(|m| m.as_str()),
Some("the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD")
);
// Unused when a code RustGIS knows names the system: nothing to say.
Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Exported {
pub date_messages: Vec<String>,
/// What reading the source lost or assumed besides the counts above
/// ([`crate::source::Batch::notes`]), said as they are.
pub read_notes: Vec<String>,
pub read_notes: crate::loss::Notes,
}

/// The rows a definition query excluded, or why the stored query could not be applied.
Expand Down Expand Up @@ -251,7 +251,7 @@ fn write_chunks_as(
let mut unread_dates = Vec::new();
let mut rounded_dates = Vec::new();
let mut null_text = Vec::new();
let mut read_notes = Vec::new();
let mut read_notes = crate::loss::Notes::new();
let mut not_utf8 = Vec::new();
let mut utc_dates = Vec::new();
let mut fine_dates = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions crates/data/src/export/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Runs {
count: Some(ds.features.len() as u64),
crs: "EPSG:4326".into(),
indexed: false,
notes: Vec::new(),
notes: Default::default(),
zm_dropped: false,
};
Runs {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl FeatureSource for Runs {
unread_dates: Vec::new(),
rounded_dates: Vec::new(),
null_text: Vec::new(),
notes: Vec::new(),
notes: Default::default(),
not_utf8: Vec::new(),
})
}
Expand Down Expand Up @@ -246,7 +246,7 @@ fn a_streamed_export_writes_what_a_whole_export_writes() {
fine_dates: if ext == "gpkg" { crate::io::fine_dates(whole.features.iter(), &whole.fields) } else { Vec::new() },
written_values: if ext == "fgb" { crate::io::written_values(whole.features.iter(), &whole.fields) } else { Vec::new() },
date_messages: Vec::new(),
read_notes: Vec::new(),
read_notes: Default::default(),
};
assert_eq!(streamed, expected, "{what}");
let (a, b) = (read_back(&a), read_back(&b));
Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/filegdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn read(name: &str, open: &dyn Fn(&str) -> Result<Option<Vec<u8>>>, layer: O
});
}
// A note several layers share is said once.
let mut said: Vec<String> = Vec::new();
let mut said: Vec<crate::loss::Note> = Vec::new();
for (_, report) in &mut out.layers {
report.messages.retain(|m| !said.contains(m));
said.extend(report.messages.iter().cloned());
Expand Down Expand Up @@ -443,7 +443,7 @@ fn read_table(name: &str, t: &[u8], x: &[u8], wkid: Option<u32>) -> Result<Optio
ds.drop_zm(&mut report, decoded);
}
if patches {
report.messages.push("3D multipatches are drawn as their footprints, with their lowest and highest Z in z_min and z_max, and the difference in height".into());
report.messages.push("3D multipatches are drawn as their footprints, with their lowest and highest Z in z_min and z_max, and the difference in height");
}
if no_footprint > 0 {
report.messages.push(format!(
Expand Down
10 changes: 7 additions & 3 deletions crates/data/src/filegdb/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,18 @@ fn planetary_systems_are_said_or_refused() {
let mut report = ReadReport::default();
let (crs, t) = esri_crs(None, Some(gcs), &mut report).unwrap();
assert!(crs.is_some_and(Crs::is_planetary) && t.is_some());
assert_eq!(report.messages.iter().filter(|m| body(m)).count(), 1, "{:?}", report.messages);
assert_eq!(report.messages.iter().filter(|m| body(&m.text)).count(), 1, "{:?}", report.messages);
let e = esri_crs(None, Some(&unread(gcs)), &mut ReadReport::default()).err().unwrap().to_string();
assert!(e.contains("belongs to another body than the Earth") && e.contains("Unheard_Of"), "{e}");
let earth = r#"GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]"#;
let mut report = ReadReport::default();
let (crs, t) = esri_crs(None, Some(&unread(earth)), &mut report).unwrap();
assert!(crs.is_none() && t.is_none());
assert!(report.messages.iter().any(|m| m.contains("Unheard_Of")) && !report.messages.iter().any(body), "{:?}", report.messages);
assert!(
report.messages.iter().any(|m| m.contains("Unheard_Of")) && !report.messages.iter().any(|m| body(&m.text)),
"{:?}",
report.messages
);
}

/// #1677: an EPSG code is used as a `.prj`'s own `AUTHORITY` is: when the WKT gives no shift to WGS
Expand Down Expand Up @@ -820,7 +824,7 @@ fn a_code_gives_way_to_its_wkts_shift_or_body() {
let mut report = ReadReport::default();
let (crs, _) = esri_crs(Some(code), Some(mars), &mut report).unwrap();
assert!(crs.is_some_and(Crs::is_planetary), "{code}: {crs:?}");
assert_eq!(report.messages.iter().filter(|m| body(m)).count(), 1, "{code}: {:?}", report.messages);
assert_eq!(report.messages.iter().filter(|m| body(&m.text)).count(), 1, "{code}: {:?}", report.messages);
// A method no one knows (Bonne is read, as PROJ 9.8.1 reads it).
let unread = format!(
r#"PROJCS["Unheard_Of",{mars},PROJECTION["Unheard_Of"],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",30.0],UNIT["Meter",1.0]]"#
Expand Down
19 changes: 14 additions & 5 deletions crates/data/src/georss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result<Vec<(Dataset, ReadReport)>>
} else {
format!("{lost_holes} holes in polygons were unreadable and left out")
};
report.losses.push(crate::loss::LossMessage { code: crate::loss::LossCode::DroppedRing, text: what });
report.messages.push(crate::loss::Note::loss(crate::loss::LossCode::DroppedRing, what));
}
// What the file as a whole said goes with its first layer only.
let out: Vec<(Dataset, ReadReport)> = layers
Expand Down Expand Up @@ -319,14 +319,15 @@ mod tests {
assert_eq!(lossy[0].0.features.len(), 1);
assert!(lossy[0].0.features[0].geometry.is_some());
assert!(
lossy[0].1.losses.iter().any(|m| m.code == crate::loss::LossCode::DroppedRing && m.text.contains("1 hole in a polygon was unreadable and left out")),
lossy[0].1.messages.iter().any(|m| m.loss == Some(crate::loss::LossCode::DroppedRing)
&& m.text.contains("1 hole in a polygon was unreadable and left out")),
"{:?}",
lossy[0].1.messages
);

let clean = read("clean.rss", feed("45.2 -110.2 45.8 -110.2 45.8 -110.8 45.2 -110.2").as_bytes()).unwrap();
assert_eq!(clean[0].0.features.len(), 1);
assert!(clean[0].1.losses.is_empty());
assert!(clean[0].1.messages.iter().all(|m| m.loss.is_none()));

let multi = r#"<?xml version="1.0"?>
<rss version="2.0" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
Expand All @@ -339,7 +340,11 @@ mod tests {
</channel></rss>"#;
let lossy_multi = read("multi.rss", multi.as_bytes()).unwrap();
assert!(
lossy_multi[0].1.losses.iter().any(|m| m.text.contains("2 holes in polygons were unreadable and left out")),
lossy_multi[0]
.1
.messages
.iter()
.any(|m| m.loss.is_some() && m.text.contains("2 holes in polygons were unreadable and left out")),
"{:?}",
lossy_multi[0].1.messages
);
Expand All @@ -355,7 +360,11 @@ mod tests {
</channel></rss>"#;
let mixed_lossy = read("mixed.rss", mixed.as_bytes()).unwrap();
assert!(
mixed_lossy[0].1.losses.iter().any(|m| m.text.contains("1 hole in a polygon was unreadable and left out")),
mixed_lossy[0]
.1
.messages
.iter()
.any(|m| m.loss.is_some() && m.text.contains("1 hole in a polygon was unreadable and left out")),
"{:?}",
mixed_lossy[0].1.messages
);
Expand Down
6 changes: 3 additions & 3 deletions crates/data/src/gml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result<Vec<(Dataset, ReadReport)>>
));
}
if file_srs.is_none() && outside {
rep.messages.push("the GML doesn't say its coordinate system (srsName) and its coordinates aren't longitude/latitude".into());
rep.messages.push("the GML doesn't say its coordinate system (srsName) and its coordinates aren't longitude/latitude");
}
// Said with the layer it happened in, which may be the only one added.
if kind.lost > 0 {
Expand Down Expand Up @@ -1000,7 +1000,7 @@ mod tests {
let layers = read("p.gml", gml.as_bytes()).unwrap();
let (ds, rep) = &layers[0];
assert_eq!((ds.features.len(), rep.skipped), (2, 0));
let said: Vec<&String> = rep.messages.iter().filter(|m| m.contains("or surface patch")).collect();
let said: Vec<&crate::loss::Note> = rep.messages.iter().filter(|m| m.contains("or surface patch")).collect();
assert_eq!(said.len(), 1, "{:?}", rep.messages);
assert!(said[0].contains(": 1 ring or surface patch of a geometry was left out"), "{said:?}");
assert!(rep.messages.iter().any(|m| m.contains(": 1 part of multi-geometries")), "{:?}", rep.messages);
Expand Down Expand Up @@ -1047,7 +1047,7 @@ mod tests {
let (ds, rep) = &layers[0];
assert_eq!((ds.features.len(), rep.skipped), (2, 0));
assert!(matches!(&ds.features[1].geometry, Some(Geometry::Line(l)) if l.len() == 2));
let said: Vec<&String> = rep.messages.iter().filter(|m| m.contains("multi-geometries")).collect();
let said: Vec<&crate::loss::Note> = rep.messages.iter().filter(|m| m.contains("multi-geometries")).collect();
assert_eq!(said, ["m: 1 part of multi-geometries not read (a reference, too short, invalid coordinates, or of a kind not read)"]);
}

Expand Down
Loading
Loading