diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 12b4c949a6..361ec02fa5 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -5447,10 +5447,11 @@ fn idw_interpolation(inp: &dyn Inputs, p: &Json) -> Result { losses: left_out .losses("IDW Interpolation", total, field, "a coordinate is not a finite number") .into_iter() + .chain(beyond_note.map(projection_point_loss)) .chain(raster_losses(&r)) .collect(), output: Output::Layers(vec![OutputLayer::Raster { file_name: format!("{name}.tif"), name, bytes }]), - messages: std::iter::once(msg).chain(beyond_note).chain(crs_note).collect(), + messages: std::iter::once(msg).chain(crs_note).collect(), }) } @@ -5607,16 +5608,22 @@ fn kriging_interpolation(inp: &dyn Inputs, p: &Json) -> Result rustgis_data::loss::LossMessage { + rustgis_data::loss::LossMessage { code: rustgis_data::loss::LossCode::DroppedGeometry, text } +} + /// How many points or rows Kriging's preparation goes through between two looks at Cancel. const LOOK_EVERY: usize = 4096; @@ -13127,7 +13134,13 @@ mod tests { for tool in ["idwInterpolation", "kriging"] { let p = serde_json::json!({"input": "polar", "field": "v", "crs": "EPSG:3857"}); let r = crate::run(tool, &m, &p).unwrap_or_else(|e| panic!("{tool}: {e}")); - assert!(r.messages.iter().any(|m| m.starts_with("1 point(s) beyond what")), "{tool}: {:?}", r.messages); + assert!( + r.losses + .iter() + .any(|n| n.code == rustgis_data::loss::LossCode::DroppedGeometry && n.text.starts_with("1 point(s) beyond what")), + "{tool}: {:?}", + r.losses + ); assert!(!r.messages.iter().any(|m| m.contains("was read in")), "{tool}: {:?}", r.messages); } } diff --git a/crates/data/src/loss.rs b/crates/data/src/loss.rs index 2f2add709d..5f060803cd 100644 --- a/crates/data/src/loss.rs +++ b/crates/data/src/loss.rs @@ -143,11 +143,17 @@ loss_codes! { "A feature's geometry could not be read or written. The feature was kept without its place, or the place was left out.", "Correct the geometry in the source; when the notice names a coordinate system, give the one its coordinates are in." ), + DroppedMask => ( + "dropped.mask", + Dropped, + "A layer's mask was cleared because the destination map has no compatible mask layer by that name.", + "Copy or add the mask layer with the layer it masks." + ), DroppedOverLimit => ( "dropped.over-limit", Dropped, - "RustGIS read only part of the data because it is past a size limit.", - "Read less at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it." + "RustGIS included only part of the data because it is past a size limit.", + "Use less data at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it." ), ChangedCsvGuard => ( "changed.csv-guard", diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index 3ce202f8e1..009d52306b 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -1375,9 +1375,9 @@ struct Mesh { keep_lines: bool, /// The estimated size it stops at, and why. most: (usize, String), - /// Polygons left out because their outer ring has fewer than 3 vertices. + /// Polygon parts with coordinates left out because their outer ring has fewer than 3 vertices. skipped: usize, - /// Holes left out because they have fewer than 3 vertices, so their areas stay solid. + /// Nonempty holes left out because they have fewer than 3 vertices. holes_dropped: usize, /// Polygons and points of zero height left out of STL, which holds solids, not flat sheets, /// that had an area or a point to lose. @@ -1588,16 +1588,15 @@ fn layer_mesh(s: &Session, p: &Value, keep_lines: bool, out: Output<'_>) -> Resu // A degenerate outer ring drops the polygon (a hole mustn't become solid); // degenerate holes are left out. if open.first().is_none_or(|r| r.len() < 3) { - mesh.skipped += 1; + mesh.skipped += usize::from(open.iter().any(|r| !r.is_empty())); continue; } - let rings_before = open.len(); + mesh.holes_dropped += open.iter().skip(1).filter(|r| !r.is_empty() && r.len() < 3).count(); let mut k = 0; open.retain(|r| { k += 1; k == 1 || r.len() >= 3 }); - mesh.holes_dropped += rings_before - open.len(); let Some(outer) = open.first() else { continue }; let n: usize = open.iter().map(Vec::len).sum(); let v = mesh.vertices; @@ -1767,14 +1766,18 @@ pub(crate) fn stl_with_cap(s: &Session, p: &Value, cap: usize) -> Result 0 { - s.notify(format!("Skipped {} polygon(s) whose outer ring has fewer than 3 vertices", mesh.skipped), false); + s.notify_loss( + LossCode::DroppedGeometry, + format!("Skipped {} polygon(s) whose outer ring has fewer than 3 vertices", mesh.skipped).into(), + ); } if mesh.holes_dropped > 0 { - s.notify(format!("Dropped {} hole(s) with fewer than 3 vertices: their areas are filled in", mesh.holes_dropped), false); + s.notify_loss(LossCode::DroppedRing, format!("Dropped {} hole(s) with fewer than 3 vertices", mesh.holes_dropped).into()); } if mesh.short_lines > 0 { - s.notify(format!("Skipped {} line part(s) with a single vertex", mesh.short_lines), false); + s.notify_loss(LossCode::DroppedGeometry, format!("Skipped {} line part(s) with a single vertex", mesh.short_lines).into()); } if let Some(note) = rustgis_data::unplaced_note("The 3D model", &mesh.layer, mesh.unplaced) { s.say(note); diff --git a/crates/engine/src/cmd/layer_copy.rs b/crates/engine/src/cmd/layer_copy.rs index 4ee9a565f5..560d05838f 100644 --- a/crates/engine/src/cmd/layer_copy.rs +++ b/crates/engine/src/cmd/layer_copy.rs @@ -136,23 +136,22 @@ impl Placed { /// Says the names cut and the masks lost, after the notice of what was added (`what`: the /// command). pub(crate) fn say(&self, s: &mut Session, what: &str) { + use rustgis_data::loss::LossCode; let (map, names_cut) = (&self.map, self.names_cut); if names_cut > 0 { - s.notify( - format!("{what}: {names_cut} copied name(s) cut so \" copy\" and a number fit in {} characters", super::MAX_NAME), - false, + s.notify_loss( + LossCode::ChangedCut, + format!("{what}: {names_cut} copied name(s) cut so \" copy\" and a number fit in {} characters", super::MAX_NAME).into(), ); } let (polygons, rasters) = self.unmasked.split_at(self.unmasked.len().saturating_sub(self.raster_unmasked)); - match polygons { - [] => {} - [one] => s.notify(format!("{one} lost its mask: {map} has no polygon layer by that name"), false), - many => s.notify(format!("{} lost their masks: {map} has no polygon layers by those names", many.join(", ")), false), - } - match rasters { - [] => {} - [one] => s.notify(format!("{one} lost its mask: {map} has no raster layer by that name"), false), - many => s.notify(format!("{} lost their masks: {map} has no raster layers by those names", many.join(", ")), false), + for (kind, layers) in [("polygon", polygons), ("raster", rasters)] { + let text = match layers { + [] => continue, + [one] => format!("{one} lost its mask: {map} has no {kind} layer by that name"), + many => format!("{} lost their masks: {map} has no {kind} layers by those names", many.join(", ")), + }; + s.notify_loss(LossCode::DroppedMask, text.into()); } } } diff --git a/crates/engine/src/cmd/sharing.rs b/crates/engine/src/cmd/sharing.rs index 9b94801409..7e1facfa25 100644 --- a/crates/engine/src/cmd/sharing.rs +++ b/crates/engine/src/cmd/sharing.rs @@ -246,7 +246,7 @@ pub(crate) fn share_output( } _ => Vec::new(), }; - let (name, bytes, source) = super::share::saying_shadows(s, what, |s| share_bytes_inner(s, kind, p, out))?; + let (name, bytes, source) = super::share::saying_shadows(s, what, |s| share_bytes_inner(s, kind, p, out, MAX_FEATURES))?; Ok((name, bytes, source, notes)) } @@ -277,7 +277,14 @@ impl Unplaced { } /// Build the saved payload for each share kind; web tools carry capabilities of their steps. -fn share_bytes_inner(s: &mut Session, kind: &str, p: &Value, out: Output<'_>) -> Result<(String, Vec, String), String> { +fn share_bytes_inner( + s: &mut Session, + kind: &str, + p: &Value, + out: Output<'_>, + feature_limit: usize, +) -> Result<(String, Vec, String), String> { + use rustgis_data::loss::LossCode; // The features read whole so far, which a download's reads are held to together. let mut held = 0; match kind { @@ -286,10 +293,13 @@ fn share_bytes_inner(s: &mut Session, kind: &str, p: &Value, out: Output<'_>) -> m.layers.iter_mut().filter(|l| shared_layer("webMap", l)).try_for_each(|l| load_whole(s, l, out, &mut held))?; let mut unplaced = Unplaced::default(); let mut limited = 0usize; - let html = out.file(|w| write_web_map(w, &m, &m.name, &mut unplaced, &mut limited))?; + let html = out.file(|w| write_web_map(w, &m, &m.name, &mut unplaced, &mut limited, feature_limit))?; unplaced.say(s, "The web map"); if limited > 0 { - s.notify(format!("{limited} feature(s) left out of the web map: the {MAX_FEATURES} feature limit was reached"), false); + s.notify_loss( + LossCode::DroppedOverLimit, + format!("{limited} feature(s) left out of the web map: the {feature_limit} feature limit was reached").into(), + ); } Ok((m.name.clone(), html, m.name)) } @@ -298,12 +308,13 @@ fn share_bytes_inner(s: &mut Session, kind: &str, p: &Value, out: Output<'_>) -> load_whole(s, &mut l, out, &mut held)?; let mut unplaced = Unplaced::default(); let mut limited = 0usize; - let zip = web_layer_zip(s, &l, &mut unplaced, &mut limited, out)?; + let zip = web_layer_zip(s, &l, &mut unplaced, &mut limited, out, feature_limit)?; unplaced.say(s, "The web layer"); if limited > 0 { - s.notify( - format!("{limited} feature(s) left out of the web layer's viewer page: the {MAX_FEATURES} feature limit was reached"), - false, + s.notify_loss( + LossCode::DroppedOverLimit, + format!("{limited} feature(s) left out of the web layer's viewer page: the {feature_limit} feature limit was reached") + .into(), ); } Ok((l.name.clone(), zip, l.name.clone())) @@ -319,10 +330,13 @@ fn share_bytes_inner(s: &mut Session, kind: &str, p: &Value, out: Output<'_>) -> p.get("fields").and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_str).map(str::to_string).collect()); let mut unplaced = Unplaced::default(); let mut limited = 0usize; - let loc = locator(&l, fields.as_deref(), &mut unplaced, &mut limited, out)?; + let loc = locator(&l, fields.as_deref(), &mut unplaced, &mut limited, out, feature_limit)?; unplaced.say(s, "The locator"); if limited > 0 { - s.notify(format!("{limited} feature(s) left out of the locator: the {MAX_FEATURES} feature limit was reached"), false); + s.notify_loss( + LossCode::DroppedOverLimit, + format!("{limited} feature(s) left out of the locator: the {feature_limit} feature limit was reached").into(), + ); } Ok((l.name.clone(), out.json(&loc)?, l.name.clone())) } @@ -725,9 +739,16 @@ fn styled_features( /// Mercator, with pan, zoom, a layer list and pop-ups. No libraries or server. Its layers are /// written to `page` as they are made, so a page held to a limit stops there. /// Visible features past the page's feature limit are counted in `limited`. -fn write_web_map(page: &mut dyn std::io::Write, m: &Map, title: &str, unplaced: &mut Unplaced, limited: &mut usize) -> Result<(), String> { +fn write_web_map( + page: &mut dyn std::io::Write, + m: &Map, + title: &str, + unplaced: &mut Unplaced, + limited: &mut usize, + feature_limit: usize, +) -> Result<(), String> { let failed = |e: std::io::Error| e.to_string(); - let mut budget = MAX_FEATURES; + let mut budget = feature_limit; let mut pictures = 0usize; let mut separator = ""; write!( @@ -1087,7 +1108,14 @@ fn ogc_entries(parts: &mut Parts<'_>, title: &str, layers: &[&Dataset], unplaced } /// A web layer: the layer as an OGC API Features collection, its style, and a viewer page. -fn web_layer_zip(s: &Session, l: &Layer, unplaced: &mut Unplaced, limited: &mut usize, out: Output<'_>) -> Result, String> { +fn web_layer_zip( + s: &Session, + l: &Layer, + unplaced: &mut Unplaced, + limited: &mut usize, + out: Output<'_>, + feature_limit: usize, +) -> Result, String> { let mut parts = out.parts(); ogc_entries(&mut parts, &l.name, &[&l.dataset], unplaced)?; parts.make("style.json".into(), |w| serde_json::to_writer_pretty(w, &web_style(l)).map_err(|e| e.to_string()))?; @@ -1108,21 +1136,10 @@ fn web_layer_zip(s: &Session, l: &Layer, unplaced: &mut Unplaced, limited: &mut m.camera.clamp(); } // The page's features are the same, already counted by the collection. - parts.make("index.html".into(), |w| write_web_map(w, &m, &l.name, &mut Unplaced::default(), limited))?; + parts.make("index.html".into(), |w| write_web_map(w, &m, &l.name, &mut Unplaced::default(), limited, feature_limit))?; parts.zip() } -/// Whether `g` has no coordinates at all (an empty extent), found from its parts without reading -/// every vertex. -fn geometry_is_empty(g: &Geometry) -> bool { - match g { - Geometry::Point(_) => false, - Geometry::MultiPoint(points) => points.is_empty(), - Geometry::Line(parts) => parts.iter().all(Vec::is_empty), - Geometry::Polygon(polygons) => polygons.iter().all(|rings| rings.iter().all(Vec::is_empty)), - } -} - /// A locator: searchable place names and where they are. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Locator { @@ -1132,7 +1149,14 @@ pub struct Locator { pub entries: Vec<(String, f64, f64)>, } -fn locator(l: &Layer, fields: Option<&[String]>, unplaced: &mut Unplaced, limited: &mut usize, out: Output<'_>) -> Result { +fn locator( + l: &Layer, + fields: Option<&[String]>, + unplaced: &mut Unplaced, + limited: &mut usize, + out: Output<'_>, + feature_limit: usize, +) -> Result { let ds = &l.dataset; let fis: Vec = match fields { Some(fs) => { @@ -1149,12 +1173,25 @@ fn locator(l: &Layer, fields: Option<&[String]>, unplaced: &mut Unplaced, limite let mut held = 0usize; let mut taken = 0usize; for (row, ft) in ds.features.iter().enumerate() { - if taken >= MAX_FEATURES { - // Rows with no geometry or an empty one were never going to be in the locator. Told - // apart by their parts, not their vertices, so this pass stays cheap. It has no Cancel - // check, like the rest of `share.locator`, which runs on the UI thread (not in - // `exports::IN_BACKGROUND`). - *limited = ds.features.rows().skip(row).filter(|ft| ft.geometry().is_some_and(|g| !geometry_is_empty(g))).count(); + if taken >= feature_limit { + // A row without a place (no geometry, or an empty extent, as a point with a NaN + // coordinate has) or a search term has no locator entry to omit, as below. Like the + // rest of share.locator, this pass runs on the UI thread (not in + // exports::IN_BACKGROUND) and has no Cancel check. + *limited = ds + .features + .rows() + .enumerate() + .skip(row) + .filter(|(i, ft)| { + ft.geometry().is_some_and(|g| !g.extent().is_empty()) + && fis.iter().any(|&fi| match ds.value(*i, fi) { + rustgis_data::Value::Null => false, + rustgis_data::Value::Text(text) => !text.trim().is_empty(), + _ => true, + }) + }) + .count(); break; } let Some(g) = &ft.geometry else { continue }; @@ -1250,8 +1287,7 @@ struct SceneBytes { impl SceneBytes { /// The same counted explanations accompany a usable scene and an empty-result error. Features - /// left out are losses, with their codes; rings and line parts with too few vertices hold no - /// area or length to lose, and fanned caps and held heights say how the scene draws them. + /// and nonempty geometry parts left out are losses, with their codes. fn notes(&self) -> Vec { use rustgis_data::loss::{LossCode, Note}; let mut notes = Vec::new(); @@ -1277,13 +1313,19 @@ impl SceneBytes { )); } if self.skipped_outer > 0 { - notes.push(Note::plain(format!("Skipped {} polygon(s) whose outer ring has fewer than 3 vertices", self.skipped_outer))); + notes.push(Note::loss( + LossCode::DroppedGeometry, + format!("Skipped {} polygon(s) whose outer ring has fewer than 3 vertices", self.skipped_outer), + )); } if self.holes_dropped > 0 { - notes.push(Note::plain(format!("Dropped {} hole(s) with fewer than 3 vertices", self.holes_dropped))); + notes.push(Note::loss(LossCode::DroppedRing, format!("Dropped {} hole(s) with fewer than 3 vertices", self.holes_dropped))); } if self.single_vertex_lines > 0 { - notes.push(Note::plain(format!("Skipped {} line part(s) with a single vertex", self.single_vertex_lines))); + notes.push(Note::loss( + LossCode::DroppedGeometry, + format!("Skipped {} line part(s) with a single vertex", self.single_vertex_lines), + )); } for (layer, n) in &self.held { notes.push(Note::plain(format!( @@ -1418,10 +1460,10 @@ fn gltf(m: &Map, view: (f64, f64), out: Output<'_>) -> Result= 3) else { - scene.skipped_outer += 1; + scene.skipped_outer += usize::from(open.iter().any(|r| !r.is_empty())); continue; }; - scene.holes_dropped += open.iter().skip(1).filter(|r| r.len() < 3).count(); + scene.holes_dropped += open.iter().skip(1).filter(|r| !r.is_empty() && r.len() < 3).count(); let open: Vec> = std::iter::once(outer.clone()).chain(open.iter().skip(1).filter(|r| r.len() >= 3).cloned()).collect(); let Some(outer) = open.first() else { continue }; @@ -2029,3 +2071,31 @@ fn style_inputs(input: &super::InputContext<'_>, p: &Value) -> Result, p: &Value) -> Result { share_kind_inputs(input, p, "locator") } + +#[cfg(test)] +mod tests { + use super::*; + use rustgis_data::loss::LossCode; + use rustgis_data::{Dataset, Field, FieldType, GeometryType, Value as Attr}; + + #[test] + fn web_shares_and_locator_code_their_feature_limits() { + let mut ds = Dataset::new("Places", GeometryType::Point, vec![Field::new("name", FieldType::Text)]); + for (i, text) in ["First", "Second", "Third", " ", ""].into_iter().enumerate() { + ds.push(Some(Geometry::Point(Coord::new(i as f64, 0.0))), vec![Attr::Text(text.into())]); + } + ds.push(Some(Geometry::Point(Coord::new(5.0, 0.0))), vec![Attr::Null]); + let mut s = Session::new(crate::Project::default()); + s.map_mut().add_dataset(ds); + for (kind, output, omitted) in [("webMap", "web map", 4), ("webLayer", "web layer's viewer page", 4), ("locator", "locator", 1)] { + let params = json!({"layer": "Places"}); + let mark = s.notice_mark(); + share_bytes_inner(&mut s, kind, ¶ms, Output::UNLIMITED, 6).unwrap(); + assert!(!s.notices_since(mark).iter().any(|n| n.loss() == Some(LossCode::DroppedOverLimit)), "{kind}"); + share_bytes_inner(&mut s, kind, ¶ms, Output::UNLIMITED, 2).unwrap(); + let name = format!("{omitted} feature(s) left out of the {output}: the 2 feature limit was reached"); + let notices = s.notices_since(mark); + assert_eq!(notices.iter().filter(|n| n.loss() == Some(LossCode::DroppedOverLimit) && n.text == name).count(), 1, "{notices:?}"); + } + } +} diff --git a/crates/engine/src/cmd/workflows.rs b/crates/engine/src/cmd/workflows.rs index 0d915b6097..079eb8fc39 100644 --- a/crates/engine/src/cmd/workflows.rs +++ b/crates/engine/src/cmd/workflows.rs @@ -2397,13 +2397,16 @@ fn interpolate_work(s: &Session, p: &Value) -> Result { why.push(format!("{no_value} whose {field_name} isn't a number")); } if !why.is_empty() { - s.notify(format!("{layer_name}: features left out of the surface: {}", why.join(", ")), false); + s.notify_loss( + rustgis_data::loss::LossCode::DroppedFeature, + format!("{layer_name}: features left out of the surface: {}", why.join(", ")).into(), + ); if let Some(o) = v.as_object_mut() { o.insert("skipped".into(), json!({"noPoint": no_point, "noValue": no_value})); } } if let Some(note) = beyond_note { - s.notify(format!("{layer_name}: {note}"), false); + s.notify_loss(rustgis_data::loss::LossCode::DroppedFeature, format!("{layer_name}: {note}").into()); } // It names the layer itself. if let Some(note) = crs_note { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 9ec6a43f0b..b157d3c036 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -44358,8 +44358,11 @@ fn layers_are_copied_and_pasted_between_maps() { let copy = second.layer_by_name("Cities copy").unwrap(); assert_eq!((copy.mask.as_deref(), second.group_of(copy.id).is_none()), (Some("Countries"), true)); s.run("map.new", &json!({"name": "Third"})).unwrap(); + let mark = s.notice_mark(); let r = s.run("layer.paste", &Value::Null).unwrap(); assert_eq!((r["unmasked"].clone(), s.map().layers[0].mask.clone()), (json!(["Cities"]), None)); + assert!(s.notices_since(mark).iter().any(|n| n.loss() == Some(rustgis_data::loss::LossCode::DroppedMask) + && n.text == "Cities lost its mask: Third has no polygon layer by that name")); // Only a polygon layer masks (as the renderer finds it): a point layer of that name doesn't. s.run("layer.rename", &json!({"layer": "Cities", "name": "Countries"})).unwrap(); let r = s.run("layer.paste", &Value::Null).unwrap(); @@ -59489,7 +59492,12 @@ fn layer_meshes_report_single_vertex_lines_and_skip_heights_of_empty_features() s.notices.clear(); crate::cmd::items::item_bytes(&mut s, kind, &json!({"heightField": "h"})).unwrap(); let said = |part: &str| s.notices.iter().any(|n| n.text.contains(part)); - assert!(said("Skipped 1 line part(s) with a single vertex"), "{kind}"); + assert!( + s.notices.iter().any(|n| n.loss() == Some(rustgis_data::loss::LossCode::DroppedGeometry) + && n.text == "Skipped 1 line part(s) with a single vertex"), + "{kind}: {:?}", + s.notices + ); assert!(!said("default height"), "{kind}"); } // A layer whose only line has one vertex says why STL has nothing. @@ -59500,23 +59508,34 @@ fn layer_meshes_report_single_vertex_lines_and_skip_heights_of_empty_features() #[test] fn layer_meshes_say_what_they_leave_out_or_default() { - // A hole of two vertices is dropped, and a height that isn't a number takes the default. + // Count a hole of two vertices and a short polygon part. Empty rings and + // parts contain nothing to lose. A nonnumeric height takes the default. let two_vertex_hole = json!({"type": "Polygon", "coordinates": [ [[0.0, 0.0], [0.01, 0.0], [0.01, 0.01], [0.0, 0.01], [0.0, 0.0]], - [[0.002, 0.002], [0.003, 0.003], [0.002, 0.002]]]}); + [[0.002, 0.002], [0.003, 0.003], [0.002, 0.002]], []]}); + use rustgis_data::loss::LossCode; + let short = json!({"type": "MultiPolygon", "coordinates": [[[[0.04, 0.0], [0.05, 0.01], [0.04, 0.0]]], []]}); let mut s = mesh_session(json!([ mesh_feature(two_vertex_hole, 30.0), + mesh_feature(short, 30.0), {"type": "Feature", "geometry": square(0.02, false), "properties": {"h": "tall"}}, ])); - crate::cmd::items::item_bytes(&mut s, "stl", &json!({"heightField": "h"})).unwrap(); - let said = |part: &str| s.notices.iter().any(|n| n.text.contains(part)); - assert!(said("Dropped 1 hole(s)")); - assert!(said("used the default height")); + for kind in ["obj", "stl"] { + s.notices.clear(); + crate::cmd::items::item_bytes(&mut s, kind, &json!({"heightField": "h"})).unwrap(); + for (prefix, code) in [ + ("Dropped 1 hole(s)", Some(LossCode::DroppedRing)), + ("Skipped 1 polygon(s)", Some(LossCode::DroppedGeometry)), + ("1 feature(s) without a numeric height", None), + ] { + assert!(s.notices.iter().any(|n| n.text.starts_with(prefix) && n.loss() == code), "{kind}: {:?}", s.notices); + } + } // Clean input says neither, for OBJ or STL. let mut clean = mesh_session(json!([mesh_feature(square(0.0, false), 30.0)])); crate::cmd::items::item_bytes(&mut clean, "obj", &json!({"heightField": "h"})).unwrap(); crate::cmd::items::item_bytes(&mut clean, "stl", &json!({"heightField": "h"})).unwrap(); - assert!(!clean.notices.iter().any(|n| n.text.contains("hole") || n.text.contains("default height"))); + assert!(clean.notices.iter().all(|n| n.loss().is_none() && !n.text.contains("default height")), "{:?}", clean.notices); } #[test] @@ -60993,10 +61012,13 @@ fn interpolation_says_the_features_it_leaves_out() { let mark = s.notice_mark(); let v = s.run("analysis.interpolate", &json!({"layer": "lossy wells", "field": "depth", "cellSize": 0.5})).unwrap(); assert_eq!(v["skipped"], json!({"noPoint": 2, "noValue": 1}), "{v}"); - let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("left out")).map(|n| n.text.clone()).collect(); + let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("left out")).map(|n| (n.text.as_str(), n.loss())).collect(); assert_eq!( said, - ["lossy wells: features left out of the surface: 2 with no geometry or no usable point, 1 whose depth isn't a number"] + [( + "lossy wells: features left out of the surface: 2 with no geometry or no usable point, 1 whose depth isn't a number", + Some(rustgis_data::loss::LossCode::DroppedFeature), + )] ); // A surface with no usable points left fails, and the error says what was left out. @@ -61150,7 +61172,8 @@ fn interpolation_in_a_projected_coordinate_system() { polar.push(Some(Geometry::Point(Coord::new(x, y))), vec![V::Float(depth)]); } crate::cmd::layer::add_dataset(&mut s, polar); - let (crs, _, notices) = surface(&mut s, json!({"layer": "polar", "field": "depth", "crs": "EPSG:3857"})); + let mark = s.notice_mark(); + let (crs, _, _) = surface(&mut s, json!({"layer": "polar", "field": "depth", "crs": "EPSG:3857"})); assert_eq!(crs, Crs::WebMercator); // Both points left make it: its values reach from near one's to near the other's. let polar = s.map().layer_by_name("polar_depth_idw").unwrap().raster.as_ref().unwrap().data.clone().unwrap(); @@ -61159,7 +61182,11 @@ fn interpolation_in_a_projected_coordinate_system() { assert!(low < 12.0 && high > 18.0 && high <= 20.0, "{low}..{high}"); let label = Crs::WebMercator.label(); let beyond = format!("polar: 1 point(s) beyond what {label} can hold (past 85.05° of latitude) were left out"); - assert!(notices.contains(&beyond), "{notices:?}"); + assert!( + s.notices_since(mark).iter().any(|n| n.text == beyond && n.loss() == Some(rustgis_data::loss::LossCode::DroppedFeature)), + "{:?}", + s.notices_since(mark) + ); // A run that fails still names an environment cell size it didn't use. let mut arctic = Dataset::new("arctic", GeometryType::Point, vec![Field::new("depth", FieldType::Double)]); for (x, y, depth) in [(0.0, 88.0, 1.0), (10.0, 89.0, 2.0)] { diff --git a/crates/engine/src/tests/engine_guards.rs b/crates/engine/src/tests/engine_guards.rs index d440b56ca4..42823bc4c5 100644 --- a/crates/engine/src/tests/engine_guards.rs +++ b/crates/engine/src/tests/engine_guards.rs @@ -550,10 +550,11 @@ fn web_map_and_locator_notify_when_feature_limit_is_reached() { "webMap must emit counted limit notice: {web_notices:?}" ); - // Rows the locator would leave out anyway (no geometry, an empty one) aren't counted as cut by - // the limit. + // Rows the locator would leave out anyway (no geometry, an empty one, a point with a NaN + // coordinate) aren't counted as cut by the limit. let places = &mut big.map_mut().layers[0].dataset; - for (id, geometry) in [(300_001, None), (300_002, Some(Geometry::MultiPoint(Vec::new())))] { + let nan = Some(Geometry::Point(Coord::new(f64::NAN, 1.0))); + for (id, geometry) in [(300_001, None), (300_002, Some(Geometry::MultiPoint(Vec::new()))), (300_003, nan)] { places.features.push(Feature { id, geometry, attrs: vec![AttrValue::Text("p".into())] }); } let mark = big.notice_mark(); diff --git a/crates/engine/src/tests/raster_mask.rs b/crates/engine/src/tests/raster_mask.rs index 26bccf8cca..097ccc9f46 100644 --- a/crates/engine/src/tests/raster_mask.rs +++ b/crates/engine/src/tests/raster_mask.rs @@ -125,8 +125,12 @@ fn a_pasted_layer_takes_its_raster_mask_to_the_raster_of_that_name() { let mark = s.notice_mark(); let r = s.run("layer.paste", &Value::Null).unwrap(); assert_eq!((r["unmasked"].clone(), mask_of(&s, "Countries")), (json!(["Countries"]), None)); - let said: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); - assert!(said.iter().any(|n| n.contains("Countries lost its mask") && n.contains("no raster layer")), "{said:?}"); + let said = s.notices_since(mark); + assert!( + said.iter().any(|n| n.loss() == Some(rustgis_data::loss::LossCode::DroppedMask) + && n.text == "Countries lost its mask: Second has no raster layer by that name"), + "{said:?}" + ); } /// A pasted layer is never its own mask: renamed on paste to its mask's name, it isn't found as diff --git a/crates/engine/src/tests/said_not_silent.rs b/crates/engine/src/tests/said_not_silent.rs index 3a65b57889..ac44b50619 100644 --- a/crates/engine/src/tests/said_not_silent.rs +++ b/crates/engine/src/tests/said_not_silent.rs @@ -82,7 +82,9 @@ fn numbered_bookmarks_and_pasted_layers_say_their_cuts() { s.run("layer.copy", &json!({"layer": [layer, "Rivers"]})).unwrap(); let mark = s.notice_mark(); s.run("layer.paste", &json!({})).unwrap(); - assert!(says(&s, mark, "Paste Layers: 1 copied name(s) cut"), "{:?}", said(&s, mark)); + let notices = s.notices_since(mark); + assert!(notices.iter().any(|n| n.loss() == Some(rustgis_data::loss::LossCode::ChangedCut) + && n.text.starts_with("Paste Layers: 1 copied name(s) cut")), "{notices:?}"); let mark = s.notice_mark(); s.run("layer.copy", &json!({"layer": "Rivers"})).unwrap(); s.run("layer.paste", &json!({})).unwrap(); diff --git a/crates/engine/src/tests/scene_losses.rs b/crates/engine/src/tests/scene_losses.rs index ae8ba055f3..6397cf8612 100644 --- a/crates/engine/src/tests/scene_losses.rs +++ b/crates/engine/src/tests/scene_losses.rs @@ -1,5 +1,6 @@ use super::{mesh_feature, mesh_session, square}; use crate::{Project, Session}; +use rustgis_data::loss::LossCode; use rustgis_data::{Coord, Dataset, Field, FieldType, Geometry, GeometryType, Value as Attr}; use serde_json::{Value, json}; @@ -29,10 +30,10 @@ fn positions(doc: &Value) -> u64 { #[test] fn web_scene_reports_degenerate_parts_and_preserves_clean_geometry() { - let short = json!({"type":"Polygon", "coordinates":[[[0.0,0.0],[0.01,0.01],[0.0,0.0]]]}); + let short = json!({"type":"MultiPolygon", "coordinates":[[[[0.0,0.0],[0.01,0.01],[0.0,0.0]]], []]}); let hole = json!({"type":"Polygon", "coordinates":[ [[0.0,0.0],[0.01,0.0],[0.01,0.01],[0.0,0.01],[0.0,0.0]], - [[0.002,0.002],[0.003,0.003],[0.002,0.002]] + [[0.002,0.002],[0.003,0.003],[0.002,0.002]], [] ]}); let line = json!({"type":"LineString", "coordinates":[[0.0,0.0]]}); let mut s = mesh_session(json!([ @@ -42,12 +43,12 @@ fn web_scene_reports_degenerate_parts_and_preserves_clean_geometry() { mesh_feature(square(0.02, false), 30.0) ])); let doc = scene(&mut s, "parts"); - for expected in [ - "Skipped 1 polygon(s) whose outer ring has fewer than 3 vertices", - "Dropped 1 hole(s) with fewer than 3 vertices", - "Skipped 1 line part(s) with a single vertex", + for (expected, code) in [ + ("Skipped 1 polygon(s) whose outer ring has fewer than 3 vertices", LossCode::DroppedGeometry), + ("Dropped 1 hole(s) with fewer than 3 vertices", LossCode::DroppedRing), + ("Skipped 1 line part(s) with a single vertex", LossCode::DroppedGeometry), ] { - assert_eq!(s.notices.iter().filter(|n| n.text == expected).count(), 1, "{expected}: {:?}", s.notices); + assert_eq!(s.notices.iter().filter(|n| n.text == expected && n.loss() == Some(code)).count(), 1, "{expected}: {:?}", s.notices); } assert_eq!(positions(&doc), 8, "the two valid squares, with the short hole omitted"); let mut clean = mesh_session(json!([mesh_feature(square(0.0, false), 30.0)])); diff --git a/docs/user-guide/loss-codes.md b/docs/user-guide/loss-codes.md index d586525032..2107d7210c 100644 --- a/docs/user-guide/loss-codes.md +++ b/docs/user-guide/loss-codes.md @@ -28,7 +28,7 @@ A map service offered legend pictures that RustGIS does not show, so they were l A polygon ring was left out. Rings that could not be read, or that have no area, are skipped, and a format with no holes keeps only the outer edge of each polygon. -**Where you see it:** reading GeoRSS, GML, DXF or MapInfo data, or feature service answers in PBF; exporting polygons to GPX (their holes are left out). +**Where you see it:** reading GeoRSS, GML, DXF or MapInfo data, or feature service answers in PBF; exporting polygons to GPX, or exporting 3D models and web scenes. **What to do:** Correct the unreadable polygon ring in the source, or write to a format that holds holes, such as GeoPackage. @@ -116,7 +116,7 @@ The date the coordinates are valid at (the coordinate epoch) was not kept, so po Whole features, rows or items were left out because they could not be read or are not supported. -**Where you see it:** reading GeoRSS, OpenStreetMap, spreadsheet, GRIB or point-cloud (LAS and LAZ) files. +**Where you see it:** reading GeoRSS, OpenStreetMap, spreadsheet, GRIB or point-cloud (LAS and LAZ) files, and running the Geostatistical Wizard. **What to do:** Correct those features in the source, or read the source in the way the notice suggests. @@ -124,17 +124,25 @@ Whole features, rows or items were left out because they could not be read or ar A feature's geometry could not be read or written. The feature was kept without its place, or the place was left out. -**Where you see it:** reading CSV with WKT, GPX, TopoJSON or MapInfo data; exporting layers with a place the target coordinate system cannot hold; Repair Geometry. +**Where you see it:** reading CSV with WKT, GPX, TopoJSON or MapInfo data; exporting layers with a place the target coordinate system cannot hold; exporting 3D models and web scenes, or running Repair Geometry, IDW Interpolation or Ordinary Kriging. **What to do:** Correct the geometry in the source; when the notice names a coordinate system, give the one its coordinates are in. +### `dropped.mask` { #dropped.mask } + +A layer's mask was cleared because the destination map has no compatible mask layer by that name. + +**Where you see it:** Paste Layers and Add Layer File. + +**What to do:** Copy or add the mask layer with the layer it masks. + ### `dropped.over-limit` { #dropped.over-limit } -RustGIS read only part of the data because it is past a size limit. +RustGIS included only part of the data because it is past a size limit. -**Where you see it:** reading point-cloud (LAS and LAZ), DXF, GML, KML or photo data, or a raster with a very long list of class names. +**Where you see it:** reading point-cloud (LAS and LAZ), DXF, GML, KML or photo data, a raster with a very long list of class names, or sharing a web map, web layer viewer, web scene or locator. -**What to do:** Read less at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it. +**What to do:** Use less data at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it. ## Changed @@ -168,7 +176,7 @@ A field name was changed to fit the format it was written to, or prefixed with a Text was cut short to fit a format or a limit. -**Where you see it:** exporting to Shapefile (254 bytes per value); labels and annotations; reading raster band or class names. +**Where you see it:** exporting to Shapefile (254 bytes per value); labels and annotations; reading raster band or class names; Paste Layers and Add Layer File. **What to do:** Shorten the text or name in the source; on export, to what the format holds (254 bytes for a Shapefile; nothing past a NUL character), or write to a format without the limit, such as GeoPackage.