From 984f7aff482af6a74f62726088270ba9a366be13 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 00:08:21 -0500 Subject: [PATCH 01/12] fix(data): read ESRI's Cassini projection name ArcGIS writes Cassini-Soldner as plain "Cassini" in .prj files, which were refused. Accept it as an alias, with a test reading Berlin's Soldner grid under that name. --- crates/data/src/raster/wkt.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/data/src/raster/wkt.rs b/crates/data/src/raster/wkt.rs index 34174fb88d..a87d4d4bdf 100644 --- a/crates/data/src/raster/wkt.rs +++ b/crates/data/src/raster/wkt.rs @@ -814,7 +814,8 @@ fn custom(p: &Node, method: &str) -> Result { // arrives as the plain name through the METHODS table. "HOTINE_OBLIQUE_MERCATOR" | "HOTINE_OBLIQUE_MERCATOR_AZIMUTH_NATURAL_ORIGIN" if get(&["AZIMUTH"]).is_some() => omerc(true)?, // EPSG's methods 9806 and 9818 have no scale factor; PROJ's cass and poly ignore one. - "CASSINI_SOLDNER" => format!("+proj=cass +lat_0={lat0} {at}"), + // ESRI writes plain `Cassini` to `.prj` files. + "CASSINI_SOLDNER" | "CASSINI" => format!("+proj=cass +lat_0={lat0} {at}"), "POLYCONIC" => format!("+proj=poly +lat_0={lat0} {at}"), "EQUAL_EARTH" => format!("+proj=eqearth {at}"), // The implementation fixes the cone axis and pseudo standard parallel. Refuse other @@ -1606,6 +1607,24 @@ mod tests { assert!((ll.x - 3.0).abs() < 1e-6 && (ll.y - 45.153_477).abs() < 1e-5, "{ll:?}"); } + #[test] + fn esri_cassini_name() { + // ArcGIS writes Cassini-Soldner as plain `Cassini` in a `.prj`: Berlin's Soldner grid + // (EPSG:3068) under that name and a name RustGIS doesn't know reads as the EPSG system. + let epsg = Crs::from_epsg(3068).unwrap(); + let wkt = to_wkt(epsg).unwrap().replace(",AUTHORITY[\"EPSG\",\"3068\"]", ""); + let start = wkt.find('"').unwrap() + 1; + let end = start + wkt[start..].find('"').unwrap(); + let esri = + format!("{}My_Soldner{}", &wkt[..start], &wkt[end..]).replace("PROJECTION[\"Cassini_Soldner\"]", "PROJECTION[\"Cassini\"]"); + assert!(esri.contains("PROJECTION[\"Cassini\"]"), "{esri}"); + let crs = crs_from_wkt(&esri).unwrap_or_else(|e| panic!("{e}: {esri}")); + let lonlat = Coord::new(13.4, 52.4); + let a = epsg.transformer().unwrap().from_lonlat(lonlat).unwrap(); + let b = crs.transformer().unwrap().from_lonlat(lonlat).unwrap(); + assert!((a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01, "{a:?} {b:?}"); + } + #[test] fn datums_and_prime_meridians() { // A prime meridian east of Greenwich moves longitudes east. From f2093cd944047fa47bac922dfc612242c0d96d8a Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 00:08:21 -0500 Subject: [PATCH 02/12] docs(data): correct raster doc comments Move the Zarr number attribute doc onto attr_f64, say a sample that rounds onto the no-data value is counted in Raster::rounded, and say RustGIS refuses the two-point oblique Mercators. --- crates/data/src/raster/esri.rs | 2 +- crates/data/src/raster/mod.rs | 4 ++-- crates/data/src/raster/zarr.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/data/src/raster/esri.rs b/crates/data/src/raster/esri.rs index 4af3d4204d..baceede8f6 100644 --- a/crates/data/src/raster/esri.rs +++ b/crates/data/src/raster/esri.rs @@ -24,7 +24,7 @@ //! (Molodensky–Badekas for Korean 1985, a chain of operations for NGO 1948 …), and the 11 //! planetary ones (Moon, Mars), whose bodies the map can't hold; //! - the seven PROJ can't write as a PROJ string (Hammer–Aitoff, Fuller, Cube, Tobler …) and the -//! two two-point oblique Mercators (53025, 54025), for which RustGIS has no WKT form. +//! two two-point oblique Mercators (53025, 54025), which RustGIS refuses. //! //! The three Earth sinusoidal systems (Sphere and World Sinusoidal, 53008 and 54008, and Africa //! Sinusoidal, 102011) were added afterwards (opengeos/RustGIS#563): RustGIS computes the diff --git a/crates/data/src/raster/mod.rs b/crates/data/src/raster/mod.rs index ab4b75bc58..8af5e0e112 100644 --- a/crates/data/src/raster/mod.rs +++ b/crates/data/src/raster/mod.rs @@ -577,8 +577,8 @@ pub struct Raster { /// left out. pub lost: Vec, /// How many values of each band changed when read as `f32` (Int32 IDs past 16,777,216, Float64 - /// values with more digits than `f32` holds), by band; empty when none did. NaN and no-data - /// values aren't counted. + /// values with more digits than `f32` holds), by band; empty when none did. NaN values and + /// samples that are exactly the no-data value aren't counted (one that rounds onto it is). pub rounded: Vec, transformer: Transformer, extent: Extent, diff --git a/crates/data/src/raster/zarr.rs b/crates/data/src/raster/zarr.rs index 68ada6a52f..0bf5d6e087 100644 --- a/crates/data/src/raster/zarr.rs +++ b/crates/data/src/raster/zarr.rs @@ -1060,7 +1060,6 @@ fn values_1d(a: &Array, chunks: &HashMap>) -> Result> { Ok(out) } -/// A number attribute (`scale_factor`, `_FillValue`). /// A JSON number exactly: a whole one as one. fn exact_number(n: &serde_json::Number) -> Option { n.as_i64() @@ -1087,6 +1086,7 @@ fn attr_exact(a: &Array, k: &str) -> Option { } } +/// A number attribute (`scale_factor`, `_FillValue`). fn attr_f64(a: &Array, k: &str) -> Option { match a.attrs.get(k)? { Value::Number(n) => n.as_f64(), From 8c1948d49f27380e912101647a631f37a5ee273f Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 00:13:48 -0500 Subject: [PATCH 03/12] fix(data): CityJSON footprint and notice fixes - A lone LoD 0 or ground face is measured by footprint's own rule (shows, now a function): one leaning near vertical goes the hull path instead of being kept as a sliver. - Geometry instances are counted for the "drawn as a point" notice only when the point row gets geometry. - The error for a system RustGIS doesn't know says to give one with the crs parameter of layer.addData. --- crates/data/src/cityjson/tests.rs | 36 +++++++++++++++++++++++++ crates/data/src/citymodel.rs | 11 +++++--- crates/data/src/footprint.rs | 44 ++++++++++++++++--------------- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/crates/data/src/cityjson/tests.rs b/crates/data/src/cityjson/tests.rs index bdd40c0ccd..3a0005a34f 100644 --- a/crates/data/src/cityjson/tests.rs +++ b/crates/data/src/cityjson/tests.rs @@ -253,6 +253,21 @@ fn instances_and_tin_reliefs_are_said() { assert!(read("m.city.json", &only, None).unwrap_err().to_string().contains("TINRelief")); } +/// An instance whose reference point can't be drawn isn't said to be drawn as a point. +#[test] +fn an_instance_kept_without_geometry_isnt_said_to_be_drawn() { + let instance = |at: usize| { + json!({"tree": {"type": "SolitaryVegetationObject", "geometry": [ + {"type": "GeometryInstance", "template": 0, "boundaries": [at], "transformationMatrix": []}]}}) + }; + let vertices = json!([[0, 0, 0], [1e200, 0, 0]]); + let out = read("m.city.json", &doc(vertices.clone(), instance(1)), Crs::from_epsg(3857)).unwrap(); + assert!(geometry(&out[0].0, 0).is_none(), "{:?}", geometry(&out[0].0, 0)); + assert!(!says(&out, "geometry instances are drawn"), "{:?}", messages_of(&out)); + let out = read("m.city.json", &doc(vertices, instance(0)), Crs::from_epsg(3857)).unwrap(); + assert!(says(&out, "1 geometry instances are drawn as a point"), "{:?}", messages_of(&out)); +} + /// An attribute named as one of the reader's fields keeps its value, under a name that says so. #[test] fn an_attribute_named_as_a_field_is_renamed_and_said() { @@ -520,6 +535,26 @@ fn a_lone_face_seen_edge_on_has_no_footprint() { assert!(says(&out, "1 city objects have a shape that can't be drawn"), "{:?}", messages_of(&out)); } +/// A level 0 face leaning a little off vertical shows a sliver from above, which isn't kept as the +/// footprint as it stands: it is measured as [`footprint`] measures any face, and is a wall. +#[test] +fn a_lone_face_nearly_on_edge_is_a_wall() { + let bytes = doc( + json!([[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [10.0, 0.3, 10.0], [0.0, 0.3, 10.0]]), + json!({"w": {"type": "Building", "geometry": [{"type": "MultiSurface", "lod": "0", "boundaries": [[[0, 1, 2, 3]]]}]}}), + ); + let out = read("m.city.json", &bytes, None).unwrap(); + assert!(says(&out, "1 city objects with no faces seen from above"), "{:?}", messages_of(&out)); + // Lying flat, the same face is the footprint and says nothing. + let bytes = doc( + json!([[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [10.0, 0.3, 0.0], [0.0, 0.3, 0.0]]), + json!({"w": {"type": "Building", "geometry": [{"type": "MultiSurface", "lod": "0", "boundaries": [[[0, 1, 2, 3]]]}]}}), + ); + let out = read("m.city.json", &bytes, None).unwrap(); + assert!((area(geometry(&out[0].0, 0)) - 3.0).abs() < 1e-9, "{:?}", geometry(&out[0].0, 0)); + assert!(messages_of(&out).is_empty(), "{:?}", messages_of(&out)); +} + /// Lines and points show the level of detail they came from, not the footprint's. Their own heights /// differing is more than `z_min` and `z_max` keep, which is said; all at one height, it isn't. #[test] @@ -981,6 +1016,7 @@ fn a_system_given_over_the_one_named_is_said() { // ...and without one given, it is an error, not a note. let e = read("m.city.json", root.to_string().as_bytes(), None).unwrap_err().to_string(); assert!(e.contains("it names a coordinate system RustGIS doesn't know"), "{e}"); + assert!(e.contains("give one with the crs parameter of layer.addData"), "{e}"); } /// One building whose LoD 2 geometry passes the face cap: a face with a courtyard first (marked diff --git a/crates/data/src/citymodel.rs b/crates/data/src/citymodel.rs index ba84312aeb..b3b48b525d 100644 --- a/crates/data/src/citymodel.rs +++ b/crates/data/src/citymodel.rs @@ -14,7 +14,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use serde_json::Value as Json; -use crate::footprint::{Hull, P3, footprint, usable_xy}; +use crate::footprint::{Hull, P3, footprint, shows, usable_xy}; use crate::raster::Crs; use crate::{Coord, DataError, Dataset, Field, Geometry, GeometryType, ReadReport, Result, Value}; @@ -211,7 +211,7 @@ fn lone_face(face: &[Vec]) -> Option { hi - lo }; let size = span(|c| c.x).max(span(|c| c.y)); - (crate::geometry::ring_area(outer).abs() > size * size * 5e-5).then(|| Geometry::Polygon(vec![rings])) + shows(face.first()?, size).then(|| Geometry::Polygon(vec![rings])) } /// An object's footprint and the level of detail it came from: the first of its LoD 0, the @@ -355,7 +355,7 @@ pub(crate) fn coordinate_system( } (None, Some(system)) => known_system(system).ok_or_else(|| { let system: String = system.chars().take(80).collect(); - DataError::Format(format!("{file_name}: it names a coordinate system RustGIS doesn't know ({system})")) + DataError::Format(format!("{file_name}: it names a coordinate system RustGIS doesn't know ({system}); give one with the crs parameter of layer.addData (from the command line, Python or the AI Assistant)")) })?, (None, None) if within(180.0, 90.0) => { notes.push("the file names no coordinate system: its coordinates are read as longitude/latitude".into()); @@ -642,7 +642,10 @@ pub(crate) fn object_rows(parts: ObjectParts, object: usize, counts: &mut Counts push(Family::Line, line_lod, geometry, heights_differ(lines.iter().flatten()), lines_draw); } let Highest { lod: point_lod, parts: points, usable: points_usable, .. } = points; - counts.instances += points.iter().filter(|(_, instance)| *instance).count(); + // Only those drawn: a point row kept without geometry draws no instance. + if points_usable { + counts.instances += points.iter().filter(|(_, instance)| *instance).count(); + } let points: Vec = points.into_iter().map(|(p, _)| p).collect(); if !points.is_empty() { let geometry = points_usable.then(|| match points.as_slice() { diff --git a/crates/data/src/footprint.rs b/crates/data/src/footprint.rs index 70634f34be..c33d57a158 100644 --- a/crates/data/src/footprint.rs +++ b/crates/data/src/footprint.rs @@ -43,6 +43,28 @@ pub(crate) enum Hull { Unmerged, } +/// Whether a face's outer `ring` shows from above, in a shape `size` across (its larger X or Y +/// span), by the cosine of its tilt (its projected area over its area): walls, even leaning ones, +/// show as slivers, which cover nothing and which the union can't always take. Faces narrower than +/// a ten-thousandth of the shape are left out too (a flat shape). +pub(crate) fn shows(ring: &[P3], size: f64) -> bool { + let (mut nx, mut ny, mut nz) = (0.0, 0.0, 0.0); + let (mut longest, mut area2) = (0.0f64, 0.0); + // From the ring's first point: projected coordinates run to millions, whose products would + // lose the millimetres a small face is measured in. + let o = ring.first().copied().unwrap_or([0.0; 3]); + let local: Vec = ring.iter().map(|p| [p[0] - o[0], p[1] - o[1], p[2] - o[2]]).collect(); + for (a, b) in local.iter().zip(local.iter().cycle().skip(1)) { + nx += (a[1] - b[1]) * (a[2] + b[2]); + ny += (a[2] - b[2]) * (a[0] + b[0]); + nz += (a[0] - b[0]) * (a[1] + b[1]); + longest = longest.max((b[0] - a[0]).hypot(b[1] - a[1])); + area2 += a[0] * b[1] - b[0] * a[1]; + } + let n = nx.hypot(ny).hypot(nz); + n > 0.0 && nz.abs() / n > 0.05 && longest > 0.0 && area2.abs() / longest > size * 1e-4 +} + /// A shape's footprint: the union of its `faces` (each its outer ring and then its holes) seen from /// above. Faces standing on edge, such as walls, show nothing and are left out. The footprint is the /// hull of `points` when no face shows, or when its faces aren't merged: `truncated` (the reader left @@ -72,26 +94,6 @@ pub(crate) fn footprint]>>( if !size.is_finite() { return (None, None); } - // A face shows from above by the cosine of its tilt (its projected area over its area): walls, - // even leaning ones, show as slivers, which cover nothing and which the union can't always - // take. Faces narrower than a ten-thousandth of the shape are left out too (a flat shape). - let shows = |ring: &[P3]| { - let (mut nx, mut ny, mut nz) = (0.0, 0.0, 0.0); - let (mut longest, mut area2) = (0.0f64, 0.0); - // From the ring's first point: projected coordinates run to millions, whose products would - // lose the millimetres a small face is measured in. - let o = ring.first().copied().unwrap_or([0.0; 3]); - let local: Vec = ring.iter().map(|p| [p[0] - o[0], p[1] - o[1], p[2] - o[2]]).collect(); - for (a, b) in local.iter().zip(local.iter().cycle().skip(1)) { - nx += (a[1] - b[1]) * (a[2] + b[2]); - ny += (a[2] - b[2]) * (a[0] + b[0]); - nz += (a[0] - b[0]) * (a[1] + b[1]); - longest = longest.max((b[0] - a[0]).hypot(b[1] - a[1])); - area2 += a[0] * b[1] - b[0] * a[1]; - } - let n = nx.hypot(ny).hypot(nz); - n > 0.0 && nz.abs() / n > 0.05 && longest > 0.0 && area2.abs() / longest > size * 1e-4 - }; let ring2 = |r: &[P3]| geo::LineString::from(r.iter().map(|p| (p[0], p[1])).collect::>()); // Past the cap, a partial union would be wrong: the hull below stands in. let seen: Vec> = faces @@ -99,7 +101,7 @@ pub(crate) fn footprint]>>( .filter(|_| !truncated) .filter_map(|face| { let (outer, holes) = face.as_ref().split_first()?; - (outer.len() >= 3 && shows(outer)) + (outer.len() >= 3 && shows(outer, size)) .then(|| geo::Polygon::new(ring2(outer), holes.iter().map(|h| ring2(h)).collect()).orient(Direction::Default)) }) .collect(); From 9c4f6059fb720f8d00c4a3f91a15d466e9a52021 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 00:13:48 -0500 Subject: [PATCH 04/12] fix(engine): describe info.fileLayers' crs parameter fully It applies to a CityJSON model named .city.json, .json or in a zip, and the addData arm runs whenever a system is given. --- crates/engine/src/cmd/layer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index f6bc99da35..a82e93a184 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -22,7 +22,7 @@ pub fn commands() -> Vec { ), C::new("info.fileLayers", "List Layers in File", "Home › Add › Add Data", file_layers).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) .view() - .params(r#"{"path": string, "crs"?: "EPSG:… for a .city.json that doesn't say (as layer.addData)"}"#), + .params(r#"{"path": string, "crs"?: "EPSG:… for a CityJSON model (.city.json, a .json, or in a zip) that doesn't say (as layer.addData)"}"#), C::new("info.fileColumns", "List Columns in File", "Home › Add › Add Data › Delimited Text", file_columns).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().params( r#"{"path": "a delimited text file (CSV, TSV, TXT) or a spreadsheet", "delimiter"?: ","|";"|"\\t"|"|", "layer"?: "a spreadsheet's sheet (the first by default)"}"#, ), @@ -1594,7 +1594,7 @@ pub(crate) fn add_layers(s: &mut Session, p: &Value, file_name: &str, bytes: &[u .map(|(dataset, report)| rustgis_data::io::LayerRead { dataset, report, styles: Vec::new() }) .collect() } - // A CityJSON model that names no coordinate system, or names one it doesn't have. + // A CityJSON model with a coordinate system given, which takes the place of any it names. _ if crs.is_some() && rustgis_data::io::is_cityjson(file_name, bytes) => { let crs = crs.map(rustgis_data::raster::Crs::parse).transpose()?; rustgis_data::cityjson::read(file_name, bytes, crs) From 1d0fded50623ecd131d0ac25081561b71a1557cc Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 00:16:25 -0500 Subject: [PATCH 05/12] fix(data): clearer WFS paging notices Keep the hits request's error in the note when the WFS total can't be read, and don't prefix the at-limit note with stop's count, which made it read "1 WFS features read: the first 1 features are read". --- crates/data/src/ogc.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index 189ad0893c..7534673c31 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -3528,9 +3528,17 @@ impl Pages { fn land_page(mut self, answer: Result, String>) -> Step { if matches!(self.phase, Phase::WfsHits) { - let matched = answer.ok().and_then(|b| wfs_matched(&b)); - let Some(matched) = matched else { - return self.stop("the WFS total couldn't be read; the features received may be incomplete".into()); + // Why the request failed is kept, so the notice says why completeness is unknown. + let matched = match answer { + Ok(b) => wfs_matched(&b).ok_or(None), + Err(e) => Err(Some(e)), + }; + let matched = match matched { + Ok(matched) => matched, + Err(why) => { + let why = why.map(|e| format!(" ({})", e.chars().take(200).collect::())).unwrap_or_default(); + return self.stop(format!("the WFS total couldn't be read{why}; the features received may be incomplete")); + } }; let offset = self.features.len(); if offset > self.max { @@ -3835,8 +3843,12 @@ impl Pages { if let Some((ds, ..)) = &mut self.decoded { ds.features.truncate(max); } - let note = format!("the first {max} features are read; the rest aren't"); - if matches!(self.phase, Phase::WfsHits | Phase::WfsOffsets { .. }) { self.stop(note) } else { self.finish(Some(note)) } + // Not through `stop`, whose "N WFS features read:" would say the count twice. + let note = match self.phase { + Phase::WfsOffsets { matched, .. } => format!("the first {max} of {matched} WFS features are read; the rest aren't"), + _ => format!("the first {max} features are read; the rest aren't"), + }; + self.finish(Some(note)) } /// The pages' features in the first page's collection, without its paging members. @@ -4998,7 +5010,10 @@ mod tests { { let (bytes, note) = join_pages(url, first.to_vec(), 100, |_| answer.clone()); assert_eq!(count(&bytes), 2); - assert!(note.unwrap().contains("incomplete")); + let note = note.unwrap(); + assert!(note.contains("incomplete")); + // The failed request's reason is kept. + assert_eq!(note.contains("(timeout)"), answer.is_err(), "{note}"); } for last in [ Err("timeout".into()), @@ -5022,10 +5037,14 @@ mod tests { if calls == 1 { Ok(hits.to_vec()) } else { Ok(br#"{"features":[{"id":3},{"id":4}]}"#.to_vec()) } }); assert_eq!(count(&bytes), 3); - assert!(note.unwrap().contains("3 of 4 WFS features read")); + let note = note.unwrap(); + assert!(note.contains("the first 3 of 4 WFS features are read"), "{note}"); + assert!(!note.contains("WFS features read:"), "{note}"); let (bytes, note) = join_pages(url, first.to_vec(), 1, |_| panic!("limit checked before hits")); assert_eq!(count(&bytes), 1); - assert!(note.unwrap().contains("first 1")); + let note = note.unwrap(); + assert!(note.contains("first 1"), "{note}"); + assert!(!note.contains("WFS features read:"), "{note}"); for suffix in ["&STARTINDEX=0", "&RESULTTYPE=hits"] { let (bytes, note) = join_pages(&format!("{url}{suffix}"), first.to_vec(), 100, |_| panic!("explicit request must stay unchanged")); From a8fb583d0f8881d4cdde1d1fc5ce54dcc842414a Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 01:23:47 -0500 Subject: [PATCH 06/12] fix(data): say when GML rings and parts are left out Rings with too few points or unreadable coordinates, exterior rings past the first, and line or point parts that can't be read were dropped with no notice. Count them in one notice per file, with tests for lossy and clean input, and correct the ring comment: a ring kept has at least four positions once closed. --- crates/data/src/gml.rs | 97 +++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 15 deletions(-) diff --git a/crates/data/src/gml.rs b/crates/data/src/gml.rs index 44cb674bc8..5c2469f05d 100644 --- a/crates/data/src/gml.rs +++ b/crates/data/src/gml.rs @@ -142,32 +142,49 @@ fn ring(mut r: Vec) -> Option> { (r.len() >= 4).then_some(r) } -/// The rings of a polygon or surface patch: exterior (outerBoundaryIs) first. -fn polygon(p: &Node, zm: &Cell) -> Option>> { - // Each ring `ring` keeps (at least three points, closed if it wasn't), and whether it had Z or M. +/// The rings of a polygon or surface patch: exterior (outerBoundaryIs) first. `lost` counts the +/// rings left out: too few points or unreadable, and exterior rings past the first. +fn polygon(p: &Node, zm: &Cell, lost: &Cell) -> Option>> { + // Each ring `ring` keeps (at least four positions once closed, closed if it wasn't), and whether + // it had Z or M. let boundary = |names: &[&str]| -> Vec<(Vec, bool)> { let kept = |b: Node| { let dims = Cell::new(false); - ring(coords(&b, &dims)?).map(|r| (r, dims.get())) + let r = coords(&b, &dims).and_then(ring).map(|r| (r, dims.get())); + lost.set(lost.get() + usize::from(r.is_none())); + r }; p.descendants().filter(|d| d.is_element() && is_gml(d) && names.contains(&local(d))).filter_map(kept).collect() }; // The first exterior ring, then the interiors: only the rings kept mark Z or M. - let outer = boundary(&["exterior", "outerBoundaryIs"]).into_iter().next()?; + let mut outers = boundary(&["exterior", "outerBoundaryIs"]).into_iter(); + let outer = outers.next()?; + lost.set(lost.get() + outers.count()); let mut rings = vec![outer]; rings.extend(boundary(&["interior", "innerBoundaryIs"])); zm.set(zm.get() || rings.iter().any(|(_, d)| *d)); Some(rings.into_iter().map(|(r, _)| r).collect()) } -/// A GML geometry element as a geometry; `zm` is set when Z or M values are dropped. -fn geometry(g: &Node, zm: &Cell) -> Option { +/// A GML geometry element as a geometry; `zm` is set when Z or M values are dropped, and `lost` +/// counts the rings and parts left out (too few points, or unreadable). +fn geometry(g: &Node, zm: &Cell, lost: &Cell) -> Option { + let left_out = || lost.set(lost.get() + 1); let kids = |names: &[&str]| -> Vec { g.descendants().filter(|d| d.is_element() && is_gml(d) && names.contains(&local(d))).collect() }; match local(g) { "Point" => coords(g, zm)?.first().map(|c| Geometry::Point(*c)), "MultiPoint" => { - let pts: Vec = kids(&["Point"]).iter().filter_map(|p| coords(p, zm)?.first().copied()).collect(); + let pts: Vec = kids(&["Point"]) + .iter() + .filter_map(|p| { + let c = coords(p, zm).and_then(|c| c.first().copied()); + if c.is_none() { + left_out(); + } + c + }) + .collect(); (!pts.is_empty()).then_some(Geometry::MultiPoint(pts)) } "LineString" | "Curve" | "LinearRing" => { @@ -178,16 +195,28 @@ fn geometry(g: &Node, zm: &Cell) -> Option { // Only a part kept (two points or more) marks Z or M. let kept = |l: &Node| { let dims = Cell::new(false); - let c = coords(l, &dims).filter(|c| c.len() >= 2)?; + let Some(c) = coords(l, &dims).filter(|c| c.len() >= 2) else { + left_out(); + return None; + }; zm.set(zm.get() || dims.get()); Some(c) }; let parts: Vec> = kids(&["LineString", "Curve"]).iter().filter_map(kept).collect(); (!parts.is_empty()).then_some(Geometry::Line(parts)) } - "Polygon" => Some(Geometry::Polygon(vec![polygon(g, zm)?])), + "Polygon" => Some(Geometry::Polygon(vec![polygon(g, zm, lost)?])), "Surface" | "MultiPolygon" | "MultiSurface" => { - let polys: Vec>> = kids(&["Polygon", "PolygonPatch"]).iter().filter_map(|p| polygon(p, zm)).collect(); + let polys: Vec>> = kids(&["Polygon", "PolygonPatch"]) + .iter() + .filter_map(|p| { + // A polygon left out whole counts once, not by its rings. + let rings = Cell::new(0); + let poly = polygon(p, zm, &rings); + lost.set(lost.get() + if poly.is_some() { rings.get() } else { 1 }); + poly + }) + .collect(); (!polys.is_empty()).then_some(Geometry::Polygon(polys)) } "Envelope" | "Box" => { @@ -241,6 +270,8 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> let (mut skipped, mut file_srs): (usize, Option<(Crs, bool)>) = (0, None); let mut unknown_srs: Option = None; let mut over = 0usize; + // Rings and parts left out of the geometries kept. + let mut parts_lost = 0usize; for f in members { let name = local(&f).to_string(); if !kinds.contains_key(&name) { @@ -275,10 +306,11 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> None => unknown_srs = Some(s.to_string()), } } - let dims = Cell::new(false); - match geometry(&g, &dims) { + let (dims, lost) = (Cell::new(false), Cell::new(0)); + match geometry(&g, &dims, &lost) { Some(gm) => { zm = dims.get(); + parts_lost += lost.get(); geom = Some(gm); } None => bad = true, @@ -312,6 +344,11 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> if skipped > 0 { report.messages.push(format!("{skipped} features had geometry that couldn't be read")); } + if parts_lost > 0 { + report + .messages + .push(format!("{parts_lost} rings or parts of geometries with too few points or unreadable coordinates were left out")); + } if over > 0 { report.messages.push(format!("{over} features of more than {MAX_LAYERS} feature types were left out")); } @@ -439,16 +476,19 @@ mod tests { // Its height is dropped, and said. assert!(ds.zm_dropped && rep.messages.iter().any(|m| m.contains("Z or M values")), "{:?}", rep.messages); - // A one-point 3D part is left out, and its height with it: the 2D line kept says nothing. + // A one-point 3D part is left out, and its height with it: the 2D line kept drops no Z, + // and the part left out is said. let gml = r#" 10 48 312 10 48 11 49 "#; let layers = read("r.gml", gml.as_bytes()).unwrap(); assert!(!layers[0].0.zm_dropped, "{:?}", layers[0].1.messages); + assert!(layers[0].1.messages.iter().any(|m| m.starts_with("1 rings or parts")), "{:?}", layers[0].1.messages); assert_eq!(layers[0].0.features[0].geometry, Some(Geometry::Line(vec![vec![Coord::new(10.0, 48.0), Coord::new(11.0, 49.0)]]))); - // A two-point 3D interior ring is left out: the 2D polygon kept says nothing. + // A two-point 3D interior ring is left out: the 2D polygon kept drops no Z, and the ring + // left out is said. let gml = r#" 10 48 11 48 11 49 10 48 @@ -457,9 +497,36 @@ mod tests { "#; let layers = read("p.gml", gml.as_bytes()).unwrap(); assert!(!layers[0].0.zm_dropped, "{:?}", layers[0].1.messages); + assert!(layers[0].1.messages.iter().any(|m| m.starts_with("1 rings or parts")), "{:?}", layers[0].1.messages); assert!(matches!(&layers[0].0.features[0].geometry, Some(Geometry::Polygon(p)) if p.len() == 1 && p[0].len() == 1)); } + /// Rings and parts with too few points are left out and counted, once a kind; a clean file + /// says nothing of them. + #[test] + fn rings_and_parts_left_out_are_counted() { + let layers = read("w.gml", WFS.as_bytes()).unwrap(); + assert!(layers.iter().all(|(_, r)| !r.messages.iter().any(|m| m.contains("rings or parts"))), "{:?}", layers[0].1.messages); + // A second exterior ring, and a surface with a polygon whose only ring is two points, beside + // one that draws: two left out, one notice. + let gml = r#" + + 10 48 11 48 11 49 10 48 + 20 48 21 48 21 49 20 48 + + + 10 48 11 48 11 49 10 48 + 10 48 11 48 + +"#; + 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("rings or parts")).collect(); + assert_eq!(said.len(), 1, "{:?}", rep.messages); + assert!(said[0].starts_with("2 rings or parts"), "{said:?}"); + } + #[test] fn unread_geometry_kinds_are_counted() { let gml = r#" From badefa01aff8a40190a46d5c111bf590d5ba1d54 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 01:23:56 -0500 Subject: [PATCH 07/12] fix(engine): say why a GeometryCollection geometry is refused edit.addFeature and edit.setGeometry said "geometry must be a GeoJSON geometry" for a valid collection of several members. Say that a GeometryCollection must hold exactly one geometry instead. --- crates/engine/src/cmd/design.rs | 2 +- crates/engine/src/cmd/edit.rs | 21 ++++++++++++++++++++- crates/engine/src/tests.rs | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/design.rs b/crates/engine/src/cmd/design.rs index 7b11b318a4..c31249acd0 100644 --- a/crates/engine/src/cmd/design.rs +++ b/crates/engine/src/cmd/design.rs @@ -986,7 +986,7 @@ fn modify(s: &mut Session, mut change: impl FnMut((u32, usize), &Geometry) -> Re fn set_geometry(s: &mut Session, p: &Json) -> CmdResult { let id = s.layer_id(p)?; let row = p.get("row").and_then(Json::as_u64).ok_or("row is required")? as usize; - let g = p.get("geometry").and_then(rustgis_data::io::geometry_from_geojson).ok_or("geometry must be a GeoJSON geometry")?; + let g = super::edit::geometry_param(p)?; replace_geometry(s, id, row, g)?; Ok(Json::Null) } diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 53fdedae7d..0c219a0d1b 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -32,7 +32,7 @@ pub fn commands() -> Vec { pub(crate) fn add_feature(s: &mut Session, p: &Json) -> CmdResult { let id = s.layer_id(p)?; - let g = p.get("geometry").and_then(rustgis_data::io::geometry_from_geojson).ok_or("geometry must be a GeoJSON geometry")?; + let g = geometry_param(p)?; let l = s.map_mut().layer_mut(id).ok_or("no layer")?; let want = l.geometry_type(); let ok = want == g.kind() || want == GeometryType::None; @@ -68,6 +68,25 @@ pub(crate) fn add_feature(s: &mut Session, p: &Json) -> CmdResult { Ok(json!({"row": row})) } +/// The `geometry` parameter as a geometry. A GeometryCollection of more or fewer than one member +/// (at any depth) is refused as such, not as something that isn't GeoJSON. +pub(crate) fn geometry_param(p: &Json) -> Result { + let given = p.get("geometry"); + if let Some(g) = given.and_then(rustgis_data::io::geometry_from_geojson) { + return Ok(g); + } + let mut g = given; + // Bounded by the JSON's own depth: each round goes one level in. + while let Some(c) = g.filter(|g| g.get("type").and_then(Json::as_str) == Some("GeometryCollection")) { + match c.get("geometries").and_then(Json::as_array).map(Vec::as_slice) { + Some([only]) => g = Some(only), + Some(_) => return Err("a GeometryCollection must hold exactly one geometry".into()), + None => break, + } + } + Err("geometry must be a GeoJSON geometry".into()) +} + /// Rejects empty or degenerate geometry, which would break extents, labels and rendering. pub(crate) fn validate(g: &Geometry) -> Result<(), String> { match g { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index c488a4749c..b53d4d39e3 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21791,6 +21791,25 @@ fn unknown_params_are_said() { assert!(said.len() < 500 && said.contains("995 more"), "{said}"); } +/// A GeometryCollection of several members is refused by what is wrong with it. +#[test] +fn a_geometry_collection_of_several_is_refused_as_such() { + let mut s = world(); + let point = json!({"type": "Point", "coordinates": [1, 2]}); + let two = json!({"type": "GeometryCollection", "geometries": [point, point]}); + let nested = json!({"type": "GeometryCollection", "geometries": [two]}); + for cmd in ["edit.addFeature", "edit.setGeometry"] { + for g in [&two, &nested] { + let e = s.run(cmd, &json!({"layer": "Cities", "row": 0, "geometry": g})).unwrap_err(); + assert!(e.contains("a GeometryCollection must hold exactly one geometry"), "{cmd}: {e}"); + } + let e = s.run(cmd, &json!({"layer": "Cities", "row": 0, "geometry": {"type": "Blob"}})).unwrap_err(); + assert!(e.contains("geometry must be a GeoJSON geometry"), "{cmd}: {e}"); + } + // One member is the geometry. + s.run("edit.addFeature", &json!({"layer": "Cities", "geometry": {"type": "GeometryCollection", "geometries": [point]}})).unwrap(); +} + #[test] fn geojson_collection_import_reports_loss_even_without_surviving_geometry() { let collection = json!({"type":"GeometryCollection", "geometries":[ From 71a122a50fdec09aa3b9b2c8a3e89d02e181cbdd Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 02:52:04 -0500 Subject: [PATCH 08/12] Address Claude review feedback - Redact and shorten the failed WFS hits request's error before it goes into the notice, so a token in the address isn't shown; test it. - Cite why ESRI's Cassini is ellipsoidal Cassini-Soldner and check the alias away from Berlin's grid origin too. --- crates/data/src/ogc.rs | 17 ++++++++++++++++- crates/data/src/raster/wkt.rs | 14 +++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index 7534673c31..785175cd93 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -3536,7 +3536,15 @@ impl Pages { let matched = match matched { Ok(matched) => matched, Err(why) => { - let why = why.map(|e| format!(" ({})", e.chars().take(200).collect::())).unwrap_or_default(); + // Without the credentials an address in the error may hold, and not all of a + // long one. + let why = why + .map(|e| { + let mut e = crate::diagnostics::redact(&e); + crate::diagnostics::cut_with_ellipsis(&mut e, MAX_REASON); + format!(" ({e})") + }) + .unwrap_or_default(); return self.stop(format!("the WFS total couldn't be read{why}; the features received may be incomplete")); } }; @@ -5015,6 +5023,13 @@ mod tests { // The failed request's reason is kept. assert_eq!(note.contains("(timeout)"), answer.is_err(), "{note}"); } + // A credential in the failed request's address isn't repeated in the notice. + { + let failed = Err::, String>("error sending request for url (https://x.test/wfs?token=abc123)".to_string()); + let (_, note) = join_pages(url, first.to_vec(), 100, |_| failed.clone()); + let note = note.unwrap(); + assert!(note.contains("incomplete") && !note.contains("abc123"), "{note}"); + } for last in [ Err("timeout".into()), Ok(br#"{"features":[]}"#.to_vec()), diff --git a/crates/data/src/raster/wkt.rs b/crates/data/src/raster/wkt.rs index a87d4d4bdf..6001bf792b 100644 --- a/crates/data/src/raster/wkt.rs +++ b/crates/data/src/raster/wkt.rs @@ -814,7 +814,9 @@ fn custom(p: &Node, method: &str) -> Result { // arrives as the plain name through the METHODS table. "HOTINE_OBLIQUE_MERCATOR" | "HOTINE_OBLIQUE_MERCATOR_AZIMUTH_NATURAL_ORIGIN" if get(&["AZIMUTH"]).is_some() => omerc(true)?, // EPSG's methods 9806 and 9818 have no scale factor; PROJ's cass and poly ignore one. - // ESRI writes plain `Cassini` to `.prj` files. + // ESRI writes plain `Cassini` to `.prj` files for the same ellipsoidal method (EPSG 9806): + // ESRI's projection reference describes it as Cassini-Soldner, and GDAL's ESRI WKT + // morphing maps `Cassini` and `Cassini_Soldner` to each other. "CASSINI_SOLDNER" | "CASSINI" => format!("+proj=cass +lat_0={lat0} {at}"), "POLYCONIC" => format!("+proj=poly +lat_0={lat0} {at}"), "EQUAL_EARTH" => format!("+proj=eqearth {at}"), @@ -1619,10 +1621,12 @@ mod tests { format!("{}My_Soldner{}", &wkt[..start], &wkt[end..]).replace("PROJECTION[\"Cassini_Soldner\"]", "PROJECTION[\"Cassini\"]"); assert!(esri.contains("PROJECTION[\"Cassini\"]"), "{esri}"); let crs = crs_from_wkt(&esri).unwrap_or_else(|e| panic!("{e}: {esri}")); - let lonlat = Coord::new(13.4, 52.4); - let a = epsg.transformer().unwrap().from_lonlat(lonlat).unwrap(); - let b = crs.transformer().unwrap().from_lonlat(lonlat).unwrap(); - assert!((a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01, "{a:?} {b:?}"); + // Near the grid origin and a few degrees from it, where a spherical form would differ. + for lonlat in [Coord::new(13.4, 52.4), Coord::new(17.5, 55.5)] { + let a = epsg.transformer().unwrap().from_lonlat(lonlat).unwrap(); + let b = crs.transformer().unwrap().from_lonlat(lonlat).unwrap(); + assert!((a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01, "{a:?} {b:?}"); + } } #[test] From 42bcfe3b2026de7f72b7e209632145c912283dc1 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 03:18:48 -0500 Subject: [PATCH 09/12] Address review feedback - GML: the dropped-rings notice names every cause, exterior rings past the first included. - WFS: a failed hits request's error that holds an address is left out of the notice, since redact keeps URL paths. - layer.addData and info.fileLayers: say that crs replaces the system a CityJSON file names, and in a zip applies only to a model naming none RustGIS knows. - Test empty and nested single-member GeometryCollections with both edit.addFeature and edit.setGeometry. --- crates/data/src/gml.rs | 2 +- crates/data/src/ogc.rs | 4 +++- crates/engine/src/cmd/layer.rs | 4 ++-- crates/engine/src/tests.rs | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/data/src/gml.rs b/crates/data/src/gml.rs index 5c2469f05d..b22760b3a9 100644 --- a/crates/data/src/gml.rs +++ b/crates/data/src/gml.rs @@ -347,7 +347,7 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> if parts_lost > 0 { report .messages - .push(format!("{parts_lost} rings or parts of geometries with too few points or unreadable coordinates were left out")); + .push(format!("{parts_lost} rings or parts of geometries were left out: too few points, unreadable coordinates, or an exterior ring past the first")); } if over > 0 { report.messages.push(format!("{over} features of more than {MAX_LAYERS} feature types were left out")); diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index 785175cd93..e35ef3a8de 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -3531,7 +3531,9 @@ impl Pages { // Why the request failed is kept, so the notice says why completeness is unknown. let matched = match answer { Ok(b) => wfs_matched(&b).ok_or(None), - Err(e) => Err(Some(e)), + // An error holding an address isn't repeated: `redact` keeps its path, which can + // hold a key. + Err(e) => Err(Some(e).filter(|e| !e.contains("://"))), }; let matched = match matched { Ok(matched) => matched, diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index a82e93a184..5644c19cab 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -16,13 +16,13 @@ use crate::{CmdResult, CommandSpec as C, Session}; pub fn commands() -> Vec { vec![ C::new("layer.addData", "Add Data", "Home › Add", add_data).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) - .params(r#"{"path": string, "name"?: string, "layer"?: "GeoPackage, GDAL, DuckDB or DXF layer", "paperSpace"?: "bool: a DXF's layout entities too", "stream"?: bool, "as"?: "scan" (a TIFF, PNG or JPEG, even a photo or a GeoTIFF, as a picture with no coordinates), "crs"?: "EPSG:… (or WKT) for Shapefile coordinates (overrides .prj), a CSV, a CityJSON model, or a GDAL or DuckDB file that doesn't say", "x"?: "CSV x/longitude column", "y"?: "CSV y/latitude column", "wkt"?: "CSV WKT geometry column", "delimiter"?: ","|";"|"\\t"|"|"}"#), + .params(r#"{"path": string, "name"?: string, "layer"?: "GeoPackage, GDAL, DuckDB or DXF layer", "paperSpace"?: "bool: a DXF's layout entities too", "stream"?: bool, "as"?: "scan" (a TIFF, PNG or JPEG, even a photo or a GeoTIFF, as a picture with no coordinates), "crs"?: "EPSG:… (or WKT) for Shapefile coordinates (overrides .prj), a CSV, a CityJSON model (it replaces the system a model file names; in a zip, it is used for a model naming none RustGIS knows), or a GDAL or DuckDB file that doesn't say", "x"?: "CSV x/longitude column", "y"?: "CSV y/latitude column", "wkt"?: "CSV WKT geometry column", "delimiter"?: ","|";"|"\\t"|"|"}"#), C::new("layer.addPhotos", "Add Photos", "Home › Add", add_photos).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).params( r#"{"paths"?: [JPEG photo files], "folder"?: "a folder of photos (every JPEG in it)", "name"?: "the layer (default Photos; photos join it when it exists)"}"#, ), C::new("info.fileLayers", "List Layers in File", "Home › Add › Add Data", file_layers).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) .view() - .params(r#"{"path": string, "crs"?: "EPSG:… for a CityJSON model (.city.json, a .json, or in a zip) that doesn't say (as layer.addData)"}"#), + .params(r#"{"path": string, "crs"?: "EPSG:… for a CityJSON model (.city.json, a .json, or in a zip): it replaces the system a model file names; in a zip, it is used for a model naming none RustGIS knows (as layer.addData)"}"#), C::new("info.fileColumns", "List Columns in File", "Home › Add › Add Data › Delimited Text", file_columns).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().params( r#"{"path": "a delimited text file (CSV, TSV, TXT) or a spreadsheet", "delimiter"?: ","|";"|"\\t"|"|", "layer"?: "a spreadsheet's sheet (the first by default)"}"#, ), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index b53d4d39e3..6618a65e31 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21794,20 +21794,29 @@ fn unknown_params_are_said() { /// A GeometryCollection of several members is refused by what is wrong with it. #[test] fn a_geometry_collection_of_several_is_refused_as_such() { + use rustgis_data::{Coord, Geometry}; let mut s = world(); let point = json!({"type": "Point", "coordinates": [1, 2]}); let two = json!({"type": "GeometryCollection", "geometries": [point, point]}); let nested = json!({"type": "GeometryCollection", "geometries": [two]}); + let empty = json!({"type": "GeometryCollection", "geometries": []}); for cmd in ["edit.addFeature", "edit.setGeometry"] { - for g in [&two, &nested] { + for g in [&two, &nested, &empty] { let e = s.run(cmd, &json!({"layer": "Cities", "row": 0, "geometry": g})).unwrap_err(); assert!(e.contains("a GeometryCollection must hold exactly one geometry"), "{cmd}: {e}"); } let e = s.run(cmd, &json!({"layer": "Cities", "row": 0, "geometry": {"type": "Blob"}})).unwrap_err(); assert!(e.contains("geometry must be a GeoJSON geometry"), "{cmd}: {e}"); } - // One member is the geometry. - s.run("edit.addFeature", &json!({"layer": "Cities", "geometry": {"type": "GeometryCollection", "geometries": [point]}})).unwrap(); + // One member, at any depth, is the geometry. + let one = json!({"type": "GeometryCollection", "geometries": [{"type": "GeometryCollection", "geometries": [point]}]}); + let added = s.run("edit.addFeature", &json!({"layer": "Cities", "geometry": one})).unwrap(); + let row = added["row"].as_u64().unwrap() as usize; + s.run("edit.setGeometry", &json!({"layer": "Cities", "row": 0, "geometry": one})).unwrap(); + let cities = &s.map().layer_by_name("Cities").unwrap().dataset; + for r in [row, 0] { + assert_eq!(cities.features[r].geometry, Some(Geometry::Point(Coord::new(1.0, 2.0))), "row {r}"); + } } #[test] From 50c17cd972830db4d299f249b2a32a1f377e76dd Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 03:37:56 -0500 Subject: [PATCH 10/12] Address review feedback - GML: count the rings and parts left out per feature type and say so with that type's layer, so adding only the second type of a file still gives the notice; test it. - Raster rounded counts: say the no-data comparison is made in f32. - Check edit.addFeature adds a row in the GeometryCollection test. --- crates/data/src/gml.rs | 41 +++++++++++++++++++++++++++-------- crates/data/src/raster/mod.rs | 4 +++- crates/engine/src/tests.rs | 2 ++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/crates/data/src/gml.rs b/crates/data/src/gml.rs index b22760b3a9..38215c4f35 100644 --- a/crates/data/src/gml.rs +++ b/crates/data/src/gml.rs @@ -244,6 +244,8 @@ struct Kind { rows: Vec<(Option, BTreeMap)>, /// Features whose Z or M values were dropped. zm: usize, + /// Rings and parts of its geometries left out. + lost: usize, } /// Reads a GML file into a layer per feature type (those with features). @@ -271,7 +273,6 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> let mut unknown_srs: Option = None; let mut over = 0usize; // Rings and parts left out of the geometries kept. - let mut parts_lost = 0usize; for f in members { let name = local(&f).to_string(); if !kinds.contains_key(&name) { @@ -287,6 +288,7 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> let mut bad = false; // Whether the geometry kept had Z or M values. let mut zm = false; + let mut parts_lost = 0; for p in f.children().filter(|c| c.is_element()) { // A property holding a geometry, or a simple value. // A feature's bounding box (gml:boundedBy) is neither its shape nor an attribute. @@ -338,17 +340,13 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> // A geometry that couldn't be read, unless another property gave the feature its shape. skipped += usize::from(bad && geom.is_none()); kind.zm += usize::from(zm && geom.is_some()); + kind.lost += parts_lost; kind.rows.push((geom, attrs)); } let mut report = ReadReport { skipped, ..ReadReport::default() }; if skipped > 0 { report.messages.push(format!("{skipped} features had geometry that couldn't be read")); } - if parts_lost > 0 { - report - .messages - .push(format!("{parts_lost} rings or parts of geometries were left out: too few points, unreadable coordinates, or an exterior ring past the first")); - } if over > 0 { report.messages.push(format!("{over} features of more than {MAX_LAYERS} feature types were left out")); } @@ -396,6 +394,13 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> 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()); } + // Said with the layer it happened in, which may be the only one added. + if kind.lost > 0 { + rep.messages.push(format!( + "{}: {} rings or parts of geometries were left out: too few points, unreadable coordinates, or an exterior ring past the first", + ds.name, kind.lost + )); + } if zm > 0 { ds.zm_dropped = true; rep.messages.push(format!("{}: {}", ds.name, crate::zm_note(Some(zm as u64)))); @@ -484,7 +489,7 @@ mod tests { "#; let layers = read("r.gml", gml.as_bytes()).unwrap(); assert!(!layers[0].0.zm_dropped, "{:?}", layers[0].1.messages); - assert!(layers[0].1.messages.iter().any(|m| m.starts_with("1 rings or parts")), "{:?}", layers[0].1.messages); + assert!(layers[0].1.messages.iter().any(|m| m.contains(": 1 rings or parts")), "{:?}", layers[0].1.messages); assert_eq!(layers[0].0.features[0].geometry, Some(Geometry::Line(vec![vec![Coord::new(10.0, 48.0), Coord::new(11.0, 49.0)]]))); // A two-point 3D interior ring is left out: the 2D polygon kept drops no Z, and the ring @@ -497,7 +502,7 @@ mod tests { "#; let layers = read("p.gml", gml.as_bytes()).unwrap(); assert!(!layers[0].0.zm_dropped, "{:?}", layers[0].1.messages); - assert!(layers[0].1.messages.iter().any(|m| m.starts_with("1 rings or parts")), "{:?}", layers[0].1.messages); + assert!(layers[0].1.messages.iter().any(|m| m.contains(": 1 rings or parts")), "{:?}", layers[0].1.messages); assert!(matches!(&layers[0].0.features[0].geometry, Some(Geometry::Polygon(p)) if p.len() == 1 && p[0].len() == 1)); } @@ -524,7 +529,25 @@ mod tests { assert_eq!((ds.features.len(), rep.skipped), (2, 0)); let said: Vec<&String> = rep.messages.iter().filter(|m| m.contains("rings or parts")).collect(); assert_eq!(said.len(), 1, "{:?}", rep.messages); - assert!(said[0].starts_with("2 rings or parts"), "{said:?}"); + assert!(said[0].contains(": 2 rings or parts"), "{said:?}"); + + // With two feature types, the notice goes with the one that lost a part, not the first. + let gml = r#" +10 48 11 49 + + 10 48 11 48 11 49 10 48 + 10 48 11 48 + +"#; + let layers = read("two.gml", gml.as_bytes()).unwrap(); + let said = |i: usize| layers[i].1.messages.iter().any(|m| m.contains("rings or parts")); + assert_eq!(layers.len(), 2); + assert!(!said(0) && said(1), "{:?}", layers.iter().map(|l| &l.1.messages).collect::>()); + assert!( + layers[1].1.messages.iter().any(|m| m.starts_with(&format!("{}: 1 rings", layers[1].0.name))), + "{:?}", + layers[1].1.messages + ); } #[test] diff --git a/crates/data/src/raster/mod.rs b/crates/data/src/raster/mod.rs index 8af5e0e112..3bf35f2ad6 100644 --- a/crates/data/src/raster/mod.rs +++ b/crates/data/src/raster/mod.rs @@ -578,7 +578,9 @@ pub struct Raster { pub lost: Vec, /// How many values of each band changed when read as `f32` (Int32 IDs past 16,777,216, Float64 /// values with more digits than `f32` holds), by band; empty when none did. NaN values and - /// samples that are exactly the no-data value aren't counted (one that rounds onto it is). + /// samples that are the no-data value aren't counted (one that rounds onto it is). The two are + /// compared once read as `f32`: a long decimal whose `f32` reading differs from the no-data + /// value's (rounded through `f64`) is counted, as it isn't masked as no-data either. pub rounded: Vec, transformer: Transformer, extent: Extent, diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 6618a65e31..05b8d6e035 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21810,8 +21810,10 @@ fn a_geometry_collection_of_several_is_refused_as_such() { } // One member, at any depth, is the geometry. let one = json!({"type": "GeometryCollection", "geometries": [{"type": "GeometryCollection", "geometries": [point]}]}); + let before = s.map().layer_by_name("Cities").unwrap().dataset.features.len(); let added = s.run("edit.addFeature", &json!({"layer": "Cities", "geometry": one})).unwrap(); let row = added["row"].as_u64().unwrap() as usize; + assert_eq!((row, s.map().layer_by_name("Cities").unwrap().dataset.features.len()), (before, before + 1)); s.run("edit.setGeometry", &json!({"layer": "Cities", "row": 0, "geometry": one})).unwrap(); let cities = &s.map().layer_by_name("Cities").unwrap().dataset; for r in [row, 0] { From a453700d0e5d793241dd88e61e9e1bdec6e2a28d Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 03:39:21 -0500 Subject: [PATCH 11/12] Address CodeRabbit review feedback - GML: the rings-left-out notice also names a polygon with no exterior ring; test it. --- crates/data/src/gml.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/data/src/gml.rs b/crates/data/src/gml.rs index 38215c4f35..a321f24639 100644 --- a/crates/data/src/gml.rs +++ b/crates/data/src/gml.rs @@ -397,7 +397,7 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> // Said with the layer it happened in, which may be the only one added. if kind.lost > 0 { rep.messages.push(format!( - "{}: {} rings or parts of geometries were left out: too few points, unreadable coordinates, or an exterior ring past the first", + "{}: {} rings or parts of geometries were left out: too few points, unreadable coordinates, a polygon with no exterior ring, or an exterior ring past the first", ds.name, kind.lost )); } @@ -548,6 +548,17 @@ mod tests { "{:?}", layers[1].1.messages ); + + // A surface's polygon with only an interior ring is left out and counted once. + let gml = r#" + + 10 48 11 48 11 49 10 48 + 10 48 11 48 11 49 10 48 + +"#; + let layers = read("hole.gml", gml.as_bytes()).unwrap(); + let said: Vec<&String> = layers[0].1.messages.iter().filter(|m| m.contains("rings or parts")).collect(); + assert!(said.len() == 1 && said[0].contains(": 1 rings") && said[0].contains("no exterior ring"), "{said:?}"); } #[test] From bfa26cdc79a0454bb53c8ccfd69195688cd0cbd3 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 8 Nov 2026 09:34:00 -0500 Subject: [PATCH 12/12] fix(data): say one ring or patch left out in the singular Address CodeRabbit review feedback: the GML notice read "1 rings or surface patches ... were left out". --- crates/data/src/gml.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/data/src/gml.rs b/crates/data/src/gml.rs index b1c02aa25f..ba9edbde90 100644 --- a/crates/data/src/gml.rs +++ b/crates/data/src/gml.rs @@ -501,8 +501,10 @@ pub fn read(file_name: &str, bytes: &[u8]) -> Result> } // Said with the layer it happened in, which may be the only one added. if kind.lost > 0 { + let what = + if kind.lost == 1 { "ring or surface patch of a geometry was" } else { "rings or surface patches of geometries were" }; rep.messages.push(format!( - "{}: {} rings or surface patches of geometries were left out: too few points, unreadable coordinates, a patch with no exterior ring, or an exterior ring past the first", + "{}: {} {what} left out: too few points, unreadable coordinates, a patch with no exterior ring, or an exterior ring past the first", ds.name, kind.lost )); } @@ -634,7 +636,11 @@ mod tests { "#; let layers = read("p.gml", gml.as_bytes()).unwrap(); assert!(!layers[0].0.zm_dropped, "{:?}", layers[0].1.messages); - assert!(layers[0].1.messages.iter().any(|m| m.contains(": 1 rings or surface patches")), "{:?}", layers[0].1.messages); + assert!( + layers[0].1.messages.iter().any(|m| m.contains(": 1 ring or surface patch of a geometry was left out")), + "{:?}", + layers[0].1.messages + ); assert!(matches!(&layers[0].0.features[0].geometry, Some(Geometry::Polygon(p)) if p.len() == 1 && p[0].len() == 1)); } @@ -643,11 +649,7 @@ mod tests { #[test] fn rings_and_parts_left_out_are_counted() { let layers = read("w.gml", WFS.as_bytes()).unwrap(); - assert!( - layers.iter().all(|(_, r)| !r.messages.iter().any(|m| m.contains("rings or surface patches"))), - "{:?}", - layers[0].1.messages - ); + assert!(layers.iter().all(|(_, r)| !r.messages.iter().any(|m| m.contains("or surface patch"))), "{:?}", layers[0].1.messages); // A second exterior ring is a ring left out; a multi-surface's polygon whose only ring is // two points is a part left out, said once, by the parts notice. let gml = r#" @@ -663,9 +665,9 @@ 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("rings or surface patches")).collect(); + let said: Vec<&String> = rep.messages.iter().filter(|m| m.contains("or surface patch")).collect(); assert_eq!(said.len(), 1, "{:?}", rep.messages); - assert!(said[0].contains(": 1 rings or surface patches"), "{said:?}"); + 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); // With two feature types, the notice goes with the one that lost a part, not the first. @@ -692,7 +694,7 @@ mod tests { "#; let layers = read("hole.gml", gml.as_bytes()).unwrap(); let messages = &layers[0].1.messages; - assert!(!messages.iter().any(|m| m.contains("rings or surface patches")), "{messages:?}"); + assert!(!messages.iter().any(|m| m.contains("or surface patch")), "{messages:?}"); assert!(messages.iter().any(|m| m.contains(": 1 part of multi-geometries")), "{messages:?}"); }