From fe91c3d980e8a813b2cb87c3bb739be2b507db7f Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 22:17:25 -0600 Subject: [PATCH 1/4] feat(engine): a QGIS import gives loss codes for the layers it leaves out (#2371) --- crates/engine/src/cmd/qgis.rs | 83 +++++++++++++++++----- crates/engine/src/tests.rs | 37 ++++++++++ crates/engine/src/tests/qgis_services.rs | 10 ++- crates/map/src/qgis/mod.rs | 89 ++++++++++++++---------- 4 files changed, 164 insertions(+), 55 deletions(-) diff --git a/crates/engine/src/cmd/qgis.rs b/crates/engine/src/cmd/qgis.rs index 93a66af867..6264fa399e 100644 --- a/crates/engine/src/cmd/qgis.rs +++ b/crates/engine/src/cmd/qgis.rs @@ -3,6 +3,7 @@ //! `style.importQgis` gives a layer a `.qml` style. Both say what they couldn't carry over //! (`rustgis_map::qgis::Report`). +use rustgis_data::loss::LossCode; use rustgis_geom::{Coord, Extent}; use rustgis_map::qgis::{self, NoteKind, Report, Source, listed}; use serde_json::{Value, json}; @@ -268,7 +269,10 @@ fn import_project(s: &mut Session, p: &Value) -> CmdResult { } } Ok(None) => {} - Err(e) => report.skipped(&layer.name, format!("the layer: {e}")), + // A layer whose data wasn't read is data the import left out; an annotation layer is + // drawing only. + Err(e) if layer.kind == "annotation" => report.skipped(&layer.name, format!("the layer: {e}")), + Err(e) => report.lost(&layer.name, NoteKind::Skipped, LossCode::DroppedFeature, format!("the layer: {e}")), } } note_texts_under_layers_above(&drawn, &mut report); @@ -427,12 +431,22 @@ fn add_layer( let name = layer.name.as_str(); if let Source::File { path, .. } | Source::Csv { path, .. } | Source::Archive { path, .. } = &layer.source { if !has_dir && qgis::is_relative(path) { - report.skipped(name, format!("the file {path}, relative to the project's folder, which the import wasn't given (pass dir)")); + report.lost( + name, + NoteKind::Skipped, + LossCode::DroppedFeature, + format!("the file {path}, relative to the project's folder, which the import wasn't given (pass dir)"), + ); return Ok(None); } // `C:roads.gpkg`: relative to the working directory on drive C, which no folder fixes. if qgis::is_drive_relative(path) { - report.skipped(name, format!("the file {path}, relative to a drive's working directory (give a full path in QGIS)")); + report.lost( + name, + NoteKind::Skipped, + LossCode::DroppedFeature, + format!("the file {path}, relative to a drive's working directory (give a full path in QGIS)"), + ); return Ok(None); } } @@ -487,8 +501,10 @@ fn add_layer( let share = path.starts_with("file://") || path.starts_with("\\\\") || path.starts_with("//"); if share || (*kind == "mbtiles" && path.contains("://")) { let at = if share { "on a network share" } else { "at a web address" }; - report.skipped( + report.lost( name, + NoteKind::Skipped, + LossCode::DroppedFeature, format!( "the tile archive {at}: RustGIS reads MBTiles files on this computer, and PMTiles archives there or on the web" ), @@ -499,13 +515,17 @@ fn add_layer( // no file by its path. #[cfg(not(target_arch = "wasm32"))] if !path.contains("://") && !std::path::Path::new(path).is_file() { - report.skipped(name, format!("the tile archive {path}: no file there")); + report.lost(name, NoteKind::Skipped, LossCode::DroppedFeature, format!("the tile archive {path}: no file there")); return Ok(None); } #[cfg(target_arch = "wasm32")] if !path.contains("://") { - report - .skipped(name, format!("the tile archive {path}, a file the browser doesn't read by its path (add it with Add Data)")); + report.lost( + name, + NoteKind::Skipped, + LossCode::DroppedFeature, + format!("the tile archive {path}, a file the browser doesn't read by its path (add it with Add Data)"), + ); return Ok(None); } let before = s.active_layer; @@ -539,7 +559,8 @@ fn add_layer( return Ok(Some(name.to_string())); } Source::Memory { geometry, crs, fields, as_text: (as_text, texts), cut, unnamed, taken, zm, curved, unknown_geometry } => { - // QGIS keeps none of a memory layer's features: it opens empty, with its fields. + // QGIS keeps none of a memory layer's features: it opens empty, with its fields, so + // what these notes leave out held no data, and they stay plain. let mut ds = rustgis_data::Dataset::new(name, *geometry, fields.clone()); if let Some(c) = layer.crs.as_deref().or(crs.as_deref()) { match rustgis_data::raster::crs::Crs::parse(c) { @@ -589,7 +610,7 @@ fn add_layer( } None => "RustGIS reads one that selects every column of one layer, with or without a WHERE clause, as that layer".into(), }; - report.skipped(name, format!("the virtual layer `{shown}{more}`: {why}")); + report.lost(name, NoteKind::Skipped, LossCode::DroppedFeature, format!("the virtual layer `{shown}{more}`: {why}")); return Ok(None); } Source::Wms { url, layer: wms, wmts, options, .. } => { @@ -709,7 +730,13 @@ fn add_layer( Source::Other { provider } => { // A layer of no provider (an annotation layer, a group layer) is told by its kind. let what = if provider.is_empty() { format!("{} layers", layer.kind) } else { format!("{provider} sources") }; - report.skipped(name, format!("the layer: RustGIS doesn't read QGIS's {what}")); + // A layer of no provider (an annotation or group layer) holds no data; any other + // layer's data is left out. + if provider.is_empty() { + report.skipped(name, format!("the layer: RustGIS doesn't read QGIS's {what}")); + } else { + report.lost(name, NoteKind::Skipped, LossCode::DroppedFeature, format!("the layer: RustGIS doesn't read QGIS's {what}")); + } return Ok(None); } } @@ -841,7 +868,7 @@ fn database_note( format!("the {what} table {table} ({connection}): connect to the database to add it{refused}{}", left("the connection text")) } }; - report.skipped(name, text); + report.lost(name, NoteKind::Skipped, LossCode::DroppedFeature, text); } /// The name of the saved connection to the database `connection` names (QGIS's `key=value` @@ -1931,7 +1958,11 @@ impl Geographic { } fn note_json(n: &qgis::Note) -> Value { - json!({"layer": n.layer, "kind": n.kind, "text": n.text, "count": n.count}) + let mut note = json!({"layer": n.layer, "kind": n.kind, "text": n.text, "count": n.count}); + if let (Some(code), Some(note)) = (n.loss, note.as_object_mut()) { + note.insert("loss".into(), json!(code.spec().id)); + } + note } /// The returned report serves CLI and Python callers; the app also needs every coalesced @@ -1945,15 +1976,33 @@ fn notify_report(s: &mut Session, report: &Report) { } text }; + // A notice is about one kind of note and one loss code, so a note that reports a loss never + // shares a notice with a plain one (or with another code's): plain notes first, then each + // code in the order its first note came. + let mut groups: Vec<(NoteKind, Option)> = Vec::new(); for kind in [NoteKind::Approximated, NoteKind::Skipped] { - let notes: Vec<_> = report.notes.iter().filter(|note| note.kind == kind).collect(); + for note in report.notes.iter().filter(|note| note.kind == kind) { + if !groups.contains(&(kind, note.loss)) { + groups.push((kind, note.loss)); + } + } + } + groups.sort_by_key(|(kind, loss)| (*kind == NoteKind::Skipped, loss.is_some())); + let say = |s: &mut Session, loss: Option, text: crate::notice_text::NoticeText| match loss { + Some(code) => s.notify_loss(code, text), + None => s.notify_text(text, false), + }; + for (kind, loss) in groups { + let notes: Vec<_> = report.notes.iter().filter(|note| note.kind == kind && note.loss == loss).collect(); let Some(first) = notes.first() else { continue }; if notes.len() == 1 { let template = match kind { NoteKind::Approximated => "QGIS import, {layer}: {detail} (drawn differently; count {count})", NoteKind::Skipped => "QGIS import, {layer}: {detail} (left out; count {count})", }; - s.notify_text( + say( + s, + loss, crate::notice_text::NoticeText::format( template, [ @@ -1962,7 +2011,6 @@ fn notify_report(s: &mut Session, report: &Report) { ("count", first.count.to_string().into()), ], ), - false, ); continue; } @@ -1990,12 +2038,13 @@ fn notify_report(s: &mut Session, report: &Report) { NoteKind::Approximated => "QGIS import: {count} approximations; affected layers: {layers}. {samples}", NoteKind::Skipped => "QGIS import: {count} omissions; affected layers: {layers}. {samples}", }; - s.notify_text( + say( + s, + loss, crate::notice_text::NoticeText::format( template, [("count", count.to_string().into()), ("layers", layers.to_string().into()), ("samples", samples.into())], ), - false, ); } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 6ea0405be9..fe6e079cd2 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -5254,6 +5254,43 @@ fn qgis_import_notices_group_layers_and_bound_the_sample_without_dropping_return assert!(said[0].text.len() < 4096); } +#[test] +fn qgis_import_codes_only_the_notes_that_lose_data() { + use rustgis_data::loss::LossCode; + let mut s = world(); + let layer = |name: &str, provider: &str, source: &str| { + format!( + r#"{name}{name}{provider}{source}"# + ) + }; + let layers = [ + layer("Unsupported", "not-a-provider", "x"), + layer("Heights", "memory", "PointZ?crs=EPSG:4326&field=a:string"), + layer("Arcs", "memory", "CompoundCurve?crs=EPSG:4326&field=a:string"), + ] + .concat(); + let text = format!(r#"{layers}"#); + let mark = s.notice_mark(); + let result = s.run("project.importQgis", &json!({"text": text})).unwrap(); + let notes = result["notes"].as_array().unwrap(); + let json_loss = |layer: &str, text: &str| { + notes.iter().find(|n| n["layer"] == layer && n["text"].as_str().unwrap().contains(text)).map(|n| n["loss"].as_str()) + }; + assert_eq!(json_loss("Unsupported", "RustGIS doesn't read"), Some(Some("dropped.feature"))); + // A memory layer opens empty, so its Z values and curves held no data: plain. + assert_eq!(json_loss("Heights", "Z and M"), Some(None)); + assert_eq!(json_loss("Arcs", "curves read as lines"), Some(None)); + assert_eq!(json_loss("", "print layouts"), Some(None), "a layout is drawing, not data: no code"); + let said = s.notices_since(mark); + let with = |code| said.iter().filter(|n| n.loss() == Some(code)).collect::>(); + assert!(with(LossCode::DroppedFeature)[0].text.contains("Unsupported"), "{said:?}"); + assert!(with(LossCode::DroppedZm).is_empty() && with(LossCode::ApproximatedCurve).is_empty(), "{said:?}"); + let layouts: Vec<_> = said.iter().filter(|n| n.text.contains("print layouts")).collect(); + assert_eq!(layouts.len(), 1); + assert_eq!(layouts[0].loss(), None); + assert!(said.iter().filter(|n| n.loss().is_some()).all(|n| !n.text.contains("print layouts")), "no coded notice holds a plain note"); +} + /// A QGIS categorized renderer by an expression classes by it where the expression reads on the /// layer; where it doesn't, every feature draws with the first category's symbol, noted, as before. #[test] diff --git a/crates/engine/src/tests/qgis_services.rs b/crates/engine/src/tests/qgis_services.rs index d12e52254e..62e3edf408 100644 --- a/crates/engine/src/tests/qgis_services.rs +++ b/crates/engine/src/tests/qgis_services.rs @@ -98,12 +98,16 @@ fn a_qgis_projects_web_service_layers_come_in_from_their_services() { } assert!(notes.contains("the same tiles as Topo, which takes its place"), "{notes}"); // A type the service doesn't list: noted, the others still in. - assert!(notes.contains(r#""kind":"skipped","layer":"Missing","text":"the layer: "#) && notes.contains("no layer 'nope'"), "{notes}"); + assert!( + notes.contains(r#""kind":"skipped","layer":"Missing","loss":"dropped.feature","text":"the layer: "#) + && notes.contains("no layer 'nope'"), + "{notes}" + ); assert!(s.map().layer_by_name("Missing").is_none()); assert_eq!(out["layers"].as_array().map(Vec::len), Some(3), "{out}"); assert!(!notes.contains("abc1234"), "{notes}"); // A map service that doesn't answer is left out: no fall back to its whole map. - assert!(notes.contains(r#""kind":"skipped","layer":"Gone","text":"the layer: "#), "{notes}"); + assert!(notes.contains(r#""kind":"skipped","layer":"Gone","loss":"dropped.feature","text":"the layer: "#), "{notes}"); assert!(!notes.contains("its map layer 1 alone"), "{notes}"); // Two layers of it: its whole map, said as what is drawn, not as an unread setting. assert!( @@ -201,7 +205,7 @@ fn ogc_api_wmts_and_wcs_layers_come_in_from_their_services() { assert_eq!(subsets, ["Long(5.1,5.3)", "Lat(49.5,49.9)"], "{get:?}"); // The WMTS layer was asked as one (its answer here isn't one: noted). assert!(asked.iter().any(|r| r.path == "/wmts" && r.query.iter().any(|(k, v)| k == "SERVICE" && v == "WMTS")), "{asked:?}"); - assert!(notes.contains(r#""layer":"Tiles","text":"the layer: "#), "{notes}"); + assert!(notes.contains(r#""layer":"Tiles","loss":"dropped.feature","text":"the layer: "#), "{notes}"); // Its tile matrix set is RustGIS's choice, not QGIS's: said for the WMTS layer, and for no other. assert!(notes.contains(r#""layer":"Tiles","text":"its tile matrix set: RustGIS takes the service's Web Mercator one"#), "{notes}"); assert_eq!(notes.matches("its tile matrix set").count(), 1, "{notes}"); diff --git a/crates/map/src/qgis/mod.rs b/crates/map/src/qgis/mod.rs index 954983afad..2c350dbc26 100644 --- a/crates/map/src/qgis/mod.rs +++ b/crates/map/src/qgis/mod.rs @@ -31,6 +31,7 @@ use crate::effects::Blend; use crate::symbology::{Labeling, LineStroke, MarkerRotation, Picture, Renderer}; pub use annotation::{Annotation, MAX_ITEMS as MAX_ANNOTATIONS}; pub use expr::{reads_measure, to_sql}; +use rustgis_data::loss::LossCode; pub use source::{MAX_MEMORY_FIELDS, Source, VirtualFrom, WebOptions, is_drive_relative, is_relative}; pub use structure::{MAX_BOOKMARKS, MAX_RELATIONS, ProjectBookmark, ProjectRelation, listed}; @@ -55,14 +56,14 @@ pub struct Report { /// Where each note is in `notes`, by layer, kind and text: a hostile project can make /// thousands of different notes, and a repeat is found without going through them all. #[serde(skip)] - index: HashMap<(String, NoteKind, String), usize>, - /// Different notes past [`MAX_NOTES`], not kept but counted in a closing note of their kind: - /// approximated, then skipped. + index: HashMap, + /// Different notes past [`MAX_NOTES`], not kept but counted in a closing note of their kind + /// and loss code. #[serde(skip)] - more: [usize; 2], - /// Where each kind's closing note is in `notes`, kept in step by [`Report::forget`]. + more: HashMap<(NoteKind, Option), usize>, + /// Where each closing note is in `notes`, kept in step by [`Report::forget`]. #[serde(skip)] - closing: [Option; 2], + closing: HashMap<(NoteKind, Option), usize>, /// Raster image markers' images by their `imageFile`, read before the symbols showing them /// (`symbol::read_images`): each kept picture with its height over its width, or why it isn't /// drawn. Carried here because every symbol reader already takes the report; passing them @@ -86,6 +87,17 @@ pub struct Note { pub text: String, /// How many times it came up (once per symbol, class or rule it applies to). pub count: usize, + /// What happened to the layer's data, when this is a loss of data (features, geometry, + /// attributes, coordinates or times) and not only of how the map is drawn. + #[serde(serialize_with = "loss_id", skip_serializing_if = "Option::is_none")] + pub loss: Option, +} + +fn loss_id(code: &Option, s: S) -> Result { + match code { + Some(code) => s.serialize_str(code.spec().id), + None => s.serialize_none(), + } } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)] @@ -97,39 +109,40 @@ pub enum NoteKind { Skipped, } +/// A note's identity: a coded note never merges with a plain one or one of another code. +type NoteKey = (String, NoteKind, Option, String); + impl Report { /// Notes `text` about `layer`, counting a repeat rather than listing it again. pub fn note(&mut self, layer: &str, kind: NoteKind, text: impl Into) { - let key = (layer.to_string(), kind, text.into()); + self.note_coded(layer, kind, None, text.into()); + } + + fn note_coded(&mut self, layer: &str, kind: NoteKind, loss: Option, text: String) { + let key: NoteKey = (layer.to_string(), kind, loss, text); if let Some(n) = self.index.get(&key).and_then(|&i| self.notes.get_mut(i)) { n.count = n.count.saturating_add(1); } else if self.notes.len() < MAX_NOTES { self.index.insert(key.clone(), self.notes.len()); - let (layer, kind, text) = key; - self.notes.push(Note { layer, kind, text, count: 1 }); + let (layer, kind, loss, text) = key; + self.notes.push(Note { layer, kind, text, count: 1, loss }); } else { - // Past the cap, a new note is counted in the one closing note of its kind, never - // listed itself. - let (_, kind, _) = key; - let k = usize::from(kind == NoteKind::Skipped); - let more = self.more.get(k).copied().unwrap_or(0).saturating_add(1); + // Past the cap, a new note is counted in the one closing note of its kind and code, + // never listed itself (a loss keeps its code there). + let at = (kind, loss); + let more = self.more.get(&at).copied().unwrap_or(0).saturating_add(1); let text = format!("{more} more note(s) not listed"); - let at = self.closing.get(k).copied().flatten(); - match at.and_then(|i| self.notes.get_mut(i)) { + match self.closing.get(&at).copied().and_then(|i| self.notes.get_mut(i)) { Some(closing) => { closing.text = text; closing.count = closing.count.saturating_add(1); } None => { - self.notes.push(Note { layer: String::new(), kind, text, count: 1 }); - if let Some(c) = self.closing.get_mut(k) { - *c = Some(self.notes.len() - 1); - } + self.notes.push(Note { layer: String::new(), kind, text, count: 1, loss }); + self.closing.insert(at, self.notes.len() - 1); } } - if let Some(m) = self.more.get_mut(k) { - *m = more; - } + self.more.insert(at, more); } } @@ -141,15 +154,21 @@ impl Report { self.note(layer, NoteKind::Skipped, text); } - /// How many times `text` was noted for `layer`. + /// Notes a loss of the layer's data (not of how it is drawn) with its code, which a notice + /// and `--strict` go by. A coded note never merges with a plain one. + pub fn lost(&mut self, layer: &str, kind: NoteKind, code: LossCode, text: impl Into) { + self.note_coded(layer, kind, Some(code), text.into()); + } + + /// How many times `text` was noted for `layer` (plain). fn noted(&self, layer: &str, kind: NoteKind, text: &str) -> usize { - let key = (layer.to_string(), kind, text.to_string()); + let key: NoteKey = (layer.to_string(), kind, None, text.to_string()); self.index.get(&key).and_then(|&i| self.notes.get(i)).map_or(0, |n| n.count) } - /// Withdraws a provisional note once checking against the destination fields disproves it. + /// Withdraws a provisional plain note once checking against the destination fields disproves it. fn forget(&mut self, layer: &str, kind: NoteKind, text: &str) { - let key = (layer.to_string(), kind, text.to_string()); + let key: NoteKey = (layer.to_string(), kind, None, text.to_string()); let Some(&at) = self.index.get(&key) else { return }; if let Some(note) = self.notes.get_mut(at) && note.count > 1 @@ -157,15 +176,15 @@ impl Report { note.count -= 1; return; } - self.notes.retain(|n| n.layer != layer || n.kind != kind || n.text != text); - self.index = self.notes.iter().enumerate().map(|(i, n)| ((n.layer.clone(), n.kind, n.text.clone()), i)).collect(); + self.notes.retain(|n| n.layer != layer || n.kind != kind || n.loss.is_some() || n.text != text); + self.index = self.notes.iter().enumerate().map(|(i, n)| ((n.layer.clone(), n.kind, n.loss, n.text.clone()), i)).collect(); // The closing notes moved up with the rest. - for (k, kind) in [NoteKind::Approximated, NoteKind::Skipped].into_iter().enumerate() { - let more = self.more.get(k).copied().unwrap_or(0); + self.closing.clear(); + for (&(kind, loss), &more) in &self.more { let text = format!("{more} more note(s) not listed"); - let at = self.notes.iter().rposition(|n| n.kind == kind && n.layer.is_empty() && n.text == text); - if let Some(c) = self.closing.get_mut(k) { - *c = at.filter(|_| more > 0); + let at = self.notes.iter().rposition(|n| n.kind == kind && n.loss == loss && n.layer.is_empty() && n.text == text); + if let Some(at) = at.filter(|_| more > 0) { + self.closing.insert((kind, loss), at); } } } @@ -599,7 +618,7 @@ pub fn read_project(text: &str, dir: &str, images: &mut ReadImage, report: &mut let maplayers: Vec = child(root, "projectlayers").map(|p| p.children().filter(|c| c.has_tag_name("maplayer")).collect()).unwrap_or_default(); if maplayers.len() > MAX_LAYERS { - report.skipped("", format!("layers past the first {MAX_LAYERS}")); + report.lost("", NoteKind::Skipped, LossCode::DroppedFeature, format!("layers past the first {MAX_LAYERS}")); } let mut layers: Vec<(Option, ProjectLayer)> = Vec::new(); // QGIS group layers (a group drawn as one) whose blending mode RustGIS's groups don't have, From b910d88bf511f47554b04789fc18dbfa89afc776 Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 23:08:43 -0600 Subject: [PATCH 2/4] fix(engine): a QGIS layer naming no provider is still a layer left out, unless it holds no data --- crates/engine/src/cmd/qgis.rs | 6 +++--- crates/engine/src/tests.rs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/qgis.rs b/crates/engine/src/cmd/qgis.rs index 6264fa399e..c811d84af4 100644 --- a/crates/engine/src/cmd/qgis.rs +++ b/crates/engine/src/cmd/qgis.rs @@ -730,9 +730,9 @@ fn add_layer( Source::Other { provider } => { // A layer of no provider (an annotation layer, a group layer) is told by its kind. let what = if provider.is_empty() { format!("{} layers", layer.kind) } else { format!("{provider} sources") }; - // A layer of no provider (an annotation or group layer) holds no data; any other - // layer's data is left out. - if provider.is_empty() { + // An annotation or group layer holds no data; any other layer's data is left out, + // with or without a provider named. + if matches!(layer.kind.as_str(), "annotation" | "group") { report.skipped(name, format!("the layer: RustGIS doesn't read QGIS's {what}")); } else { report.lost(name, NoteKind::Skipped, LossCode::DroppedFeature, format!("the layer: RustGIS doesn't read QGIS's {what}")); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index fe6e079cd2..0d3b496662 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -5265,6 +5265,7 @@ fn qgis_import_codes_only_the_notes_that_lose_data() { }; let layers = [ layer("Unsupported", "not-a-provider", "x"), + r#"UnnamedUnnamedx"#.to_string(), layer("Heights", "memory", "PointZ?crs=EPSG:4326&field=a:string"), layer("Arcs", "memory", "CompoundCurve?crs=EPSG:4326&field=a:string"), ] @@ -5277,6 +5278,7 @@ fn qgis_import_codes_only_the_notes_that_lose_data() { notes.iter().find(|n| n["layer"] == layer && n["text"].as_str().unwrap().contains(text)).map(|n| n["loss"].as_str()) }; assert_eq!(json_loss("Unsupported", "RustGIS doesn't read"), Some(Some("dropped.feature"))); + assert_eq!(json_loss("Unnamed", "RustGIS doesn't read"), Some(Some("dropped.feature")), "a vector layer naming no provider"); // A memory layer opens empty, so its Z values and curves held no data: plain. assert_eq!(json_loss("Heights", "Z and M"), Some(None)); assert_eq!(json_loss("Arcs", "curves read as lines"), Some(None)); From 6de83487a79323ff55eece0f0357b7092adc4f67 Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 23:12:40 -0600 Subject: [PATCH 3/4] fix(map): layers past a QGIS import's limit are a data loss only when one holds data --- crates/map/src/qgis/mod.rs | 8 +++++++- crates/map/src/qgis/tests.rs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/map/src/qgis/mod.rs b/crates/map/src/qgis/mod.rs index 2c350dbc26..4aabb262a5 100644 --- a/crates/map/src/qgis/mod.rs +++ b/crates/map/src/qgis/mod.rs @@ -618,7 +618,13 @@ pub fn read_project(text: &str, dir: &str, images: &mut ReadImage, report: &mut let maplayers: Vec = child(root, "projectlayers").map(|p| p.children().filter(|c| c.has_tag_name("maplayer")).collect()).unwrap_or_default(); if maplayers.len() > MAX_LAYERS { - report.lost("", NoteKind::Skipped, LossCode::DroppedFeature, format!("layers past the first {MAX_LAYERS}")); + // Coded only when a layer left out holds data: a group or annotation layer holds none. + let text = format!("layers past the first {MAX_LAYERS}"); + if maplayers.iter().skip(MAX_LAYERS).any(|ml| !matches!(ml.attribute("type"), Some("group" | "annotation"))) { + report.lost("", NoteKind::Skipped, LossCode::DroppedFeature, text); + } else { + report.skipped("", text); + } } let mut layers: Vec<(Option, ProjectLayer)> = Vec::new(); // QGIS group layers (a group drawn as one) whose blending mode RustGIS's groups don't have, diff --git a/crates/map/src/qgis/tests.rs b/crates/map/src/qgis/tests.rs index 1614b857d2..d071b00b2f 100644 --- a/crates/map/src/qgis/tests.rs +++ b/crates/map/src/qgis/tests.rs @@ -3493,3 +3493,21 @@ fn a_dropped_virtual_filter_is_not_noted_for_letter_case() { assert!(report.notes.iter().any(|n| n.layer == "v" && n.text.contains("too long to read together")), "{:?}", report.notes); assert_eq!(letter_case_notes(&report, "v"), 0, "{:?}", report.notes); } + +/// Layers past the most an import reads are a data loss only when one of them holds data: a +/// group or annotation layer holds none. +#[test] +fn layers_past_the_limit_are_coded_only_when_one_holds_data() { + let past = |tail: &str| { + let group = r#"gg"#.repeat(super::MAX_LAYERS); + let text = format!("{group}{tail}"); + let mut report = Report::default(); + read_project(&text, "/maps", &mut report).unwrap(); + report.notes.iter().find(|n| n.text.contains("layers past the first")).map(|n| n.loss) + }; + let group = r#"hh"#; + let vector = + r#"vvogrv.shp"#; + assert_eq!(past(group), Some(None), "only a group past the limit: plain"); + assert_eq!(past(vector), Some(Some(rustgis_data::loss::LossCode::DroppedFeature))); +} From 7c098f6597f97a32e067b4f201656cd898d9682a Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 26 Nov 2026 23:38:18 -0600 Subject: [PATCH 4/4] fix(map): a memory layer past a QGIS import's limit holds no data --- crates/map/src/qgis/mod.rs | 9 +++++++-- crates/map/src/qgis/tests.rs | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/map/src/qgis/mod.rs b/crates/map/src/qgis/mod.rs index 4aabb262a5..6252493d72 100644 --- a/crates/map/src/qgis/mod.rs +++ b/crates/map/src/qgis/mod.rs @@ -618,9 +618,14 @@ pub fn read_project(text: &str, dir: &str, images: &mut ReadImage, report: &mut let maplayers: Vec = child(root, "projectlayers").map(|p| p.children().filter(|c| c.has_tag_name("maplayer")).collect()).unwrap_or_default(); if maplayers.len() > MAX_LAYERS { - // Coded only when a layer left out holds data: a group or annotation layer holds none. + // Coded only when a layer left out holds data: a group or annotation layer holds none, nor + // does a memory layer, which QGIS saves without its features. let text = format!("layers past the first {MAX_LAYERS}"); - if maplayers.iter().skip(MAX_LAYERS).any(|ml| !matches!(ml.attribute("type"), Some("group" | "annotation"))) { + let holds_data = |ml: &Node| { + !matches!(ml.attribute("type"), Some("group" | "annotation")) + && child(*ml, "provider").and_then(|p| p.text()).map(str::trim) != Some("memory") + }; + if maplayers.iter().skip(MAX_LAYERS).any(holds_data) { report.lost("", NoteKind::Skipped, LossCode::DroppedFeature, text); } else { report.skipped("", text); diff --git a/crates/map/src/qgis/tests.rs b/crates/map/src/qgis/tests.rs index d071b00b2f..9346f1a44c 100644 --- a/crates/map/src/qgis/tests.rs +++ b/crates/map/src/qgis/tests.rs @@ -3509,5 +3509,8 @@ fn layers_past_the_limit_are_coded_only_when_one_holds_data() { let vector = r#"vvogrv.shp"#; assert_eq!(past(group), Some(None), "only a group past the limit: plain"); + let memory = + r#"mmmemoryPoint"#; + assert_eq!(past(memory), Some(None), "a memory layer opens empty: plain"); assert_eq!(past(vector), Some(Some(rustgis_data::loss::LossCode::DroppedFeature))); }