From 4b775719e2f65c89095beb275c7d4644fe64ecd3 Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 30 Nov 2026 07:39:41 -0600 Subject: [PATCH 1/2] fix(analysis): report the assumed XY coordinate system --- crates/analysis/src/tools.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index b51b34681e..6c899c7eb9 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -550,7 +550,7 @@ pub static TOOLS: &[ToolSpec] = &[ label: "Coordinate System", kind: K::Text, required: false, - default: "\"EPSG:4326\"", + default: "\"\"", help: "The coordinates' system, as EPSG: or WKT; longitude/latitude (EPSG:4326) when empty.", }, P { name: "output", label: "Output Name", kind: K::Text, required: false, default: "", help: "" }, @@ -4690,6 +4690,7 @@ fn crs_with_compatibility_note(text: &str) -> Result<(Crs, Option), Stri Ok((crs, rustgis_data::raster::wkt::typed_crs_note(text, crs))) } +/// Places points from two fields, whose system is independent of any input layer geometry. fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let field = |k: &str| { @@ -4697,7 +4698,8 @@ fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result { find_field_case_insensitive(ds, name) }; let (xi, yi) = (field("x")?, field("y")?); - let (crs, crs_note) = match s(p, "crs").trim() { + let crs_text = s(p, "crs").trim(); + let (crs, crs_note) = match crs_text { "" => (Crs::LonLat, None), text => crs_with_compatibility_note(text)?, }; @@ -4738,6 +4740,9 @@ fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result { }); } let mut messages = vec![format!("XY Table To Point: {placed} points")]; + if crs_text.is_empty() { + messages.push("XY Table To Point: WGS 84 (EPSG:4326) was assumed because no coordinate system was given".into()); + } let mut losses: Vec = Vec::new(); messages.extend(crs_note.map(|note| format!("XY Table To Point: its coordinate system: {note}"))); // A row without numbers had no place to lose; one whose numbers have no place in the system @@ -13970,6 +13975,7 @@ mod tests { assert_eq!( said(&r)[1..], [ + "XY Table To Point: WGS 84 (EPSG:4326) was assumed because no coordinate system was given", "3 of 7 rows have no numbers in both fields; they are in the table without a point", "DroppedGeometry: 1 of 7 rows have coordinates with no place in EPSG:4326; they are in the table without a point" ] @@ -14011,8 +14017,12 @@ mod tests { assert!(said(&r).iter().any(|m| m.starts_with("DroppedGeometry: 1 of 2 rows")), "{:?}", said(&r)); assert!(layer(r).features[1].geometry.is_none()); // Points in longitude/latitude are held there, with no system of their own, as before. - let lonlat = layer(run(serde_json::json!({"input": "stops", "x": "lon", "y": "lat", "crs": "EPSG:4326"})).unwrap()); - assert_eq!((lonlat.coord_crs(), lonlat.crs), (Crs::LonLat, None)); + for (crs, assumed) in [("", true), (" ", true), ("EPSG:4326", false)] { + let r = run(serde_json::json!({"input": "stops", "x": "lon", "y": "lat", "crs": crs})).unwrap(); + assert_eq!(r.messages.iter().filter(|m| m.contains("WGS 84 (EPSG:4326) was assumed")).count(), usize::from(assumed), "{crs:?}"); + let lonlat = layer(r); + assert_eq!((lonlat.coord_crs(), lonlat.crs), (Crs::LonLat, None)); + } // Metres read as longitude/latitude, fields without numbers, and junk parameters. let e = run(serde_json::json!({"input": "metres", "x": "e", "y": "n"})).unwrap_err(); From 9962be862f4ccda007ee64735135a558d48bd35b Mon Sep 17 00:00:00 2001 From: mavrick Date: Mon, 30 Nov 2026 08:43:17 -0600 Subject: [PATCH 2/2] fix(analysis): refuse non-text XY coordinate systems --- crates/analysis/src/tools.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 6c899c7eb9..54b806a507 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -4690,7 +4690,8 @@ fn crs_with_compatibility_note(text: &str) -> Result<(Crs, Option), Stri Ok((crs, rustgis_data::raster::wkt::typed_crs_note(text, crs))) } -/// Places points from two fields, whose system is independent of any input layer geometry. +/// Places points from X/Y fields in the requested system, or longitude/latitude when empty. +/// The input layer's geometry system does not determine these coordinates. fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result { let ds = input(inp, p, "input")?; let field = |k: &str| { @@ -4698,6 +4699,9 @@ fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result { find_field_case_insensitive(ds, name) }; let (xi, yi) = (field("x")?, field("y")?); + if p.get("crs").is_some_and(|v| !v.is_null() && !v.is_string()) { + return Err("crs must be text".into()); + } let crs_text = s(p, "crs").trim(); let (crs, crs_note) = match crs_text { "" => (Crs::LonLat, None), @@ -13970,6 +13974,8 @@ mod tests { let m = Map(HashMap::from([("stops".to_string(), stops), ("metres".to_string(), metres)])); let run = |p: serde_json::Value| crate::run("xyTableToPoint", &m, &p); + assert_eq!(run(serde_json::json!({"input": "stops", "x": "lon", "y": "lat", "crs": 3857})).unwrap_err(), "crs must be text"); + let r = run(serde_json::json!({"input": "stops", "x": "lon", "y": "lat"})).unwrap(); // Rows without numbers lose nothing; the one off the globe loses its place. assert_eq!(