diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 80aa9bdbe9..31a20febd7 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -1182,9 +1182,16 @@ impl Dataset { /// `results`, a dataset in longitude/latitude made from this one (a tool's update of it), in /// its own coordinates: as it is while they are longitude/latitude; otherwise each geometry /// written back as an edit is ([`Dataset::edit_from_lonlat`]), its stored places kept as - /// stored. Every stored place is read, but only those the results read as are held, so what is - /// held is as large as the results, not the layer. Refused, naming the first feature, when one - /// of its places can't be held in its system. + /// stored. Every stored place of `self` is read (for a streamed layer, its window: a place + /// outside it is converted back, exact to the conversion's round trip, not kept as stored), + /// but only those the results read as are held, so what is held is as large as the results, + /// not the layer. Refused, naming the first feature, when one + /// of its places can't be held in its system. A feature of the results without geometry whose + /// stored one has a place that can't be given in longitude/latitude, so it was read without it + /// ([`Dataset::in_lonlat_leaving_out`]), is left as stored, a field the results add empty: + /// every result field of it is taken from the stored feature (or empty), which assumes the + /// update's fields are worked out from geometry, as Calculate Geometry Attributes' are, the + /// only in-place update today. A tool updating attributes alone would need its own values kept. pub fn results_from_lonlat(&self, mut results: Dataset) -> std::result::Result { // Exact through WGS 84 both ways, as the results were read (`in_lonlat`), whatever map // the layer is shown on. @@ -1201,13 +1208,45 @@ impl Dataset { Self::hold_places_by(&read, g, None, &mut held); } } + // The stored features of the results without geometry whose stored geometry has a place + // that can't be given in longitude/latitude, by id: only those are converted again. The + // ids of the results without geometry, sorted (8 bytes each, at most the results' count; + // nothing when every result has geometry), and of the unplaced among them. + let mut bare: Vec = results.features.rows().filter(|r| r.geometry().is_none()).map(|r| r.id()).collect(); + bare.sort_unstable(); + let mut unplaced = std::collections::HashMap::new(); + if !bare.is_empty() { + for (i, f) in self.features.iter().enumerate() { + stop_when_asked(i)?; + if bare.binary_search(&f.id).is_ok() + && let Some(g) = &f.geometry + && convert_keeping_missing(&read, g, &HeldPlaces::default()).is_none() + { + unplaced.insert(f.id, f); + } + } + } // Before the rows are copied out of what shares them. stop_when_asked(0)?; for (i, f) in results.features.iter_mut().enumerate() { stop_when_asked(i)?; - if let Some(g) = f.geometry.take() { - f.geometry = - Some(Self::edit_from_lonlat_by(&write, g, &held).map_err(|e| format!("{}: feature {}: {e}", self.name, f.id))?); + match f.geometry.take() { + Some(g) => { + f.geometry = + Some(Self::edit_from_lonlat_by(&write, g, &held).map_err(|e| format!("{}: feature {}: {e}", self.name, f.id))?); + } + // Read without its geometry: left as it was, what the results add to it empty, as + // nothing was worked out from a geometry it wasn't given. + None => { + if let Some(stored) = unplaced.get(&f.id) { + f.geometry.clone_from(&stored.geometry); + for (k, field) in results.fields.iter().enumerate() { + if let Some(a) = f.attrs.get_mut(k) { + *a = self.field_index(&field.name).and_then(|j| stored.attrs.get(j)).cloned().unwrap_or(Value::Null); + } + } + } + } } } results.held_in = self.held_in; diff --git a/crates/engine/src/cmd/gp.rs b/crates/engine/src/cmd/gp.rs index 1ea1627713..53dee93e38 100644 --- a/crates/engine/src/cmd/gp.rs +++ b/crates/engine/src/cmd/gp.rs @@ -1312,6 +1312,10 @@ struct MapInputs<'a> { /// Streamed layers the tool reads, loaded whole, and copies of layers in another system than /// the one it works in, converted ([`work_inputs`]), by lowercase name. loaded: std::collections::HashMap, + /// The layers read whole for the run (streamed ones) with features read without their + /// geometry, a place of theirs having none in longitude/latitude: an update of one is refused, + /// as the map holds only its window, where such a feature's stored geometry may not be. + left_out_whole: std::collections::HashSet, /// The system the tool works in ([`work_system`]): the one its inputs are given in and its /// outputs are made in. work: Crs, @@ -1339,6 +1343,15 @@ impl MapInputs<'_> { /// the project is; one with a place it can't hold stays in longitude/latitude, said. Tables /// have no coordinates to hold. fn hold_results(&self, result: &mut rustgis_analysis::ToolResult) -> Result<(), String> { + // An update writes back into the window the map holds of a streamed layer, which may not + // have the stored geometry of a feature read without it: refused, rather than lost. + if let Output::Update { layer, .. } = &result.output + && self.left_out_whole.contains(&layer.to_ascii_lowercase()) + { + return Err(format!( + "{layer} is read in place and has features with a place that can't be given in longitude/latitude, which an update would lose: Load All Features (layer.loadAll) before a tool updates it" + )); + } // A geocentric system holds no map coordinates: outputs stay in longitude/latitude then. let project = self.snap.project.filter(|c| *c != Crs::LonLat && !c.is_geocentric()); if self.work == Crs::LonLat && project.is_none() { @@ -1448,7 +1461,8 @@ fn inputs_of<'a>(snap: Snapshot<'a>, spec: Option<&rustgis_analysis::ToolSpec>, } } } - let work = work_inputs(&snap.map, &snap.tables, spec, params, &mut full, &mut messages)?; + let mut left_out_whole = std::collections::HashSet::new(); + let work = work_inputs(&snap.map, &snap.tables, spec, params, &mut full, &mut messages, &mut left_out_whole)?; let mut rows = env_inputs(&snap.map, &full, &snap.env, params)?; narrow_to_queries(&snap.map, spec, params, &full, &mut rows, &mut messages)?; let unread = if work == Crs::LonLat { std::collections::HashSet::new() } else { attributes_only(spec, params) }; @@ -1457,6 +1471,7 @@ fn inputs_of<'a>(snap: Snapshot<'a>, spec: Option<&rustgis_analysis::ToolSpec>, rows, loaded: full, work, + left_out_whole, unread, messages, losses, @@ -1645,7 +1660,8 @@ fn attributes_only(spec: Option<&rustgis_analysis::ToolSpec>, params: &Value) -> /// its first input's own for a tool that works in it, every other input converted into it; else /// longitude/latitude. An input with a place that system can't hold has the run work in /// longitude/latitude instead, and a message says so (the conversions made for the first attempt -/// are dropped then, and the inputs read again in longitude/latitude). Returns the system. +/// are dropped then, and the inputs read again in longitude/latitude, a feature with a place +/// that has none there either read without its geometry, [`inputs_in`]). Returns the system. fn work_inputs( map: &rustgis_map::Map, tables: &[crate::project::Table], @@ -1653,10 +1669,11 @@ fn work_inputs( params: &Value, full: &mut std::collections::HashMap, messages: &mut Vec, + left_out_whole: &mut std::collections::HashSet, ) -> Result { let work = work_system(map, spec, params, full); if work != Crs::LonLat { - match inputs_in(map, tables, spec, params, full, work) { + match inputs_in(map, tables, spec, params, full, work, left_out_whole) { Ok((converted, said)) => { full.extend(converted); messages.extend(said); @@ -1670,14 +1687,17 @@ fn work_inputs( } } } - let (converted, _) = inputs_in(map, tables, spec, params, full, Crs::LonLat)?; + let (converted, said) = inputs_in(map, tables, spec, params, full, Crs::LonLat, left_out_whole)?; full.extend(converted); + messages.extend(said); Ok(Crs::LonLat) } /// Copies of the layers a tool reads converted into `work`, by lowercase name: those read whole /// (streamed layers, files) and each other layer or standalone table with geometry it names whose -/// coordinates are in another system. Nothing is copied for a layer already in `work`. +/// coordinates are in another system. Nothing is copied for a layer already in `work`. In +/// longitude/latitude, a feature with a place that can't be given there is read without its +/// geometry, and one notice says how many of each layer were. fn inputs_in( map: &rustgis_map::Map, tables: &[crate::project::Table], @@ -1685,6 +1705,7 @@ fn inputs_in( params: &Value, full: &std::collections::HashMap, work: Crs, + left_out_whole: &mut std::collections::HashSet, ) -> Result<(std::collections::HashMap, Vec), String> { let mut converted = std::collections::HashMap::new(); // The converted inputs with edges that bend ([`bent_edges`]): name, how many, how far. @@ -1699,6 +1720,27 @@ fn inputs_in( } Ok(()) }; + // The inputs with features read without their geometry, a place of theirs having none in + // longitude/latitude: name, how many. In `work`, another system, such a place sends the run + // to longitude/latitude instead ([`work_inputs`]), where the feature is read without it, + // rather than the run refused. + let mut unplaced: Vec<(String, usize)> = Vec::new(); + let mut convert = |ds: &'_ Dataset| -> Result, String> { + if work != Crs::LonLat { + return Ok(match ds.in_crs(work)? { + std::borrow::Cow::Owned(c) => Some(c), + std::borrow::Cow::Borrowed(_) => None, + }); + } + let (c, n) = ds.in_lonlat_leaving_out()?; + if n > 0 { + unplaced.push((ds.name.clone(), n)); + } + Ok(match c { + std::borrow::Cow::Owned(c) => Some(c), + std::borrow::Cow::Borrowed(_) => None, + }) + }; // Read only for its attributes in a run in its first input's system: as it is. (The first // input, if it is named there too, is in that system already.) let unread = if work == Crs::LonLat { std::collections::HashSet::new() } else { attributes_only(spec, params) }; @@ -1706,7 +1748,7 @@ fn inputs_in( if unread.contains(&key.to_ascii_lowercase()) { continue; } - if let std::borrow::Cow::Owned(c) = ds.in_crs(work)? { + if let Some(c) = convert(ds)? { say(ds, &c)?; converted.insert(key.clone(), c); } @@ -1737,7 +1779,7 @@ fn inputs_in( .filter(|i| !matches!(i, ProjectInput::Layer(l) if l.is_raster())) .map(|i| i.dataset()) .filter(|d| d.geometry_type != rustgis_data::GeometryType::None) - && let std::borrow::Cow::Owned(c) = ds.in_crs(work)? + && let Some(c) = convert(ds)? { say(ds, &c)?; converted.insert(key, c); @@ -1766,13 +1808,27 @@ fn inputs_in( if t.dataset.geometry_type == rustgis_data::GeometryType::None { continue; } - if let std::borrow::Cow::Owned(c) = t.dataset.in_crs(work)? { + if let Some(c) = convert(&t.dataset)? { say(&t.dataset, &c)?; converted.insert(table_key(t.id), c); } } // One notice for them all, naming each layer. let mut said = Vec::new(); + // The layers read whole (streamed ones, files) with features read without their geometry. + for (key, ds) in full { + if unplaced.iter().any(|(name, _)| *name == ds.name) { + left_out_whole.insert(key.to_ascii_lowercase()); + } + } + if !unplaced.is_empty() { + let name = spec.map_or("The tool", |t| t.name); + let n: usize = unplaced.iter().map(|(_, n)| n).sum(); + let layers = unplaced.iter().map(|(layer, n)| format!("'{layer}' ({n})")).collect::>().join(", "); + said.push(format!( + "{name}: {n} feature(s) of {layers} have a place that can't be given in longitude/latitude, so the tool reads them without their geometry" + )); + } if !bent.is_empty() { let name = spec.map_or("The tool", |t| t.name); let n: usize = bent.iter().map(|(_, n, _)| n).sum(); @@ -3602,8 +3658,13 @@ fn apply_with( let l = s.map_mut().layers.iter_mut().find(|l| l.name.eq_ignore_ascii_case(&layer)).ok_or("the input layer disappeared")?; // Made in the system the tool worked in ([`MapInputs::hold_results`]): taken as made // when that is the layer's own, else written back in its own coordinates from - // longitude/latitude. - l.dataset = if dataset.coord_crs() == l.dataset.coord_crs() { + // longitude/latitude. (A streamed layer whose whole read left a feature out is refused + // before this: [`MapInputs::hold_results`].) + // A streamed layer's window may be in another system than its source (longitude/latitude + // unless the map is in the source's own), while the tool read the whole source: a + // result in the source's own system is taken as made too, the layer then holding it. + let own = l.source.as_ref().map(|src| src.coord_crs()); + l.dataset = if dataset.coord_crs() == l.dataset.coord_crs() || Some(dataset.coord_crs()) == own { dataset } else { let lonlat = if dataset.coord_crs() == Crs::LonLat { dataset } else { dataset.in_lonlat()?.into_owned() }; diff --git a/crates/engine/src/cmd/labels.rs b/crates/engine/src/cmd/labels.rs index 80dfbcccd0..e7341cddeb 100644 --- a/crates/engine/src/cmd/labels.rs +++ b/crates/engine/src/cmd/labels.rs @@ -966,6 +966,8 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult { // said. let astray = std::cell::Cell::new(0usize); let unplaced = std::cell::Cell::new(0usize); + // Features left without annotation, a place of theirs having none in longitude/latitude. + let mut unplaced_features = 0usize; // `None` for one left at its feature's label point, which isn't moved there any more. let put_at = |[x, y]: [f64; 2]| -> Option { let c = Coord::new(x, y); @@ -993,34 +995,40 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult { }, } }; + // A class's label text for a row, and whether it was cut: `None` when it gives none (no + // expression or field, an expression with no value, a null field), so no label is made. + let text_of = |i: usize, row: usize| -> Option<(String, bool)> { + match by_text(i).and_then(|e| e.text_cut(&l.dataset, row)) { + Some(Some((t, was_cut))) => Some((t, was_cut)), + Some(None) => None, + None => { + let fi = fields.get(i).copied().flatten()?; + let v = l.dataset.value(row, fi); + (!v.is_null()).then(|| (v.to_string(), false)) + } + } + }; for (row, ft) in l.dataset.features.rows().enumerate() { if rows.get(row) != Some(&true) { continue; } // In the system the annotation layer is made in (above). let Some(g) = ft.geometry() else { continue }; + // One with a place that can't be given in longitude/latitude, which the map doesn't + // draw either, becomes no annotation, and is said. let g = if own { std::borrow::Cow::Borrowed(g) + } else if let Some(g) = rustgis_data::Dataset::converted_to_lonlat(&to, g) { + g } else { - rustgis_data::Dataset::geometry_to_lonlat_by(&to, g).map_err(|e| format!("{}: feature {}: {e}", l.name, ft.id()))? + // Counted only when it has a label to convert: a visible class giving it text. + unplaced_features += usize::from(matcher.classes_of(&l.dataset, row).any(|(i, c)| c.visible && text_of(i, row).is_some())); + continue; }; let Some(at) = g.label_point() else { continue }; for (i, class) in matcher.classes_of(&l.dataset, row).filter(|(_, c)| c.visible) { - let text = match by_text(i).and_then(|e| e.text_cut(&l.dataset, row)) { - Some(Some((t, was_cut))) => { - cut += usize::from(was_cut); - t - } - Some(None) => continue, - None => { - let Some(fi) = fields.get(i).copied().flatten() else { continue }; - let v = l.dataset.value(row, fi); - if v.is_null() { - continue; - } - v.to_string() - } - }; + let Some((text, was_cut)) = text_of(i, row) else { continue }; + cut += usize::from(was_cut); let mut attrs = vec![Attr::Text(text)]; if classes { attrs.push(Attr::Text(class.name.clone())); @@ -1057,9 +1065,20 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult { } } if ds.features.is_empty() { + if unplaced_features > 0 { + return Err(format!( + "the layer has no labels to convert: {unplaced_features} feature(s) have a place that can't be given in longitude/latitude" + )); + } return Err("the layer has no labels to convert".into()); } let n = ds.features.len(); + let unplaced_features_note = (unplaced_features > 0).then(|| { + NoticeText::format( + "{name}: {n} feature(s) of {layer} have a place that can't be given in longitude/latitude, so their labels aren't converted", + [("name", ds.name.clone().into()), ("n", unplaced_features.to_string().into()), ("layer", l.name.clone().into())], + ) + }); let flattened_note = (flattened > 0).then(|| { NoticeText::format( "{name}: {n} label(s) along lines made upright points at their lines' middle vertex, no longer laid along the line", @@ -1143,7 +1162,7 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult { if let Some(note) = cut_note { s.notify(note, false); } - for note in [flattened_note, repeated_note, astray_note, unplaced_note].into_iter().flatten() { + for note in [flattened_note, repeated_note, astray_note, unplaced_note, unplaced_features_note].into_iter().flatten() { s.notify_text(note, false); } if let Some((_, unread)) = &whole { diff --git a/crates/engine/src/cmd/stac_area.rs b/crates/engine/src/cmd/stac_area.rs index cac0cbfb07..d43999e14a 100644 --- a/crates/engine/src/cmd/stac_area.rs +++ b/crates/engine/src/cmd/stac_area.rs @@ -49,13 +49,17 @@ fn read_geometries(path: &str) -> Result<(Vec, rustgis_data::loss::Not return Err(format!("{path} has more than {} features: simplify it or use a bounding box", area::MAX_FEATURES)); } let mut messages = report.messages.prefixed(path); - // The search area is in longitude/latitude; a file in another system is read in its own. - let ds = ds.in_lonlat().map_err(|e| format!("{path}: {e}"))?; + // The search area is in longitude/latitude; a file in another system is read in its own, a + // feature with a place that can't be given in longitude/latitude left out, and said. + let had: usize = ds.features.rows().filter(|r| r.geometry().is_some()).count(); + let (ds, unplaced) = ds.in_lonlat_leaving_out().map_err(|e| format!("{path}: {e}"))?; let geometries: Vec = ds.features.iter().filter_map(|f| f.geometry.clone()).collect(); - if geometries.len() < ds.features.len() { + if had < ds.features.len() { + messages.push(format!("{path}: {} feature(s) have no geometry and are left out of the search area", ds.features.len() - had)); + } + if unplaced > 0 { messages.push(format!( - "{path}: {} feature(s) have no geometry and are left out of the search area", - ds.features.len() - geometries.len() + "{path}: {unplaced} feature(s) have a place that can't be given in longitude/latitude and are left out of the search area" )); } Ok((geometries, messages)) @@ -164,20 +168,29 @@ fn selected(s: &Session, p: &Value) -> Result<(Vec, Vec), Stri return Err(format!("more than {} features are selected: select fewer or use a bounding box", area::MAX_FEATURES)); } // In longitude/latitude, as a search area is, whatever system the layer holds them in. - let mut geometries: Vec = Vec::new(); + // One with a place that can't be given there is left out, and said. + let (mut geometries, mut unplaced): (Vec, usize) = (Vec::new(), 0); let to = layer.dataset.lonlat_conversion().map_err(|e| format!("{}: {e}", layer.name))?; for f in layer.selection.iter().filter_map(|row| layer.dataset.features.row(*row)) { if let Some(g) = f.geometry() { - let g = rustgis_data::Dataset::geometry_to_lonlat_by(&to, g).map_err(|e| format!("{}: feature {}: {e}", layer.name, f.id()))?; - geometries.push(g.into_owned()); + match rustgis_data::Dataset::converted_to_lonlat(&to, g) { + Some(g) => geometries.push(g.into_owned()), + None => unplaced += 1, + } } } let mut notes = Vec::new(); - if geometries.len() < layer.selection.len() { + if geometries.len() + unplaced < layer.selection.len() { notes.push(format!( "{}: {} selected feature(s) have no geometry and are left out of the search area", layer.name, - layer.selection.len() - geometries.len() + layer.selection.len() - geometries.len() - unplaced + )); + } + if unplaced > 0 { + notes.push(format!( + "{}: {unplaced} selected feature(s) have a place that can't be given in longitude/latitude and are left out of the search area", + layer.name )); } Ok((geometries, notes)) diff --git a/crates/engine/src/cmd/workflows.rs b/crates/engine/src/cmd/workflows.rs index d1dc10b7c2..326d4f9fba 100644 --- a/crates/engine/src/cmd/workflows.rs +++ b/crates/engine/src/cmd/workflows.rs @@ -1822,12 +1822,14 @@ fn route(s: &mut Session, p: &Value) -> CmdResult { rustgis_map::rows::Rows::Subset(rows) => rows, }; // The network in longitude/latitude, as `from` and `to` are, whatever system the layer holds - // its coordinates in: converted only when its graph is built, which is kept for the layer's - // rows, so routes over a held network reuse it as they do over one in longitude/latitude. + // its coordinates in: each line given there as its graph is built, which is kept for the + // layer's rows, so routes over a held network reuse it as they do over one in + // longitude/latitude. A line with a place that can't be given there is left out of it, its + // segments counted with those with invalid coordinates, rather than the route refused. let system = (l.dataset.coord_crs(), l.dataset.crs); let r = network::shortest_route_held( &l.dataset, - || l.dataset.in_lonlat(), + || Ok(std::borrow::Cow::Borrowed(&l.dataset)), &rows, point(p, "from")?, point(p, "to")?, @@ -1968,7 +1970,17 @@ fn simulate(s: &mut Session, p: &Value) -> CmdResult { // system, as the polygons are. let system = (l.dataset.coord_crs(), l.dataset.crs); let own = rustgis_analysis::works_in(system.0); - let polygons = if own { std::borrow::Cow::Borrowed(&l.dataset) } else { l.dataset.in_lonlat()? }; + // A polygon with a place that can't be given in longitude/latitude gets no points, and is + // said, rather than the run refused. + let polygons = if own { std::borrow::Cow::Borrowed(&l.dataset) } else { l.dataset.in_lonlat_leaving_out()?.0 }; + let unplaced = rows + .iter() + .filter(|&&r| { + l.dataset.features.row(r).is_some_and(|f| f.geometry().is_some()) + && polygons.features.row(r).is_some_and(|f| f.geometry().is_none()) + }) + .count(); + let source = l.name.clone(); let seed = f(p, "seed").map_or(42, |v| v.max(0.0) as u64); let pts: Vec<(usize, Coord)> = match ps(p, "field") { Some(fname) => { @@ -2008,6 +2020,12 @@ fn simulate(s: &mut Session, p: &Value) -> CmdResult { if let Some(notice) = query_notice { s.notify_text(notice, false); } + if unplaced > 0 { + s.warn(format!( + "{}: {unplaced} polygon(s) of {source} have a place that can't be given in longitude/latitude, so no points are simulated in them", + ds.name + )); + } let nid = super::layer::add_dataset(s, ds); Ok(json!({"layer": nid, "points": n})) } diff --git a/crates/engine/src/cmd/workspace.rs b/crates/engine/src/cmd/workspace.rs index 14cb15e4c4..a1ea49fe9e 100644 --- a/crates/engine/src/cmd/workspace.rs +++ b/crates/engine/src/cmd/workspace.rs @@ -219,19 +219,24 @@ pub fn commands() -> Vec { r#"{"layer": elevation raster, "samples"?: number (default 200), "points": [[lon, lat], [lon, lat]] (the line crossed), "at"?: 0..1 along it, "width"?: metres}"#, ), C::new("profile.alongLine", "Profile Along a Line", "View › Profile Viewing", |s, p| { - let lines = selected_lines(s, p, false)?; + let (lines, _) = selected_lines(s, p, false)?; let first = lines.into_iter().next().ok_or("no line")?; profile(s, p, &first) }).inputs(profile_inputs).roles(&[]).effects(crate::policy::Effects::NONE) .view() .params(r#"{"layer": elevation raster, "samples"?: number (default 200), "lines": line layer, "row"?: number (the first selected when omitted)}"#), C::new("profile.alongSelected", "Profile Along Selected Lines", "View › Profile Viewing", |s, p| { - let lines = selected_lines(s, p, true)?; + let (lines, unplaced) = selected_lines(s, p, true)?; // The lines past the first 50 get no profile, and that is said (#1896). if lines.len() > MAX_PROFILED_LINES { s.notify(format!("Profile Along Selected Lines: the first {MAX_PROFILED_LINES} of the {} lines are profiled", lines.len()), false); } let out: Vec = lines.iter().take(MAX_PROFILED_LINES).map(|l| profile(s, p, l)).collect::>()?; + if unplaced > 0 { + s.warn(format!( + "Profile Along Selected Lines: {unplaced} line(s) have a place that can't be given in longitude/latitude, so they get no profile" + )); + } Ok(Value::Array(out)) }).inputs(profile_inputs).roles(&[]).effects(crate::policy::Effects::NONE) .view() @@ -554,7 +559,9 @@ fn profile(s: &Session, p: &Value, path: &[Coord]) -> CmdResult { Ok(json!({"length": prof.last().map_or(0.0, |x| x.0), "min": lo, "max": hi, "gain": gain, "loss": loss, "samples": rows})) } -fn selected_lines(s: &Session, p: &Value, all: bool) -> Result>, String> { +/// The chosen lines of the line layer `lines` names, in longitude/latitude, and how many of them +/// were left out as a place of theirs can't be given there. Refused when none is left. +fn selected_lines(s: &Session, p: &Value, all: bool) -> Result<(Vec>, usize), String> { let n = profile_lines(p)?; let l = s.map().layer_by_name(n).filter(|l| l.geometry_type() == GeometryType::Polyline).ok_or_else(|| format!("no line layer '{n}'"))?; @@ -566,19 +573,26 @@ fn selected_lines(s: &Session, p: &Value, all: bool) -> Result>, }; // Sampled in longitude/latitude, whatever system the layer holds its coordinates in. let mut out: Vec> = Vec::new(); + let mut unplaced = 0usize; let to = l.dataset.lonlat_conversion().map_err(|e| format!("{n}: {e}"))?; for f in rows.iter().filter_map(|r| l.dataset.features.row(*r)) { let Some(g) = f.geometry().filter(|g| matches!(g, Geometry::Line(_))) else { continue }; - if let Geometry::Line(parts) = - &*rustgis_data::Dataset::geometry_to_lonlat_by(&to, g).map_err(|e| format!("{n}: feature {}: {e}", f.id()))? - { + let Some(g) = rustgis_data::Dataset::converted_to_lonlat(&to, g) else { + unplaced += 1; + continue; + }; + if let Geometry::Line(parts) = &*g { let v: Vec = parts.iter().flatten().copied().collect(); if v.len() >= 2 { out.push(v); } } } - if out.is_empty() { Err("no usable lines".into()) } else { Ok(out) } + match (out.is_empty(), unplaced) { + (true, 0) => Err("no usable lines".into()), + (true, u) => Err(format!("no usable lines: {u} have a place that can't be given in longitude/latitude")), + (false, _) => Ok((out, unplaced)), + } } /// Every keyframe-to-keyframe move rendered as PNG frames in a zip. diff --git a/crates/engine/src/geometry_calc.rs b/crates/engine/src/geometry_calc.rs index 3a5aa92524..1a498bfa3d 100644 --- a/crates/engine/src/geometry_calc.rs +++ b/crates/engine/src/geometry_calc.rs @@ -33,7 +33,8 @@ pub fn units(property: &str) -> &'static [(&'static str, &'static str)] { } /// Runs `edit.calculateGeometry`: fills `field` (new or existing numeric) of the chosen features -/// with `property` in `unit`, as one undo step; on any error nothing changes. +/// with `property` in `unit`, as one undo step; on any error nothing changes. A feature with a +/// place that can't be given in longitude/latitude gets an empty value, and a notice counts them. pub fn run(s: &mut Session, p: &Json) -> CmdResult { let id = s.layer_id(p)?; let l = s.map().layer(id).ok_or("no layer")?; @@ -83,8 +84,13 @@ pub fn run(s: &mut Session, p: &Json) -> CmdResult { if rows.is_empty() { return Err("no features to calculate".into()); } + // Read in longitude/latitude, where a ring through both poles is ambiguous; one with a place + // that can't be given there is left empty below, and said, not refused. if property == "area" - && let Some(message) = l.dataset.ambiguous_area_message(rows.iter().filter_map(|&r| l.dataset.features.get(r)?.geometry.as_ref())) + && let Ok(to) = l.dataset.lonlat_conversion() + && let Some(message) = rustgis_data::ambiguous_area_message( + rows.iter().filter_map(|&r| rustgis_data::Dataset::converted_to_lonlat(&to, l.dataset.features.get(r)?.geometry.as_ref()?)), + ) { return Err(format!("{}: {message}", l.dataset.name)); } @@ -95,6 +101,8 @@ pub fn run(s: &mut Session, p: &Json) -> CmdResult { }; let mut values = Vec::with_capacity(rows.len()); let mut nulls = 0; + // Those left empty as a place of theirs can't be given in longitude/latitude. + let mut unplaced = 0usize; // Made at the first feature with a geometry, once for the layer. let mut conversion = None; for row in &rows { @@ -109,7 +117,12 @@ pub fn run(s: &mut Session, p: &Json) -> CmdResult { Some(to) => &*to, slot @ None => slot.insert(l.dataset.lonlat_conversion().map_err(|e| format!("feature {}: {e}", f.id))?), }; - let g = rustgis_data::Dataset::geometry_to_lonlat_by(to, g).map_err(|e| format!("feature {}: {e}", f.id))?; + let Some(g) = rustgis_data::Dataset::converted_to_lonlat(to, g) else { + unplaced += 1; + nulls += 1; + values.push((*row, Value::Null)); + continue; + }; let g = g.as_ref(); // Lengths and areas use longitude differences, so a shape drawn or buffered across the // antimeridian may run past ±180°; a coordinate has to be a real longitude. @@ -169,5 +182,11 @@ pub fn run(s: &mut Session, p: &Json) -> CmdResult { changes.push(crate::cmd::design::Change { before: Some(before), row: Some(row) }); } crate::cmd::design::apply(s, id, changes)?; - Ok(json!({"rows": rows.len(), "nulls": nulls, "field": field})) + if unplaced > 0 { + let name = s.map().layer(id).map(|l| l.name.clone()).unwrap_or_default(); + s.warn(format!( + "{name}: {unplaced} feature(s) have a place that can't be given in longitude/latitude, so their {property} is left empty in {field}" + )); + } + Ok(json!({"rows": rows.len(), "nulls": nulls, "unplaced": unplaced, "field": field})) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index ffd3895998..d73906374b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17,6 +17,8 @@ mod services_own; #[cfg(not(target_arch = "wasm32"))] #[path = "tests/sources_own.rs"] mod sources_own; +#[path = "tests/unplaced_gp.rs"] +mod unplaced_gp; #[path = "tests/unplaced_out.rs"] mod unplaced_out; diff --git a/crates/engine/src/tests/unplaced_gp.rs b/crates/engine/src/tests/unplaced_gp.rs new file mode 100644 index 0000000000..5b75569b45 --- /dev/null +++ b/crates/engine/src/tests/unplaced_gp.rs @@ -0,0 +1,259 @@ +//! Geoprocessing over a layer held in its own system with a place that can't be given in +//! longitude/latitude (#2032 C2f-4b): tools, the geometry calculator, annotation, routes, +//! simulation, profiles and a search area read such a feature without its geometry (or leave it +//! out) and say so once, rather than failing; a layer whose places all convert says nothing of it. +//! The layers are held in Robinson, a world projection, so every run converts them to +//! longitude/latitude. + +use crate::Session; +use rustgis_data::{Dataset, Field, FieldType, Geometry, GeometryType, Value, raster::Crs}; +use rustgis_geom::Coord; +use serde_json::json; + +fn robinson() -> Crs { + Crs::parse("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs").unwrap() +} + +/// A place in Robinson with none in longitude/latitude: far past the projection's edge. +const FAR: Coord = Coord { x: 1e12, y: 1e12 }; + +/// A dataset held in Robinson, made from `lonlat` geometries in longitude/latitude, then with +/// `far`, one more feature (named "far") reaching past the projection's edge. +fn held(name: &str, kind: GeometryType, lonlat: Vec, far: Option) -> Dataset { + let mut ds = Dataset::new(name, kind, vec![Field::new("name", FieldType::Text)]); + for (i, g) in lonlat.into_iter().enumerate() { + ds.push(Some(g), vec![Value::Text(format!("{name} {i}"))]); + } + ds.hold_in(robinson()).unwrap(); + if let Some(g) = far { + ds.push(Some(g), vec![Value::Text("far".into())]); + } + ds +} + +/// A session with the DEM, the line layer "lines" (one line over the hill) and the polygon layer +/// "areas" (one square on it), both held in Robinson; with `far`, each has one more feature with a +/// place that can't be given in longitude/latitude. +fn session(far: bool) -> Session { + let mut s = Session::new(crate::Project::default()); + s.run("layer.addDataBytes", &json!({"fileName": "dem.tif", "data": super::dem_b64()})).unwrap(); + let line = Geometry::Line(vec![vec![Coord::new(10.002, 45.002), Coord::new(10.038, 45.038)]]); + let far_line = Geometry::Line(vec![vec![Coord::new(1_000_000.0, 5_000_000.0), FAR]]); + let square = Geometry::Polygon(vec![vec![vec![ + Coord::new(10.0, 45.0), + Coord::new(10.03, 45.0), + Coord::new(10.03, 45.03), + Coord::new(10.0, 45.03), + Coord::new(10.0, 45.0), + ]]]); + let far_square = Geometry::Polygon(vec![vec![vec![ + Coord::new(1_000_000.0, 5_000_000.0), + Coord::new(1_000_100.0, 5_000_000.0), + FAR, + Coord::new(1_000_000.0, 5_000_000.0), + ]]]); + let lines = held("lines", GeometryType::Polyline, vec![line], far.then_some(far_line)); + let areas = held("areas", GeometryType::Polygon, vec![square], far.then_some(far_square)); + // The far places truly have none in longitude/latitude. + let to = lines.lonlat_conversion().unwrap(); + assert_eq!(to.point(FAR), None); + crate::cmd::layer::add_dataset(&mut s, lines); + crate::cmd::layer::add_dataset(&mut s, areas); + s +} + +/// What `cmd` with `p` answers, and its notices that speak of a place that can't be given in +/// longitude/latitude. +fn run(s: &mut Session, cmd: &str, p: serde_json::Value) -> (serde_json::Value, Vec) { + let mark = s.notice_mark(); + let out = s.run(cmd, &p).unwrap_or_else(|e| panic!("{cmd}: {e}")); + let said = s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("can't be given in")).collect(); + (out, said) +} + +/// The messages of a tool's run (`gp.run`) that speak of such a place. +fn tool_said(out: &serde_json::Value, notes: Vec) -> Vec { + let messages = out["messages"].as_array().into_iter().flatten().filter_map(|m| m.as_str().map(String::from)); + notes + .into_iter() + .chain(messages.filter(|t| t.contains("can't be given in"))) + .collect::>() + .into_iter() + .collect() +} + +fn geometry_of(s: &Session, layer: &str, row: usize) -> Option { + s.map().layer_by_name(layer).unwrap().dataset.features.row(row).and_then(|r| r.geometry().cloned()) +} + +#[test] +fn a_tool_reads_a_feature_it_cant_place_without_its_geometry_and_says_so() { + for far in [false, true] { + let mut s = session(far); + // A tool that makes a layer: the far line gives no points. + let (out, notes) = run(&mut s, "gp.run", json!({"tool": "featureVerticesToPoints", "params": {"input": "lines"}})); + let said = tool_said(&out, notes); + if far { + assert_eq!(said.len(), 1, "{said:?}"); + assert!(said[0].contains("1 feature(s) of 'lines' (1)") && said[0].contains("without their geometry"), "{}", said[0]); + } else { + assert!(said.is_empty(), "{said:?}"); + } + let points = s.map().layers.iter().find(|l| l.name.contains("lines") && l.name != "lines").expect("the tool's output"); + assert_eq!(points.dataset.features.rows().filter(|r| r.geometry().is_some()).count(), 2, "the line's two vertices"); + // A tool that updates the layer in place: the far line keeps its stored geometry, bit for + // bit, rather than losing it, and gets no length worked out from a geometry it wasn't + // given (left empty, not 0). + let before = geometry_of(&s, "lines", 1); + let (out, notes) = run(&mut s, "gp.run", json!({"tool": "calculateGeometry", "params": {"input": "lines"}})); + let said = tool_said(&out, notes); + assert_eq!(said.len(), usize::from(far), "{said:?}"); + assert_eq!(geometry_of(&s, "lines", 1), before); + assert!(geometry_of(&s, "lines", 0).is_some()); + let ds = &s.map().layer_by_name("lines").unwrap().dataset; + let fi = ds.field_index("length_km").unwrap(); + assert!((4.0..6.0).contains(&ds.value(0, fi).as_f64().unwrap()), "{:?}", ds.value(0, fi)); + if far { + assert!(ds.value(1, fi).is_null(), "{:?}", ds.value(1, fi)); + assert_eq!(ds.value(1, ds.field_index("name").unwrap()), &Value::Text("far".into())); + } + assert_eq!(s.map().layer_by_name("lines").unwrap().dataset.coord_crs(), robinson()); + } +} + +#[test] +fn the_geometry_calculator_leaves_a_feature_it_cant_place_empty_and_says_so() { + for far in [false, true] { + let mut s = session(far); + let (out, said) = run( + &mut s, + "edit.calculateGeometry", + json!({"layer": "lines", "property": "length", "unit": "m", "field": "len", "create": true, "scope": "all"}), + ); + assert_eq!(out["unplaced"], json!(usize::from(far))); + assert_eq!(said.len(), usize::from(far), "{said:?}"); + let ds = &s.map().layer_by_name("lines").unwrap().dataset; + let fi = ds.field_index("len").unwrap(); + let length = ds.value(0, fi).as_f64().unwrap(); + assert!((4000.0..6000.0).contains(&length), "{length}"); + if far { + assert!(ds.value(1, fi).is_null()); + assert!(said[0].contains("1 feature(s)") && said[0].contains("length is left empty in len"), "{}", said[0]); + } + // Areas too: no ring through both poles to refuse, the far one left empty. + let (out, said) = run( + &mut s, + "edit.calculateGeometry", + json!({"layer": "areas", "property": "area", "unit": "m2", "field": "a", "create": true, "scope": "all"}), + ); + assert_eq!((out["unplaced"].clone(), said.len()), (json!(usize::from(far)), usize::from(far))); + } +} + +#[test] +fn annotation_leaves_out_a_feature_it_cant_place_and_says_so() { + for far in [false, true] { + let mut s = session(far); + let l = s.map_mut().layers.iter_mut().find(|l| l.name == "lines").unwrap(); + l.labels.enabled = true; + l.labels.default.field = "name".into(); + let (out, said) = run(&mut s, "labels.convert", json!({"layer": "lines"})); + assert_eq!(out["annotations"], json!(1)); + assert_eq!(said.len(), usize::from(far), "{said:?}"); + if far { + assert!(said[0].contains("1 feature(s) of lines") && said[0].contains("labels aren't converted"), "{}", said[0]); + } + } + // A far feature with no label text (its field null) would make no label anyway: not counted. + let mut s = session(true); + let l = s.map_mut().layers.iter_mut().find(|l| l.name == "lines").unwrap(); + let fi = l.dataset.field_index("name").unwrap(); + l.dataset.features.set_value(1, fi, Value::Null); + l.labels.enabled = true; + l.labels.default.field = "name".into(); + let (out, said) = run(&mut s, "labels.convert", json!({"layer": "lines"})); + assert_eq!(out["annotations"], json!(1)); + assert!(said.is_empty(), "{said:?}"); +} + +#[test] +fn a_route_and_a_simulation_leave_out_what_they_cant_place() { + for far in [false, true] { + let mut s = session(far); + // The route runs over the line it can place, rather than being refused. + let mark = s.notice_mark(); + let r = s.run("analysis.route", &json!({"layer": "lines", "from": [10.002, 45.002], "to": [10.038, 45.038]})).unwrap(); + assert!(r["lengthKm"].as_f64().unwrap() > 4.0, "{r}"); + let omitted: Vec<_> = + s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("segments with invalid coordinates")).collect(); + assert_eq!(omitted.len(), usize::from(far), "{omitted:?}"); + // Points in the square only. + let (out, said) = run(&mut s, "analysis.simulate", json!({"layer": "areas", "count": 5})); + assert_eq!(out["points"], json!(5)); + assert_eq!(said.len(), usize::from(far), "{said:?}"); + if far { + assert!(said[0].contains("1 polygon(s) of areas"), "{}", said[0]); + } + } +} + +#[test] +fn profiles_and_a_search_area_leave_out_what_they_cant_place() { + for far in [false, true] { + let mut s = session(far); + let dem = s.map().layers.iter().find(|l| l.is_raster()).unwrap().name.clone(); + s.run("select.rows", &json!({"layer": "lines", "rows": if far { json!([0, 1]) } else { json!([0]) }})).unwrap(); + let (out, said) = run(&mut s, "profile.alongSelected", json!({"layer": dem, "lines": "lines"})); + assert_eq!(out.as_array().unwrap().len(), 1); + assert_eq!(said.len(), usize::from(far), "{said:?}"); + let (geometries, notes) = crate::cmd::stac_area::selected_geometries(&s, &json!({"layer": "lines"})).unwrap(); + assert_eq!(geometries.len(), 1); + let unplaced: Vec<_> = notes.iter().filter(|n| n.contains("can't be given in")).collect(); + assert_eq!(unplaced.len(), usize::from(far), "{notes:?}"); + assert!(notes.iter().all(|n| !n.contains("have no geometry")), "{notes:?}"); + if far { + // The far line alone: no line to profile, and why. + s.run("select.rows", &json!({"layer": "lines", "rows": [1]})).unwrap(); + let e = s.run("profile.alongSelected", &json!({"layer": dem, "lines": "lines"})).unwrap_err(); + assert!(e.contains("can't be given in longitude/latitude"), "{e}"); + } + } +} + +/// A search area read from a file in its own system leaves out a feature it can't place and says +/// so; a file whose places all convert says nothing of it. +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_search_area_file_leaves_out_what_it_cant_place() { + let dir = std::env::temp_dir().join(format!("rustgis-unplaced-area-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let square = Geometry::Polygon(vec![vec![vec![ + Coord::new(10.0, 45.0), + Coord::new(10.03, 45.0), + Coord::new(10.03, 45.03), + Coord::new(10.0, 45.03), + Coord::new(10.0, 45.0), + ]]]); + let far_square = Geometry::Polygon(vec![vec![vec![ + Coord::new(1_000_000.0, 5_000_000.0), + Coord::new(1_000_100.0, 5_000_000.0), + FAR, + Coord::new(1_000_000.0, 5_000_000.0), + ]]]); + for far in [false, true] { + // Robinson's numbers written as they are, then labelled Robinson by the .prj, as a file + // made elsewhere would be: a writer converting to longitude/latitude refuses the far one. + let mut ds = held("area", GeometryType::Polygon, vec![square.clone()], far.then(|| far_square.clone())); + ds.held_in = Crs::LonLat; + ds.crs = None; + let path = dir.join(format!("area-{far}.shp")); + rustgis_data::io::write_path(&ds, &path).unwrap(); + std::fs::write(path.with_extension("prj"), rustgis_data::raster::wkt::to_wkt(robinson()).unwrap()).unwrap(); + let loaded = crate::cmd::stac_area::load_file(path.to_str().unwrap()).unwrap(); + // Said by the reader while files are read into longitude/latitude (C2f-4b-2 keeps such a + // feature, and then the search area says it); a clean file says nothing of it. + let said = loaded.notices.iter().any(|n| n.contains("longitude/latitude")); + assert_eq!(said, far, "{:?}", loaded.notices); + } + std::fs::remove_dir_all(&dir).ok(); +} diff --git a/crates/engine/src/tests/unplaced_out.rs b/crates/engine/src/tests/unplaced_out.rs index 18c14dc371..6d104eff37 100644 --- a/crates/engine/src/tests/unplaced_out.rs +++ b/crates/engine/src/tests/unplaced_out.rs @@ -94,10 +94,12 @@ fn what_leaves_the_session_takes_a_feature_it_cant_place_without_that_geometry_a } } -/// A streamed source held in UTM 31N whose second line reaches 1e9 m east, read a chunk at a time. +/// A streamed source held in `crs` (UTM 31N unless said) whose second line reaches 1e9 m east, +/// read a chunk at a time. struct Far { info: rustgis_data::source::SourceInfo, features: Vec, + crs: Option, } impl rustgis_data::source::FeatureSource for Far { @@ -105,7 +107,7 @@ impl rustgis_data::source::FeatureSource for Far { &self.info } fn coord_crs(&self) -> rustgis_data::raster::Crs { - rustgis_data::raster::Crs::from_epsg(32631).unwrap() + self.crs.unwrap_or_else(|| rustgis_data::raster::Crs::from_epsg(32631).unwrap()) } fn read(&self, _: &rustgis_data::source::Request) -> rustgis_data::Result { Ok(rustgis_data::source::Batch { features: self.features.clone(), matched: 2, complete: true, ..Default::default() }) @@ -157,7 +159,7 @@ fn a_streamed_conversion_writes_a_feature_it_cant_place_without_its_geometry_and zm_dropped: false, }; let mut s = Session::new(crate::Project::default()); - let src = rustgis_map::source::SourceLayer::from_path("far.test", None, Box::new(Far { info, features })); + let src = rustgis_map::source::SourceLayer::from_path("far.test", None, Box::new(Far { info, features, crs: None })); s.map_mut().add_streamed("lines", src); for format in ["geojson", "csv"] { let path = d.0.join(format!("lines.{format}")).display().to_string(); @@ -212,3 +214,61 @@ fn kml_counts_a_feature_it_cant_place_as_left_out_and_a_3d_model_is_placed_by_wh assert!(!alone.is_empty()); assert_eq!(alone, beside); } + +/// A tool updating a streamed layer in place keeps a feature with no place in longitude/latitude: +/// a run in the source's own system (UTM) writes the whole source back in it, that feature's +/// geometry as stored; a run in longitude/latitude (a source in Robinson, a world projection) is +/// refused, as the map holds only the layer's window, where that feature's stored geometry may +/// not be. With every place converting, both run. +#[test] +fn an_update_of_a_streamed_layer_keeps_a_feature_it_cant_place() { + use rustgis_data::{Field, FieldType, Geometry, GeometryType, Value, raster::Crs}; + let line = |a: (f64, f64), b: (f64, f64)| { + Some(Geometry::Line(vec![vec![rustgis_geom::Coord::new(a.0, a.1), rustgis_geom::Coord::new(b.0, b.1)]])) + }; + let utm = Crs::from_epsg(32631).unwrap(); + let robinson = Crs::parse("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs").unwrap(); + for (crs, far) in [(utm, false), (utm, true), (robinson, false), (robinson, true)] { + let far_line = line((451_500.0, 5_411_500.0), (1e12, 1e12)); + let mut features = vec![rustgis_data::Feature { + id: 1, + geometry: line((451_000.0, 5_411_000.0), (452_000.0, 5_412_000.0)), + attrs: vec![Value::Text("paris".into())], + }]; + if far { + features.push(rustgis_data::Feature { id: 2, geometry: far_line.clone(), attrs: vec![Value::Text("far".into())] }); + } + let info = rustgis_data::source::SourceInfo { + name: "lines".into(), + format: "test", + geometry_type: GeometryType::Polyline, + fields: vec![Field::new("name", FieldType::Text)], + extent: rustgis_geom::Extent::new(2.3, 48.8, 2.4, 48.9), + count: Some(features.len() as u64), + crs: crs.label(), + indexed: false, + notes: Default::default(), + zm_dropped: false, + }; + let mut s = Session::new(crate::Project::default()); + let src = rustgis_map::source::SourceLayer::from_path("far.test", None, Box::new(Far { info, features, crs: Some(crs) })); + s.map_mut().add_streamed("lines", src); + let r = s.run("gp.run", &json!({"tool": "calculateGeometry", "params": {"input": "lines"}})); + let what = format!("{} far={far}", crs.label()); + if far && crs == robinson { + let e = r.unwrap_err(); + assert!(e.contains("Load All Features") && e.contains("can't be given in longitude/latitude"), "{what}: {e}"); + assert!(s.map().layer_by_name("lines").unwrap().is_streamed(), "{what}: left as it was"); + continue; + } + r.unwrap_or_else(|e| panic!("{what}: {e}")); + let ds = &s.map().layer_by_name("lines").unwrap().dataset; + if crs == utm { + assert_eq!(ds.coord_crs(), utm, "{what}: held in the source's own system"); + } + if far { + let kept = ds.features.iter().find(|f| f.id == 2).unwrap(); + assert_eq!(kept.geometry, far_line, "{what}: its geometry as stored"); + } + } +} diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index 917913cca3..fa7d7dd89f 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -197,7 +197,14 @@ world projection (World Mercator, Plate Carrée, Robinson, Equal Earth and the l the antimeridian as a seam and the poles as lines, is worked on in longitude/latitude, as Web Mercator is. If another input has a place that system can't hold, the tool works in longitude/latitude instead, and its message says so. A layer in longitude/latitude, Web Mercator or -another geographic system is worked on in longitude/latitude, as before. In a projected system a +another geographic system is worked on in longitude/latitude, as before. There, a feature with a place +that can't be given in longitude/latitude (one far past where its layer's own system reaches) is read +without its geometry, and the tool's message says how many of each layer were; a tool that updates +its input in place, as Calculate Geometry Attributes does, leaves that feature's geometry as it was. +A layer read in place from its file (streamed) holds only the part the map shows: an update of it +worked in longitude/latitude that read such a feature without its geometry is refused until you +Load All Features, since that feature's stored geometry may not be in that part. +In a projected system a tool works in, distances in metres (Buffer's, Simplify's tolerance, Points Along Lines' spacing, Near's, and the search distances of Select Layer By Location and Spatial Join) are measured flat there, in its unit, as distances in a projected system are: a kilometre is 1000 of its metres, or @@ -1611,7 +1618,7 @@ click them on the map: | Geostatistical Wizard | An IDW surface from feature values, using 12 nearest neighbours by default | | Network Analysis | The shortest (or cheapest, by a cost field) route over a line layer | | Neighborhood Explorer | What lies within a distance of a point, with sums of numeric fields | -| Simulation | Random points in polygons (a fixed number, or from a field × rate), spread in the layer's own coordinates when it is held in a projected system, else in longitude/latitude (then held in the project's coordinate system when it has one, other than a geocentric one) | +| Simulation | Random points in polygons (a fixed number, or from a field × rate), spread in the layer's own coordinates when it is held in a projected system, else in longitude/latitude (then held in the project's coordinate system when it has one, other than a geocentric one; a polygon with a place that can't be given in longitude/latitude gets no points, and a notice counts them) | | Data Engineering | Counts, nulls, distinct values, min, max and mean of every field | | Exploratory Analysis | Histograms and correlations of numeric fields | | Embeddings | The features most like the selected one, by their numeric attributes | diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index 43602efca9..f3d0764297 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -773,7 +773,9 @@ Turn labels on per layer (Labeling › Labels › **Label**), then: The annotation layer is held in the labelled layer's system; for a layer in longitude/latitude, Web Mercator or another system in degrees, in the project's coordinate system when it has one (not a geocentric one). In a projected system a label's point is found in its own coordinates, where a map in that system draws it; a moved label that - can't be placed there stays at its feature's label point, and the conversion says how many. + can't be placed there stays at its feature's label point, and the conversion says how many. In + longitude/latitude, a feature with a place that can't be given there, which the map doesn't draw + either, gets no annotation, and the conversion says how many. A label along a line becomes an upright point at its line's middle vertex (the end of a line of two), which can be some way from where the label was drawn: its angle, curve, repeats and distance from the line are left out, and the conversion says how many, and how many of them diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index b3103294c9..a3a6964443 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -11,7 +11,9 @@ field from an expression; **Calculate Geometry** (in the attribute table's toolb existing numeric field with each feature's area, perimeter, length or X/Y coordinate, in the units you choose, for all features or the selected ones. Length and perimeter include feet and miles; area includes square feet (`ft2`), acres (`ac`) and square miles (`mi2`). An unrecognized -`edit.calculateGeometry` unit is refused with the valid unit keys for the chosen property. +`edit.calculateGeometry` unit is refused with the valid unit keys for the chosen property. A feature +with a place that can't be given in longitude/latitude (one far past where its layer's own system +reaches) is left empty, and a notice counts them. Every edit is one undo step. Areas, perimeters and lengths measure on the WGS 84 ellipsoid, the same measure as the network tools and the Measure panel (Spatial Join still measures on the sphere). A ring with a full-turn edge, -180° to 180° along a parallel that the ring reaches down one meridian and leaves back up the other (a globe-wide band, or a cap closed diff --git a/xtask/row-uses.txt b/xtask/row-uses.txt index effca51f21..82e07640ac 100644 --- a/xtask/row-uses.txt +++ b/xtask/row-uses.txt @@ -4,4 +4,4 @@ # down: new code reads and changes rows through the accessors on `Features` # (crates/data/src/row_access.rs). When a change lowers it, run `cargo xtask rows --update` and # commit this file with it. -count = 780 +count = 778