Repository navigation
feat(crs): held layers: the globe's longitude/latitude copy in a cache of its own, undrawable places said, a sync compares same-system copies as held (#2032 C2b) #2528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -498,9 +498,12 @@ fn selected_lines(s: &Session, p: &Value, all: bool) -> Result<Vec<Vec<Coord>>, | |
| }; | ||
| // Sampled in longitude/latitude, whatever system the layer holds its coordinates in. | ||
| let mut out: Vec<Vec<Coord>> = Vec::new(); | ||
| 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) = &*l.dataset.geometry_to_lonlat(g).map_err(|e| format!("{n}: feature {}: {e}", f.id()))? { | ||
| if let Geometry::Line(parts) = | ||
| &*rustgis_data::Dataset::geometry_to_lonlat_by(&to, g).map_err(|e| format!("{n}: feature {}: {e}", f.id()))? | ||
| { | ||
| let v: Vec<Coord> = parts.iter().flatten().copied().collect(); | ||
| if v.len() >= 2 { | ||
| out.push(v); | ||
|
|
@@ -884,16 +887,33 @@ pub(crate) fn sync_area(s: &mut Session, ai: usize, edited: &rustgis_map::Map) - | |
| // system the source, its last synced copy or the package hold them in; the source is | ||
| // written back in its own, its unchanged places as stored (`results_from_lonlat`). | ||
| let ol_ds = ol.dataset.in_lonlat().map_err(|e| format!("cannot sync layer '{}': {e}", ol.name))?; | ||
| let baseline = area | ||
| .data | ||
| .layers | ||
| .iter() | ||
| .find(|l| l.id == ol.id) | ||
| .map(|l| l.dataset.in_lonlat()) | ||
| .transpose() | ||
| .map_err(|e| format!("cannot sync layer '{}': {e}", ol.name))?; | ||
| let last_synced = area.data.layers.iter().find(|l| l.id == ol.id).map(|l| &l.dataset); | ||
| let baseline = last_synced.map(|d| d.in_lonlat()).transpose().map_err(|e| format!("cannot sync layer '{}': {e}", ol.name))?; | ||
| // Whether a feature was edited offline: the returned copy against the last synced one, | ||
| // as they are when both are held in the same system (as an offline map in the project | ||
| // and its area are), so a conversion that changed meanwhile (a datum grid downloaded) | ||
| // can't make an unedited feature look edited; else both in longitude/latitude. | ||
| type ById<'a> = std::collections::HashMap<u64, rustgis_data::RowRef<'a>>; | ||
| fn by_id(d: &rustgis_data::Dataset) -> ById<'_> { | ||
| d.features.rows().map(|r| (r.id(), r)).collect() | ||
| } | ||
| let raw: Option<(ById<'_>, ById<'_>)> = | ||
| last_synced.filter(|b| b.coord_crs() == ol.dataset.coord_crs()).map(|b| (by_id(b), by_id(&ol.dataset))); | ||
| let same_row = |a: rustgis_data::RowRef, b: rustgis_data::RowRef| a.geometry() == b.geometry() && a.values().eq(b.values()); | ||
| // `lonlat_base` and `lonlat_now`, the copies in longitude/latitude, are used only when | ||
| // the two aren't held in the same system. | ||
| let unchanged_offline = |fid: u64, lonlat_base: Option<&&rustgis_data::Feature>, lonlat_now: &rustgis_data::Feature| match &raw | ||
| { | ||
| Some((raw_base, raw_now)) => raw_base.get(&fid).is_some_and(|b| raw_now.get(&fid).is_some_and(|n| same_row(*b, *n))), | ||
| None => lonlat_base.is_some_and(|b| *b == lonlat_now), | ||
| }; | ||
| let same_as_last = match (&raw, &baseline) { | ||
| (Some(_), Some(_)) => last_synced.is_some_and(|b| b.features == ol.dataset.features), | ||
| (None, Some(b)) => b.features == ol_ds.features, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug (confidence: medium, ~0.6). This is the case the PR's third bullet says it fixes, and it still isn't fixed for a returned package. When the returned copy is held in longitude/latitude but the source and last-synced copy are held in UTM, Suggested fix: compare the returned copy against the lonlat copy frozen when the area was downloaded or last synced, rather than re-converting the baseline now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept for C2c, and the PR body now says so under "Not in this PR". The same-system path covers an offline map in the project. A field package returned in longitude/latitude to a source held in UTM is still compared in longitude/latitude, because there's no longitude/latitude copy from the download to compare it with: the area keeps its last synced copy in the source's system. Packages from held sources first occur with the flip, so the fix goes there: keep the area's longitude/latitude copy from packaging and compare the returned copy with it. Until then, the conflict notice names such a feature and Undo restores the source. |
||
| _ => false, | ||
| }; | ||
| if !offline_fields_match(&sl.dataset.fields, &ol_ds.fields) | ||
| && baseline.as_ref().is_none_or(|b| !offline_fields_match(&b.fields, &ol_ds.fields) || b.features != ol_ds.features) | ||
| && baseline.as_ref().is_none_or(|b| !offline_fields_match(&b.fields, &ol_ds.fields) || !same_as_last) | ||
| { | ||
| return Err(format!("cannot sync layer '{}': source and offline fields differ; align the fields before syncing", ol.name)); | ||
| } | ||
|
|
@@ -926,7 +946,7 @@ pub(crate) fn sync_area(s: &mut Session, ai: usize, edited: &rustgis_map::Map) - | |
| for f in &ol_ds.features { | ||
| let fid = f.id; | ||
| if had.contains(&fid) { | ||
| let changed_offline = base.get(&fid).is_none_or(|b| *b != f); | ||
| let changed_offline = !unchanged_offline(fid, base.get(&fid), f); | ||
| match sl.dataset.features.iter_mut().find(|x| x.id == fid) { | ||
| Some(x) if changed_offline && x != f => { | ||
| if base.get(&fid).is_some_and(|b| *b != x) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -852,6 +852,10 @@ pub struct Session { | |
| pub(crate) crs_used_elsewhere: Vec<(String, String)>, | ||
| /// When the frame path last looked for missing datum grids ([`Session::say_grid_notes`]). | ||
| grid_notes_checked: Option<web_time::Instant>, | ||
| /// Each layer held in another system (by instance) and the geometry revision and system whose | ||
| /// places were last counted for [`Session::say_unplaced`], so a version of a layer is looked at | ||
| /// once. | ||
| unplaced_checked: std::collections::HashMap<u64, (u64, rustgis_data::raster::Crs)>, | ||
| /// The datum grids the map's layers were last projected with | ||
| /// ([`rustgis_data::raster::crs::grid_generation`]). | ||
| grid_generation: u64, | ||
|
|
@@ -1337,6 +1341,7 @@ impl Session { | |
| grid_pairs: Vec::new(), | ||
| crs_used_elsewhere: Vec::new(), | ||
| grid_notes_checked: None, | ||
| unplaced_checked: Default::default(), | ||
| grid_generation: rustgis_data::raster::crs::grid_generation(), | ||
| grid_downloads_said: Default::default(), | ||
| grid_turns: 0, | ||
|
|
@@ -1767,6 +1772,7 @@ impl Session { | |
| self.undo_memory.publish(&self.project, &self.undo, &self.redo); | ||
| // And the coordinate systems that needed a missing datum grid, after every command. | ||
| self.say_grid_notes(); | ||
| self.say_unplaced(); | ||
| // A plugin's command waiting for its fetches answers `pending` and runs again when they | ||
| // land: logged then, once. (Another command's `pending`, a download the web app makes, is | ||
| // logged as it is asked for: nothing runs it again.) | ||
|
|
@@ -3060,6 +3066,60 @@ impl Session { | |
| if due { | ||
| self.grid_notes_checked = Some(web_time::Instant::now()); | ||
| self.say_grid_notes(); | ||
| self.say_unplaced(); | ||
| } | ||
| } | ||
|
|
||
| /// Says, once for each version of a layer's geometry, that a layer held in another system | ||
| /// has features with a place that can't be given in longitude/latitude, which the map and | ||
| /// the globe draw from: they draw such a feature without that place (a line broken there, a | ||
| /// point not at all), and labels' lines, block diagrams and terrain water leave it out. Or | ||
| /// that none of the layer is drawn, when its system can't be converted. | ||
| /// Layers in longitude/latitude, every layer read today, are passed over at no cost. A held | ||
| /// layer's count reads each of its places through the conversion, on the UI thread with no | ||
| /// Cancel, once per version of its geometry: as long as converting it for the map takes. | ||
| fn say_unplaced(&mut self) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance / Never hold the window (confidence: medium, ~0.5).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stated in bafe9e2, with the move off the UI thread left for part 2 (#2032). The doc comments of |
||
| // One notice per kind, with the count and the layers it is about. | ||
| let (mut features, mut partly, mut undrawn) = (0usize, Vec::new(), Vec::new()); | ||
| let mut seen = std::collections::HashSet::new(); | ||
| for map in &self.project.maps { | ||
| for l in map.layers.iter().filter(|l| !l.is_raster() && l.dataset.coord_crs() != rustgis_data::raster::Crs::LonLat) { | ||
| seen.insert(l.instance_id()); | ||
| let version = (l.geometry_rev(), l.dataset.coord_crs()); | ||
| if self.unplaced_checked.insert(l.instance_id(), version) == Some(version) { | ||
| continue; | ||
| } | ||
| match l.dataset.unplaced_in_lonlat() { | ||
| Ok(0) => {} | ||
| Ok(n) => { | ||
| features += n; | ||
| partly.push(format!("map '{}', layer '{}' ({n})", map.name, l.name)); | ||
| } | ||
| Err(e) => undrawn.push(format!("map '{}', layer '{}': {e}", map.name, l.name)), | ||
| } | ||
| } | ||
| } | ||
| // Layers gone are forgotten, so the map stays as small as the project. | ||
| self.unplaced_checked.retain(|id, _| seen.contains(id)); | ||
| let listed = |v: &[String]| { | ||
| let more = v.len().saturating_sub(10); | ||
| let shown = v.iter().take(10).cloned().collect::<Vec<_>>().join("; "); | ||
| if more > 0 { format!("{shown}; and {more} more") } else { shown } | ||
| }; | ||
| if features > 0 { | ||
| let text = format!( | ||
| "{features} feature(s) have a place that can't be given in longitude/latitude: the map and the globe draw them without it, and labels' lines, block diagrams and terrain water leave them out ({})", | ||
| listed(&partly) | ||
| ); | ||
| self.notice(text, rustgis_data::diagnostics::Severity::Warning); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| if !undrawn.is_empty() { | ||
| let text = format!( | ||
| "{} layer(s) aren't drawn, as their system can't be given in longitude/latitude: {}", | ||
| undrawn.len(), | ||
| listed(&undrawn) | ||
| ); | ||
| self.notice(text, rustgis_data::diagnostics::Severity::Warning); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AGENTS.md notices (confidence: low-medium, ~0.4). AGENTS.md asks for "one notice per kind with a count". This loop emits one notice per held layer, so two held layers with undrawable features give two notices of the same kind. Aggregate them into a single notice that names the layers and gives the total count.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in bafe9e2: one notice per kind. One counts every held layer's features with a place that can't be given in longitude/latitude, and names each map and layer with its count (up to 10, then "and N more"). The other names the layers whose system can't be converted at all. |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behaviour change (confidence: low, ~0.3). The layer's conversion is now resolved before the loop, so the command fails for an unconvertible system even when no selected row has a geometry. Before, the error came only from a feature that reached the conversion. The same pattern appears in
items.rs(layer_mesh),sharing.rs(styled_features),stac_area.rs(selected) andworkspace.rs(selected_lines). Failing here is consistent with "unusable results are errors", so this is probably acceptable. The PR doesn't mention it, though, so please state it in the PR body or confirm the early failure is intended.