From e37a07bb3d7fe3b62e3eef1925954e9f3e847227 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 9 Nov 2026 19:44:16 -0700 Subject: [PATCH 1/5] =?UTF-8?q?fix(data):=20an=20export=20in=20Web=20Merca?= =?UTF-8?q?tor=20says=20what=20it=20writes=20at=2085.05=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Web Mercator ends at 85.05° north and south, and an export in it wrote every latitude beyond (an infinite one too) at 85.05° without saying so: the World Atlas's Countries lost Antarctica's southern edge. The export notices now count the vertices moved, from the layer's features, or name the layer from its source's extent when its features are only a window. What is written is unchanged. --- crates/data/src/io.rs | 64 +++++++++++++++++++++++++++++++++ crates/data/src/lib.rs | 39 ++++++++++++++++++++ crates/engine/src/tests.rs | 40 +++++++++++++++++++++ docs/user-guide/data-formats.md | 4 ++- 4 files changed, 146 insertions(+), 1 deletion(-) diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index 876ab041aa..257a008c9c 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -3457,6 +3457,70 @@ mod tests { ); } + /// An export in Web Mercator writes a latitude beyond 85.05°, an infinite one too, at 85.05°, + /// where Web Mercator ends, and says how many vertices it moved; for a streamed layer, its + /// source's extent tells. Within 85.05°, or in another system, nothing is said of it. + #[test] + fn a_web_mercator_export_says_what_it_writes_at_85_degrees() { + use rustgis_geom::{Extent, MAX_LAT, lonlat_to_merc, merc_to_lonlat}; + let c = Coord::new; + let ext = |ds: &Dataset| ds.extent(); + let layer = |name: &str, points: &[Coord]| { + let mut ds = Dataset::new(name, GeometryType::Point, vec![]); + for p in points { + ds.push(Some(Geometry::Point(*p)), vec![]); + } + ds + }; + let polar = layer("polar", &[c(10.0, 89.0), c(20.0, -90.0), c(30.0, 60.0), c(40.0, f64::INFINITY)]); + // What the export writes: each latitude beyond at 85.05°. + let merc = project(&polar, Crs::WebMercator).unwrap(); + let written: Vec = merc + .features + .iter() + .filter_map(|f| match f.geometry { + Some(Geometry::Point(p)) => Some(merc_to_lonlat(p)), + _ => None, + }) + .collect(); + assert_eq!(written.len(), 4); + for (w, lat) in written.iter().zip([MAX_LAT, -MAX_LAT, 60.0, MAX_LAT]) { + assert!((w.y - lat).abs() < 1e-9, "{w:?}"); + } + assert_eq!(merc.features[0].geometry, Some(Geometry::Point(lonlat_to_merc(c(10.0, MAX_LAT))))); + assert_eq!( + crate::export_notes([(&polar, ext(&polar))], "polar.shp", Crs::WebMercator), + ["polar.shp: 3 vertices of polar are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"] + ); + // In another system, or within 85.05°: nothing. + for crs in [Crs::LonLat, Crs::Epsg(32631)] { + assert!(crate::export_notes([(&polar, ext(&polar))], "polar.shp", crs).is_empty(), "{crs:?}"); + } + let within = layer("within", &[c(30.0, 60.0), c(0.0, -MAX_LAT)]); + assert!(crate::export_notes([(&within, ext(&within))], "within.shp", Crs::WebMercator).is_empty()); + // One vertex; and several layers in one notice, counting the vertices of all. + let one = layer("one", &[c(0.0, 86.0)]); + assert_eq!( + crate::export_notes([(&one, ext(&one))], "one.gpkg", Crs::WebMercator), + ["one.gpkg: 1 vertex of one is beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"] + ); + assert_eq!( + crate::export_notes([(&polar, ext(&polar)), (&within, ext(&within)), (&one, ext(&one))], "map.gpkg", Crs::WebMercator), + [ + "map.gpkg: 4 vertices of 2 layers (polar, one) are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends" + ] + ); + // A streamed layer's features are only those in view: its source's extent tells, without + // a count. + let mut window = layer("tiles", &[c(0.0, 0.0)]); + window.windowed = true; + assert_eq!( + crate::export_notes([(&window, Extent::new(-180.0, -90.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator), + ["tiles.gpkg: the parts of tiles are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"] + ); + assert!(crate::export_notes([(&window, Extent::new(-180.0, -80.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator).is_empty()); + } + #[test] fn wkt_geometries() { use crate::interop::parse_wkt; diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 28564991df..504fceefde 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -408,6 +408,8 @@ fn layer_list(names: &[&str]) -> String { /// body's name ([`raster::Crs::is_planetary`]). /// - Coordinates that aren't longitude/latitude (beyond ±180.5° or ±90.5°, as the readers check), /// which an export writes as if they were. +/// - Latitudes beyond 85.05° north or south, which an export in Web Mercator writes at 85.05°, +/// where it ends ([`rustgis_geom::lonlat_to_merc`]). pub fn export_notes<'a>( layers: impl IntoIterator, target: &str, @@ -471,9 +473,46 @@ pub fn export_notes<'a>( layer_list(&names) )), } + if crs == raster::Crs::WebMercator { + notes.extend(web_mercator_note(&layers, target)); + } notes } +/// What an export in Web Mercator says of the layers it writes past 85.05° north or south, where +/// Web Mercator ends: [`rustgis_geom::lonlat_to_merc`] writes a latitude beyond (an infinite one +/// too) at 85.05°. The vertices moved are counted from a layer's features; for a layer whose +/// features are only a window onto its source, or a streamed layer's whole source, its extent +/// tells instead, without a count. A missing coordinate, or an infinite longitude, isn't counted: +/// it can't be projected, so the export refuses it. +fn web_mercator_note(layers: &[(&Dataset, rustgis_geom::Extent)], target: &str) -> Option { + use rustgis_geom::MAX_LAT; + let beyond: Vec<(&str, Option)> = layers + .iter() + .filter_map(|(ds, e)| { + let mut moved = 0usize; + if !ds.windowed { + for g in ds.features.iter().filter_map(|f| f.geometry.as_ref()) { + g.for_each_coord(|c| moved += usize::from(c.x.is_finite() && c.y.abs() > MAX_LAT)); + } + } + let past = !e.is_empty() && (e.min_y < -MAX_LAT || e.max_y > MAX_LAT); + if moved > 0 { Some((ds.name.as_str(), Some(moved))) } else { past.then_some((ds.name.as_str(), None)) } + }) + .collect(); + let total: Option = beyond.iter().map(|(_, n)| *n).sum(); + let names: Vec<&str> = beyond.iter().map(|(name, _)| *name).collect(); + let what = match (names.as_slice(), total) { + ([], _) => return None, + (_, Some(1)) => format!("1 vertex of {} is", names.join(", ")), + ([one], Some(n)) => format!("{n} vertices of {one} are"), + ([one], None) => format!("the parts of {one} are"), + (_, Some(n)) => format!("{n} vertices of {} are", layer_list(&names)), + (_, None) => format!("the parts of {} are", layer_list(&names)), + }; + Some(format!("{target}: {what} beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends")) +} + /// Why exporting `ds` in `crs` would write other data than the layer's: a layer on another body /// projected onto another ellipsoid ([`raster::planetary::export_error`]). `None` when the export /// writes its numbers, which [`export_notes`] says when they go under another system's name. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index f13184a141..2dee538e64 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33277,6 +33277,46 @@ fn shapefile_exports_say_which_field_names_they_changed() { std::fs::remove_dir_all(dir).unwrap(); } +/// Exporting to Web Mercator says how many vertices beyond 85.05° it writes at 85.05°, where Web +/// Mercator ends: the World Atlas's countries reach the South Pole, and the file's stop at 85.05° +/// south. In longitude/latitude nothing is said of it. +#[test] +fn web_mercator_exports_say_what_they_write_at_85_degrees() { + let dir = std::env::temp_dir().join(format!("rustgis-engine-merc-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let mut s = world(); + let said = |s: &Session, mark| -> Vec { + s.notices_since(mark).iter().filter(|n| n.text.contains("where Web Mercator ends")).map(|n| n.text.clone()).collect() + }; + let south = |s: &Session, id: u32| s.map().layer(id).unwrap().dataset.extent().min_y; + let mut beyond = 0; + for g in + s.map().layers.iter().filter(|l| l.name == "Countries").flat_map(|l| l.dataset.features.iter()).filter_map(|f| f.geometry.as_ref()) + { + g.for_each_coord(|c| beyond += usize::from(c.y.abs() > rustgis_geom::MAX_LAT)); + } + assert!(beyond > 0); + let out = dir.join("countries.shp").display().to_string(); + let mark = s.notice_mark(); + s.run("share.exportLayer", &json!({"layer": "Countries", "path": out, "crs": "EPSG:3857"})).unwrap(); + assert_eq!( + said(&s, mark), + [format!("{out}: {beyond} vertices of Countries are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends")], + "{:?}", + s.notices_since(mark) + ); + let back = s.run("layer.addData", &json!({"path": out})).unwrap()["layer"].as_u64().unwrap() as u32; + assert!((south(&s, back) + rustgis_geom::MAX_LAT).abs() < 1e-6, "{}", south(&s, back)); + // In longitude/latitude, the South Pole is kept and nothing is said of it. + let mark = s.notice_mark(); + let lonlat = dir.join("countries-4326.shp"); + s.run("share.exportLayer", &json!({"layer": "Countries", "path": lonlat, "crs": "EPSG:4326"})).unwrap(); + assert!(said(&s, mark).is_empty(), "{:?}", s.notices_since(mark)); + let back = s.run("layer.addData", &json!({"path": lonlat})).unwrap()["layer"].as_u64().unwrap() as u32; + assert!(south(&s, back) < -rustgis_geom::MAX_LAT, "{}", south(&s, back)); + std::fs::remove_dir_all(dir).unwrap(); +} + #[test] fn a_cancelled_tool_leaves_the_map_as_it_was_and_says_so_in_the_history() { let mut s = world(); diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index a35a4f10d7..8a568cf0c1 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -617,7 +617,9 @@ coordinate system defined in a file whose datum has no shift to WGS 84 (a NAD 27 another system says so; written back in that same system they are exact, and nothing is said. Coordinates beyond ±180.5° longitude or ±90.5° latitude (a CSV of eastings and northings without its `"crs"`, a Shapefile without its `.prj`) aren't longitude/latitude: an export says they're out of -place, and Define Projection, below, places them. +place, and Define Projection, below, places them. Web Mercator (EPSG:3857) ends at 85.05° north and +south: an export in it writes a latitude beyond (Antarctica near the South Pole, say) at 85.05°, and says how many +vertices it moved, or for a layer read in place, which layer had them. Coordinate systems of other bodies than the Earth (Mars, the Moon and the rest of the IAU's `IAU_2015` codes, or any datum whose ellipsoid isn't the Earth's) aren't read as such yet: every From 5e0c79756244de50d4e82f7255ca54f4dc9cf806 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 9 Nov 2026 20:13:35 -0700 Subject: [PATCH 2/5] test(engine): an export in longitude/latitude keeps the layer's own southern edge --- crates/engine/src/tests.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 2dee538e64..1a369e7211 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33307,13 +33307,15 @@ fn web_mercator_exports_say_what_they_write_at_85_degrees() { ); let back = s.run("layer.addData", &json!({"path": out})).unwrap()["layer"].as_u64().unwrap() as u32; assert!((south(&s, back) + rustgis_geom::MAX_LAT).abs() < 1e-6, "{}", south(&s, back)); - // In longitude/latitude, the South Pole is kept and nothing is said of it. + // In longitude/latitude, the layer's southern edge is kept as it is, and nothing is said of it. + let source_south = s.map().layers.iter().find(|l| l.name == "Countries").unwrap().dataset.extent().min_y; + assert!(source_south < -rustgis_geom::MAX_LAT, "{source_south}"); let mark = s.notice_mark(); let lonlat = dir.join("countries-4326.shp"); s.run("share.exportLayer", &json!({"layer": "Countries", "path": lonlat, "crs": "EPSG:4326"})).unwrap(); assert!(said(&s, mark).is_empty(), "{:?}", s.notices_since(mark)); let back = s.run("layer.addData", &json!({"path": lonlat})).unwrap()["layer"].as_u64().unwrap() as u32; - assert!(south(&s, back) < -rustgis_geom::MAX_LAT, "{}", south(&s, back)); + assert!((south(&s, back) - source_south).abs() < 1e-6, "{} for {source_south}", south(&s, back)); std::fs::remove_dir_all(dir).unwrap(); } From b8f2a03224f268c169a85681a83160e700b7d17c Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 10 Nov 2026 04:56:20 -0700 Subject: [PATCH 3/5] =?UTF-8?q?fix(data):=20the=2085.05=C2=B0=20notice=20c?= =?UTF-8?q?ounts=20what=20the=20file=20holds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An export passed every layer's extent to the Web Mercator notice, so a raster layer, which writes no vertices, was said to have parts beyond 85.05°, and a streamed layer read whole was judged by the extent its source declares. The extent of the features written is passed now, and the source's only for a layer written a chunk at a time, where the notice says only that the extent reaches beyond. A Shapefile holds only geometry of the layer's kind, and of it only parts it can draw: the count now leaves out what it doesn't write (io::shapefile_vertices), as the file read back shows. --- crates/data/src/io.rs | 75 ++++++++++++++++++++++++++++++++- crates/data/src/lib.rs | 40 ++++++++++++------ crates/engine/src/cmd/share.rs | 7 ++- crates/engine/src/tests.rs | 38 +++++++++++++++++ crates/ui-egui/src/lib.rs | 4 +- docs/user-guide/data-formats.md | 5 ++- 6 files changed, 150 insertions(+), 19 deletions(-) diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index 257a008c9c..ebf9d2d72e 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -2641,6 +2641,26 @@ fn shapefile_keeps(g: Option<&Geometry>, gt: GeometryType) -> bool { } } +/// Calls `f` with each vertex of `g` that [`shapefile_parts_in`] writes, in a layer of type `gt`, +/// once a projected export has made every coordinate finite (`project` refuses one it can't): +/// none of another kind than the layer's, and of a line or a polygon only the parts it can draw, +/// a line part of two vertices, a ring of three (a polygon's holes go with its outer ring). +pub(crate) fn shapefile_vertices(g: &Geometry, gt: GeometryType, f: impl FnMut(Coord)) { + match (g, gt) { + (Geometry::Point(_) | Geometry::MultiPoint(_), GeometryType::Point) => g.for_each_coord(f), + (Geometry::Line(parts), GeometryType::Polyline) => parts.iter().filter(|p| p.len() >= 2).flatten().copied().for_each(f), + (Geometry::Polygon(polys), GeometryType::Polygon) => polys + .iter() + .filter(|p| p.first().is_some_and(|outer| outer.len() >= 3)) + .flatten() + .filter(|r| r.len() >= 3) + .flatten() + .copied() + .for_each(f), + _ => {} + } +} + /// A dataset as the files of a Shapefile: (extension, bytes) for `.shp`, `.shx`, `.dbf`, `.prj` /// (WGS 84) and `.cpg` (UTF-8). Shapefiles hold one kind of shape and features with geometry: /// features without it (or with nothing drawable) are left out, and the count of them returned. @@ -3511,14 +3531,65 @@ mod tests { ] ); // A streamed layer's features are only those in view: its source's extent tells, without - // a count. + // a count, and only that it reaches beyond, as a source can declare a wider one than its + // data's. let mut window = layer("tiles", &[c(0.0, 0.0)]); window.windowed = true; assert_eq!( crate::export_notes([(&window, Extent::new(-180.0, -90.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator), - ["tiles.gpkg: the parts of tiles are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"] + [ + "tiles.gpkg: the extent of tiles reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°, where Web Mercator ends" + ] ); assert!(crate::export_notes([(&window, Extent::new(-180.0, -80.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator).is_empty()); + // A Shapefile holds only geometry of the layer's kind, and of it only parts it can draw: + // the vertices it leaves out aren't counted, though a GeoPackage holds them. Of the lines, + // the 2 vertices of the first are written, not the one-vertex part or the point. Of the + // polygons, the 4 of the first one's three-vertex hole, not its two-vertex one, nor the + // second polygon, whose outer ring has 2 vertices, with its hole. + let mut lines = Dataset::new("lines", GeometryType::Polyline, vec![]); + lines.push(Some(Geometry::Line(vec![vec![c(0.0, 88.0), c(10.0, 88.0)]])), vec![]); + lines.push(Some(Geometry::Line(vec![vec![c(0.0, 89.0)], vec![c(0.0, 0.0), c(1.0, 0.0)]])), vec![]); + lines.push(Some(Geometry::Point(c(5.0, 89.0))), vec![]); + let mut polys = Dataset::new("polys", GeometryType::Polygon, vec![]); + let ring = |r: &[(f64, f64)]| r.iter().map(|&(x, y)| c(x, y)).collect::>(); + polys.push( + Some(Geometry::Polygon(vec![vec![ + ring(&[(0.0, 0.0), (0.0, 10.0), (10.0, 10.0), (0.0, 0.0)]), + ring(&[(1.0, 86.0), (2.0, 86.0), (1.5, 87.0), (1.0, 86.0)]), + ring(&[(3.0, 89.0), (3.0, 89.0)]), + ]])), + vec![], + ); + polys.push( + Some(Geometry::Polygon(vec![vec![ + ring(&[(0.0, 89.0), (1.0, 89.0)]), + ring(&[(0.0, 86.0), (1.0, 86.0), (1.0, 87.0), (0.0, 86.0)]), + ]])), + vec![], + ); + for (ds, in_shapefile, in_geopackage) in [(&lines, 2, 4), (&polys, 4, 12)] { + let name = ds.name.as_str(); + for (target, n) in + [(format!("{name}.shp"), in_shapefile), (format!("{name}.zip"), in_shapefile), (format!("{name}.gpkg"), in_geopackage)] + { + assert_eq!( + crate::export_notes([(ds, ext(ds))], &target, Crs::WebMercator), + [format!( + "{target}: {n} vertices of {name} are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends" + )] + ); + } + // As many as the Shapefile written holds at 85.05°. + let (zip, _) = write_bytes_in(ds, "shp", Crs::WebMercator).unwrap(); + let mut at_edge = 0; + for (back, _) in read_zip(&format!("{name}.zip"), &zip).unwrap() { + for g in back.features.iter().filter_map(|f| f.geometry.as_ref()) { + g.for_each_coord(|c| at_edge += usize::from((c.y.abs() - MAX_LAT).abs() < 1e-6)); + } + } + assert_eq!(at_edge, in_shapefile, "{name}"); + } } #[test] diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 504fceefde..6c87580a37 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -481,19 +481,33 @@ pub fn export_notes<'a>( /// What an export in Web Mercator says of the layers it writes past 85.05° north or south, where /// Web Mercator ends: [`rustgis_geom::lonlat_to_merc`] writes a latitude beyond (an infinite one -/// too) at 85.05°. The vertices moved are counted from a layer's features; for a layer whose -/// features are only a window onto its source, or a streamed layer's whole source, its extent -/// tells instead, without a count. A missing coordinate, or an infinite longitude, isn't counted: -/// it can't be projected, so the export refuses it. +/// too) at 85.05°. The vertices moved are counted from a layer's features, those the file holds: +/// a Shapefile target (`.shp`, or zipped to `.zip`, as the exports name it) holds only geometry of +/// the layer's kind, and of it only parts it can draw ([`io::shapefile_vertices`]). A missing +/// coordinate, or an infinite longitude, isn't counted: it can't be projected, so the export +/// refuses it. A layer whose features are only a window onto its source, or a streamed layer +/// written a chunk at a time (which comes with no features), has its extent tell instead, without +/// a count; as a source can declare a wider extent than its data's, that notice says only that +/// the extent reaches beyond. The count is one pass over the coordinates, without a Cancel point, +/// as the other notices' passes are. fn web_mercator_note(layers: &[(&Dataset, rustgis_geom::Extent)], target: &str) -> Option { use rustgis_geom::MAX_LAT; + let shapefile = std::path::Path::new(target) + .extension() + .and_then(|e| e.to_str()) + .is_some_and(|e| e.eq_ignore_ascii_case("shp") || e.eq_ignore_ascii_case("zip")); let beyond: Vec<(&str, Option)> = layers .iter() .filter_map(|(ds, e)| { let mut moved = 0usize; if !ds.windowed { + let mut count = |c: Coord| moved += usize::from(c.x.is_finite() && c.y.abs() > MAX_LAT); for g in ds.features.iter().filter_map(|f| f.geometry.as_ref()) { - g.for_each_coord(|c| moved += usize::from(c.x.is_finite() && c.y.abs() > MAX_LAT)); + if shapefile { + crate::io::shapefile_vertices(g, ds.geometry_type, &mut count); + } else { + g.for_each_coord(&mut count); + } } } let past = !e.is_empty() && (e.min_y < -MAX_LAT || e.max_y > MAX_LAT); @@ -502,15 +516,17 @@ fn web_mercator_note(layers: &[(&Dataset, rustgis_geom::Extent)], target: &str) .collect(); let total: Option = beyond.iter().map(|(_, n)| *n).sum(); let names: Vec<&str> = beyond.iter().map(|(name, _)| *name).collect(); - let what = match (names.as_slice(), total) { + let said = match (names.as_slice(), total) { ([], _) => return None, - (_, Some(1)) => format!("1 vertex of {} is", names.join(", ")), - ([one], Some(n)) => format!("{n} vertices of {one} are"), - ([one], None) => format!("the parts of {one} are"), - (_, Some(n)) => format!("{n} vertices of {} are", layer_list(&names)), - (_, None) => format!("the parts of {} are", layer_list(&names)), + (_, Some(1)) => format!("1 vertex of {} is beyond 85.05° north or south, and written at 85.05°", names.join(", ")), + ([one], Some(n)) => format!("{n} vertices of {one} are beyond 85.05° north or south, and written at 85.05°"), + (_, Some(n)) => format!("{n} vertices of {} are beyond 85.05° north or south, and written at 85.05°", layer_list(&names)), + ([one], None) => format!("the extent of {one} reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°"), + (_, None) => { + format!("the extents of {} reach beyond 85.05° north or south, and what lies beyond is written at 85.05°", layer_list(&names)) + } }; - Some(format!("{target}: {what} beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends")) + Some(format!("{target}: {said}, where Web Mercator ends")) } /// Why exporting `ds` in `crs` would write other data than the layer's: a layer on another body diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index e8a5afb121..b6cfcbf047 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -633,8 +633,11 @@ fn write_layer(l: &rustgis_map::Layer, path: &str, asked: Option, gpkg: Gpk (ds.features.len().saturating_sub(left_out), left_out, unread, table, unfit) } }; - // A streamed layer's extent is its whole source's. - let notes = rustgis_data::export_notes([(ds, l.extent())], path, crs); + // The features written give their own extent. A streamed layer written a chunk at a time has + // none at hand, and its whole source's extent tells instead. (A raster layer's extent is its + // raster's, which the file doesn't hold.) + let extent = if chunks.is_some() { l.extent() } else { ds.extent() }; + let notes = rustgis_data::export_notes([(ds, extent)], path, crs); // A Shapefile (`.shp`, or zipped to `.zip`) cuts field names to dBase's. let shapefile = matches!(ext.as_str(), "shp" | "zip"); let mut dbf_notes = Vec::new(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1a369e7211..9ed5c758a7 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33316,6 +33316,44 @@ fn web_mercator_exports_say_what_they_write_at_85_degrees() { assert!(said(&s, mark).is_empty(), "{:?}", s.notices_since(mark)); let back = s.run("layer.addData", &json!({"path": lonlat})).unwrap()["layer"].as_u64().unwrap() as u32; assert!((south(&s, back) - source_south).abs() < 1e-6, "{} for {source_south}", south(&s, back)); + // A raster layer reaching the poles writes no vertices: nothing is said of 85.05°. + let world_tif = { + use base64::Engine; + use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster, geotiff}; + let gt = GeoTransform { origin_x: -180.0, origin_y: 90.0, pixel_width: 45.0, pixel_height: -45.0 }; + let bands = (0..3).map(|b| (0..32).map(|i| ((i * 7 + b * 40) % 256) as f32).collect()).collect(); + let r = Raster::new("globe", 8, 4, bands, gt, Crs::LonLat, None, ColorHint::Rgb { alpha: false }, "UInt8").unwrap(); + base64::engine::general_purpose::STANDARD.encode(geotiff::write(&r, 0).unwrap()) + }; + let globe = s.run("layer.addDataBytes", &json!({"fileName": "globe.tif", "data": world_tif})).unwrap()["layer"].as_u64().unwrap(); + assert!(s.map().layer(globe as u32).unwrap().is_raster()); + let mark = s.notice_mark(); + let out = dir.join("globe.gpkg").display().to_string(); + let _ = s.run("share.exportLayer", &json!({"layer": globe, "path": out, "crs": "EPSG:3857"})); + assert!(said(&s, mark).is_empty(), "{:?}", s.notices_since(mark)); + // Streamed, the countries exported a chunk at a time (to a GeoPackage) have their source's + // extent tell, without a count; read whole (for a Shapefile), they're counted. + let gpkg = dir.join("countries.gpkg").display().to_string(); + s.run("share.exportLayer", &json!({"layer": "Countries", "path": gpkg, "crs": "EPSG:4326"})).unwrap(); + s.run("layer.addData", &json!({"path": gpkg, "stream": true, "name": "Streamed"})).unwrap(); + for (file, notice) in [ + ( + "streamed.gpkg", + "the extent of Streamed reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°, where Web Mercator ends" + .to_string(), + ), + ( + "streamed.shp", + format!("{beyond} vertices of Streamed are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"), + ), + ] { + let out = dir.join(file).display().to_string(); + let mark = s.notice_mark(); + s.run("share.exportLayer", &json!({"layer": "Streamed", "path": out, "crs": "EPSG:3857"})).unwrap(); + assert_eq!(said(&s, mark), [format!("{out}: {notice}")], "{:?}", s.notices_since(mark)); + } + // The streamed layer holds its GeoPackage open (Windows won't delete it till it's closed). + drop(s); std::fs::remove_dir_all(dir).unwrap(); } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f6c119d1f6..a17760ddd0 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -3966,7 +3966,9 @@ impl RustGisApp { }; let ext = if ext == "shp" { "zip".to_string() } else { ext }; let name = format!("{}.{ext}", l.name); - let notes = rustgis_engine::data::export_notes([(ds, l.extent())], &name, crs); + // The features written, read whole, give their own extent (not a raster's, or the + // one a streamed layer's source declares). + let notes = rustgis_engine::data::export_notes([(ds, ds.extent())], &name, crs); let mut dbf_notes = Vec::new(); if ext == "zip" { dbf_notes.extend(io::shapefile_names_note(&ds.fields, &name)); diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index 8a568cf0c1..dfe15dbeb2 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -618,8 +618,9 @@ another system says so; written back in that same system they are exact, and not Coordinates beyond ±180.5° longitude or ±90.5° latitude (a CSV of eastings and northings without its `"crs"`, a Shapefile without its `.prj`) aren't longitude/latitude: an export says they're out of place, and Define Projection, below, places them. Web Mercator (EPSG:3857) ends at 85.05° north and -south: an export in it writes a latitude beyond (Antarctica near the South Pole, say) at 85.05°, and says how many -vertices it moved, or for a layer read in place, which layer had them. +south: an export in it writes a latitude beyond (Antarctica near the South Pole, say, or an infinite +one) at 85.05°, and says how many of the vertices the file holds it moved. For a layer read in place +and written a chunk at a time, its source's extent tells instead, without a count. Coordinate systems of other bodies than the Earth (Mars, the Moon and the rest of the IAU's `IAU_2015` codes, or any datum whose ellipsoid isn't the Earth's) aren't read as such yet: every From dbc4d7b6a720b0bf3e0da5afb93761e58142486a Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 10 Nov 2026 06:10:59 -0700 Subject: [PATCH 4/5] =?UTF-8?q?fix(data):=20a=20chunked=20Web=20Mercator?= =?UTF-8?q?=20export=20counts=20what=20it=20writes=20at=2085.05=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A streamed layer written a chunk at a time comes with no features, so its 85.05° notice went by the extent: the one its source declares, or the loaded window when it declares none, which can leave out polar features and say nothing of them. The chunk writer now counts the vertices beyond 85.05° as it writes them (Exported::beyond_web_mercator), and the export says the count. The extent stands in only for a windowed layer now. --- crates/data/src/export.rs | 15 ++++++++++++- crates/data/src/export/tests.rs | 37 ++++++++++++++++++++++++++++++++- crates/data/src/io.rs | 4 ++++ crates/data/src/lib.rs | 30 ++++++++++++++++++++------ crates/engine/src/cmd/share.rs | 15 +++++++------ crates/engine/src/tests.rs | 19 +++++------------ docs/user-guide/data-formats.md | 4 ++-- 7 files changed, 94 insertions(+), 30 deletions(-) diff --git a/crates/data/src/export.rs b/crates/data/src/export.rs index 40fad08759..f90071d223 100644 --- a/crates/data/src/export.rs +++ b/crates/data/src/export.rs @@ -36,6 +36,9 @@ pub struct Exported { /// them (GeoParquet; empty for the other formats). See /// [`crate::source::parquet::unfit_note`]. pub unfit: Vec, + /// Vertices beyond 85.05° north or south, written at 85.05° by an export in Web Mercator, + /// where it ends (0 in another system). See [`crate::web_mercator_moved_note`]. + pub beyond_web_mercator: usize, } /// Writes every feature of `src` to `path` in the format of its extension, in `crs` (see @@ -95,12 +98,22 @@ fn write_chunks_to( let t = if crs == Crs::LonLat { None } else { Some(crs.transformer().map_err(DataError::Format)?) }; let mut total = 0usize; let mut skipped = 0usize; + let mut beyond_web_mercator = 0usize; let mut feed = |add: &mut dyn FnMut(&[Feature]) -> Result<()>| -> Result<()> { // A GeoPackage export that starts again feeds the features again, and counts them again. total = 0; + beyond_web_mercator = 0; // The writers count the features; a source that doesn't know how many leaves the total at 0. crate::progress::begin(src.info().count.map_or(0, |n| usize::try_from(n).unwrap_or(usize::MAX))); let batch = src.visit_chunks(None, bytes, &mut |mut chunk| { + // Counted from the longitude/latitude, before projecting. Every vertex is written: + // the formats written in Web Mercator a chunk at a time (GeoPackage, FlatGeobuf) + // leave out only features without geometry. + if crs == Crs::WebMercator { + for g in chunk.iter().filter_map(|f| f.geometry.as_ref()) { + g.for_each_coord(|c| beyond_web_mercator += usize::from(c.x.is_finite() && c.y.abs() > rustgis_geom::MAX_LAT)); + } + } if let Some(t) = &t { // Counted as the writer writes them, so only stopped on a cancel here. project_each(&mut chunk, t, crs, false)?; @@ -146,7 +159,7 @@ fn write_chunks_to( Ok::<_, DataError>(0) })?, }; - Ok((Exported { written: total.saturating_sub(left_out), left_out, skipped, unfit }, table)) + Ok((Exported { written: total.saturating_sub(left_out), left_out, skipped, unfit, beyond_web_mercator }, table)) } /// The kind of a source's first geometry, read up to it; `None` for a source without any (read diff --git a/crates/data/src/export/tests.rs b/crates/data/src/export/tests.rs index b7e05cd1a6..7a518166cf 100644 --- a/crates/data/src/export/tests.rs +++ b/crates/data/src/export/tests.rs @@ -103,6 +103,40 @@ impl FeatureSource for Runs { } } +/// An export in Web Mercator written a chunk at a time counts the vertices beyond 85.05° it +/// writes at 85.05°, as it writes them: from a source that declares no extent, whose features +/// beyond aren't in its first chunk. In longitude/latitude, or within 85.05°, it counts none. +#[test] +fn a_streamed_web_mercator_export_counts_what_it_writes_at_85_degrees() { + let d = folder("merc"); + let mut ds = Dataset::new("polar", GeometryType::Point, vec![]); + for (x, y) in [(0.0, 0.0), (1.0, 10.0), (2.0, 89.0), (3.0, -90.0), (4.0, 60.0), (5.0, 86.0)] { + ds.push_next(Some(Geometry::Point(Coord::new(x, y))), vec![]); + } + ds.push_next(None, vec![]); + let mut src = Runs::new(&ds, 2); + src.info.extent = rustgis_geom::Extent::EMPTY; + for ext in ["gpkg", "fgb"] { + for (crs, n) in [(Crs::WebMercator, 3), (Crs::LonLat, 0)] { + let path = d.join(format!("polar-{}.{ext}", crs.epsg())); + let e = write_chunks_in(&src, &ds, &path, crs, 1).unwrap(); + assert_eq!(e.beyond_web_mercator, n, ".{ext} in {}", crs.label()); + // As many as the file holds at 85.05°. + let mut at_edge = 0; + for g in read_back(&path).features.iter().filter_map(|f| f.geometry.as_ref()) { + g.for_each_coord(|c| at_edge += usize::from((c.y.abs() - rustgis_geom::MAX_LAT).abs() < 1e-6)); + } + assert_eq!(at_edge, n, ".{ext} in {}", crs.label()); + } + } + assert_eq!( + crate::web_mercator_moved_note("polar.gpkg", "polar", 3).as_deref(), + Some("polar.gpkg: 3 vertices of polar are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends") + ); + assert_eq!(crate::web_mercator_moved_note("polar.gpkg", "polar", 0), None); + let _ = std::fs::remove_dir_all(d); +} + /// Every streamed format, from a source read in place a few features a chunk, holds what the /// same export of the whole layer holds, in longitude/latitude and in a projected system. #[test] @@ -130,7 +164,8 @@ fn a_streamed_export_writes_what_a_whole_export_writes() { let what = format!("{format} to .{ext} in {}", crs.label()); let unfit = streamed.unfit.clone(); assert!(unfit.iter().all(|n| *n == 0), "{what}: {unfit:?}"); - assert_eq!(streamed, Exported { written: whole.features.len() - left_out, left_out, skipped: 0, unfit }, "{what}"); + let expected = Exported { written: whole.features.len() - left_out, left_out, skipped: 0, unfit, beyond_web_mercator: 0 }; + assert_eq!(streamed, expected, "{what}"); let (a, b) = (read_back(&a), read_back(&b)); assert_eq!((&a.fields, a.geometry_type, a.crs), (&b.fields, b.geometry_type, b.crs), "{what}"); assert_eq!(a.features, b.features, "{what}"); diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index ebf9d2d72e..3d36a3dde7 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -3542,6 +3542,10 @@ mod tests { ] ); assert!(crate::export_notes([(&window, Extent::new(-180.0, -80.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator).is_empty()); + // A layer without features that isn't a window (a raster layer's, or a streamed layer's + // written a chunk at a time, whose export counts as it writes) has no extent tell. + let empty = Dataset::new("empty", GeometryType::Point, vec![]); + assert!(crate::export_notes([(&empty, Extent::new(-180.0, -90.0, 180.0, 90.0))], "empty.gpkg", Crs::WebMercator).is_empty()); // A Shapefile holds only geometry of the layer's kind, and of it only parts it can draw: // the vertices it leaves out aren't counted, though a GeoPackage holds them. Of the lines, // the 2 vertices of the first are written, not the one-vertex part or the point. Of the diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 6c87580a37..e6d4c5c566 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -485,11 +485,12 @@ pub fn export_notes<'a>( /// a Shapefile target (`.shp`, or zipped to `.zip`, as the exports name it) holds only geometry of /// the layer's kind, and of it only parts it can draw ([`io::shapefile_vertices`]). A missing /// coordinate, or an infinite longitude, isn't counted: it can't be projected, so the export -/// refuses it. A layer whose features are only a window onto its source, or a streamed layer -/// written a chunk at a time (which comes with no features), has its extent tell instead, without -/// a count; as a source can declare a wider extent than its data's, that notice says only that -/// the extent reaches beyond. The count is one pass over the coordinates, without a Cancel point, -/// as the other notices' passes are. +/// refuses it. A layer whose features are only a window onto its source (`windowed`) has its +/// extent tell instead, without a count; as a source can declare a wider extent than its data's, +/// that notice says only that the extent reaches beyond. A streamed layer written a chunk at a +/// time comes with no features, and its export counts them as it writes them +/// ([`export::Exported::beyond_web_mercator`], said by [`web_mercator_moved_note`]). The count is +/// one pass over the coordinates, without a Cancel point, as the other notices' passes are. fn web_mercator_note(layers: &[(&Dataset, rustgis_geom::Extent)], target: &str) -> Option { use rustgis_geom::MAX_LAT; let shapefile = std::path::Path::new(target) @@ -510,10 +511,27 @@ fn web_mercator_note(layers: &[(&Dataset, rustgis_geom::Extent)], target: &str) } } } - let past = !e.is_empty() && (e.min_y < -MAX_LAT || e.max_y > MAX_LAT); + let past = ds.windowed && !e.is_empty() && (e.min_y < -MAX_LAT || e.max_y > MAX_LAT); if moved > 0 { Some((ds.name.as_str(), Some(moved))) } else { past.then_some((ds.name.as_str(), None)) } }) .collect(); + web_mercator_said(&beyond, target) +} + +/// What an export in Web Mercator written a chunk at a time says of the `moved` vertices of +/// `layer` it wrote at 85.05° north or south, where Web Mercator ends, as it counted them +/// ([`export::Exported::beyond_web_mercator`]): as [`export_notes`] says it of a layer it has +/// whole. `None` for none. +pub fn web_mercator_moved_note(target: &str, layer: &str, moved: usize) -> Option { + if moved == 0 { + return None; + } + web_mercator_said(&[(layer, Some(moved))], target) +} + +/// The 85.05° notice for the layers `beyond` (each with its count of vertices moved, or `None` +/// when only its extent tells), or `None` for none. +fn web_mercator_said(beyond: &[(&str, Option)], target: &str) -> Option { let total: Option = beyond.iter().map(|(_, n)| *n).sum(); let names: Vec<&str> = beyond.iter().map(|(name, _)| *name).collect(); let said = match (names.as_slice(), total) { diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index b6cfcbf047..e5a8c56552 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -619,25 +619,28 @@ fn write_layer(l: &rustgis_map::Layer, path: &str, asked: Option, gpkg: Gpk return Err(format!("{path}: {e}")); } let parquet = matches!(ext.as_str(), "parquet" | "geoparquet"); - let (written, left_out, skipped, table, unfit) = match &chunks { + let (written, left_out, skipped, table, unfit, moved) = match &chunks { Some((src, layer)) => { let (e, table) = rustgis_data::export::write_source_to(src.as_ref(), layer, Path::new(&path), crs, &gpkg).map_err(|e| e.to_string())?; // Counted as the chunks were written, as the layer holds none of them. let unfit = rustgis_data::source::parquet::unfit_note(&layer.fields, &e.unfit, path); - (e.written, e.left_out, e.skipped, table, unfit) + let moved = rustgis_data::web_mercator_moved_note(path, &layer.name, e.beyond_web_mercator); + (e.written, e.left_out, e.skipped, table, unfit, moved) } None => { let (left_out, table) = rustgis_data::io::write_path_to(ds, Path::new(&path), crs, &gpkg).map_err(|e| e.to_string())?; let unfit = if parquet { rustgis_data::source::parquet::values_note(ds, path) } else { None }; - (ds.features.len().saturating_sub(left_out), left_out, unread, table, unfit) + (ds.features.len().saturating_sub(left_out), left_out, unread, table, unfit, None) } }; // The features written give their own extent. A streamed layer written a chunk at a time has - // none at hand, and its whole source's extent tells instead. (A raster layer's extent is its - // raster's, which the file doesn't hold.) + // none at hand, and its whole source's extent tells instead (the vertices written at 85.05° + // in Web Mercator, the export counted). A raster layer's extent is its raster's, which the + // file doesn't hold. let extent = if chunks.is_some() { l.extent() } else { ds.extent() }; - let notes = rustgis_data::export_notes([(ds, extent)], path, crs); + let mut notes = rustgis_data::export_notes([(ds, extent)], path, crs); + notes.extend(moved); // A Shapefile (`.shp`, or zipped to `.zip`) cuts field names to dBase's. let shapefile = matches!(ext.as_str(), "shp" | "zip"); let mut dbf_notes = Vec::new(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 9ed5c758a7..db8225b29d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33329,24 +33329,15 @@ fn web_mercator_exports_say_what_they_write_at_85_degrees() { assert!(s.map().layer(globe as u32).unwrap().is_raster()); let mark = s.notice_mark(); let out = dir.join("globe.gpkg").display().to_string(); - let _ = s.run("share.exportLayer", &json!({"layer": globe, "path": out, "crs": "EPSG:3857"})); + s.run("share.exportLayer", &json!({"layer": globe, "path": out, "crs": "EPSG:3857"})).unwrap(); assert!(said(&s, mark).is_empty(), "{:?}", s.notices_since(mark)); - // Streamed, the countries exported a chunk at a time (to a GeoPackage) have their source's - // extent tell, without a count; read whole (for a Shapefile), they're counted. + // Streamed, the countries are counted as they're written a chunk at a time (to a GeoPackage), + // whatever extent the source declares, and read whole (for a Shapefile), from their features. let gpkg = dir.join("countries.gpkg").display().to_string(); s.run("share.exportLayer", &json!({"layer": "Countries", "path": gpkg, "crs": "EPSG:4326"})).unwrap(); s.run("layer.addData", &json!({"path": gpkg, "stream": true, "name": "Streamed"})).unwrap(); - for (file, notice) in [ - ( - "streamed.gpkg", - "the extent of Streamed reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°, where Web Mercator ends" - .to_string(), - ), - ( - "streamed.shp", - format!("{beyond} vertices of Streamed are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"), - ), - ] { + let notice = format!("{beyond} vertices of Streamed are beyond 85.05° north or south, and written at 85.05°, where Web Mercator ends"); + for file in ["streamed.gpkg", "streamed.shp"] { let out = dir.join(file).display().to_string(); let mark = s.notice_mark(); s.run("share.exportLayer", &json!({"layer": "Streamed", "path": out, "crs": "EPSG:3857"})).unwrap(); diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index dfe15dbeb2..806f1b51ba 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -619,8 +619,8 @@ Coordinates beyond ±180.5° longitude or ±90.5° latitude (a CSV of eastings a `"crs"`, a Shapefile without its `.prj`) aren't longitude/latitude: an export says they're out of place, and Define Projection, below, places them. Web Mercator (EPSG:3857) ends at 85.05° north and south: an export in it writes a latitude beyond (Antarctica near the South Pole, say, or an infinite -one) at 85.05°, and says how many of the vertices the file holds it moved. For a layer read in place -and written a chunk at a time, its source's extent tells instead, without a count. +one) at 85.05°, and says how many of the vertices the file holds it moved; a layer read in place and +written a chunk at a time is counted as it's written. Coordinate systems of other bodies than the Earth (Mars, the Moon and the rest of the IAU's `IAU_2015` codes, or any datum whose ellipsoid isn't the Earth's) aren't read as such yet: every From 3a424cfa98c70bf4aa6db146a6a50ff9f7de1a2b Mon Sep 17 00:00:00 2001 From: giswqs Date: Tue, 10 Nov 2026 19:43:33 -0500 Subject: [PATCH 5/5] =?UTF-8?q?fix(data):=20the=2085.05=C2=B0=20notice=20s?= =?UTF-8?q?ays=20counted=20and=20extent-only=20layers=20both?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A layer counted and a windowed layer told by its extent made the notice fall back to extents for both, dropping the count. Each kind now gets its own clause in the one notice. Also corrects the comment on the extent write_layer passes for a chunk-written layer. --- crates/data/src/io.rs | 7 +++++++ crates/data/src/lib.rs | 38 +++++++++++++++++++++------------- crates/engine/src/cmd/share.rs | 6 +++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index a014cced02..c6c1e78514 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -3779,6 +3779,13 @@ mod tests { ] ); assert!(crate::export_notes([(&window, Extent::new(-180.0, -80.0, 180.0, 84.0))], "tiles.gpkg", Crs::WebMercator).is_empty()); + // A layer counted and a window told by its extent: one notice, saying both. + assert_eq!( + crate::export_notes([(&polar, ext(&polar)), (&window, Extent::new(-180.0, -90.0, 180.0, 84.0))], "map.gpkg", Crs::WebMercator), + [ + "map.gpkg: 3 vertices of polar are beyond 85.05° north or south, and written at 85.05°; the extent of tiles reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°, where Web Mercator ends" + ] + ); // A layer without features that isn't a window (a raster layer's, or a streamed layer's // written a chunk at a time, whose export counts as it writes) has no extent tell. let empty = Dataset::new("empty", GeometryType::Point, vec![]); diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 23527b4d0b..a9f6f7b4d2 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -543,21 +543,31 @@ pub fn web_mercator_moved_note(target: &str, layer: &str, moved: usize) -> Optio } /// The 85.05° notice for the layers `beyond` (each with its count of vertices moved, or `None` -/// when only its extent tells), or `None` for none. +/// when only its extent tells), or `None` for none. Layers counted and layers told by their +/// extent are said in one notice, each in its own clause, so neither hides the other. fn web_mercator_said(beyond: &[(&str, Option)], target: &str) -> Option { - let total: Option = beyond.iter().map(|(_, n)| *n).sum(); - let names: Vec<&str> = beyond.iter().map(|(name, _)| *name).collect(); - let said = match (names.as_slice(), total) { - ([], _) => return None, - (_, Some(1)) => format!("1 vertex of {} is beyond 85.05° north or south, and written at 85.05°", names.join(", ")), - ([one], Some(n)) => format!("{n} vertices of {one} are beyond 85.05° north or south, and written at 85.05°"), - (_, Some(n)) => format!("{n} vertices of {} are beyond 85.05° north or south, and written at 85.05°", layer_list(&names)), - ([one], None) => format!("the extent of {one} reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°"), - (_, None) => { - format!("the extents of {} reach beyond 85.05° north or south, and what lies beyond is written at 85.05°", layer_list(&names)) - } - }; - Some(format!("{target}: {said}, where Web Mercator ends")) + let counted: Vec<&str> = beyond.iter().filter(|(_, n)| n.is_some()).map(|(name, _)| *name).collect(); + let total: usize = beyond.iter().filter_map(|(_, n)| *n).sum(); + let extents: Vec<&str> = beyond.iter().filter(|(_, n)| n.is_none()).map(|(name, _)| *name).collect(); + let mut said = Vec::new(); + match (counted.as_slice(), total) { + ([], _) => {} + (_, 1) => said.push(format!("1 vertex of {} is beyond 85.05° north or south, and written at 85.05°", counted.join(", "))), + ([one], n) => said.push(format!("{n} vertices of {one} are beyond 85.05° north or south, and written at 85.05°")), + (_, n) => said.push(format!("{n} vertices of {} are beyond 85.05° north or south, and written at 85.05°", layer_list(&counted))), + } + match extents.as_slice() { + [] => {} + [one] => said.push(format!("the extent of {one} reaches beyond 85.05° north or south, and what lies beyond is written at 85.05°")), + _ => said.push(format!( + "the extents of {} reach beyond 85.05° north or south, and what lies beyond is written at 85.05°", + layer_list(&extents) + )), + } + if said.is_empty() { + return None; + } + Some(format!("{target}: {}, where Web Mercator ends", said.join("; "))) } /// Why exporting `ds` in `crs` would write other data than the layer's: a layer on another body diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index 5fc13b69df..c201be79db 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -645,9 +645,9 @@ fn write_layer(l: &rustgis_map::Layer, path: &str, asked: Option, gpkg: Gpk } }; // The features written give their own extent. A streamed layer written a chunk at a time has - // none at hand, and its whole source's extent tells instead (the vertices written at 85.05° - // in Web Mercator, the export counted). A raster layer's extent is its raster's, which the - // file doesn't hold. + // none at hand: its vertices beyond 85.05° in Web Mercator are counted as they're written + // (`e.beyond_web_mercator`), and its source's extent only serves the out-of-place check. A + // raster layer's extent is its raster's, which the file doesn't hold. let extent = if chunks.is_some() { l.extent() } else { ds.extent() }; let mut notes = rustgis_data::export_notes([(ds, extent)], path, crs); notes.extend(moved);