Repository navigation
Edits, paste, topology and offline sync with a feature that has no longitude/latitude place (#2032 C2f-4b-1c) #2842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d686aed
Carry-overs: the planetary check reads a PROJ definition's radius any…
pick2510 2efaf6e
Edits, paste, topology and sync leave out a feature with a place that…
pick2510 f845bf2
Review: a paste converts before it changes the layer; a rule that lef…
pick2510 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,13 +141,53 @@ fn coerce(v: &Attr, ty: FieldType) -> (Attr, Cut) { | |
| } | ||
|
|
||
| fn paste(s: &mut Session, p: &Value) -> CmdResult { | ||
| let (src, said) = clip(s, p)?; | ||
| let (mut src, said) = clip(s, p)?; | ||
| let id = s.layer_id(p)?; | ||
| let l = s.map_mut().layer_mut(id).ok_or("no such layer")?; | ||
| if l.is_raster() { | ||
| return Err("features can't be pasted into a raster layer".into()); | ||
| } | ||
| let want = l.geometry_type(); | ||
| // The shapes the layer takes, written in its own coordinates from the system the clipboard | ||
| // holds them in: as they are in a layer of that system (pasted where they were copied from, | ||
| // nothing moves), else converted by the operation between the two, which doesn't depend on | ||
| // the map. All converted before anything changes; one with a place the layer's system can't | ||
| // hold is left out, counted and said, rather than the paste refused. | ||
| let (from, own) = (src.coord_crs(), l.dataset.coord_crs()); | ||
| // Into Web Mercator by way of longitude/latitude, where the latitudes it can't hold are found. | ||
| let steps = if from == own { | ||
| vec![] | ||
| } else if own == Crs::WebMercator && from != Crs::LonLat { | ||
| vec![from.to(Crs::LonLat)?, Crs::LonLat.to(own)?] | ||
| } else { | ||
| vec![from.to(own)?] | ||
| }; | ||
| let mut placed = Vec::with_capacity(src.features.len()); | ||
| if !steps.is_empty() { | ||
| let none = rustgis_data::HeldPlaces::default(); | ||
| for r in 0..src.features.len() { | ||
| let fits = src.features.row(r).and_then(|x| x.geometry()).is_some_and(|g| want == GeometryType::None || g.kind() == want); | ||
| let Some(Some(g)) = fits.then(|| src.features.set_geometry(r, None)).flatten() else { | ||
| placed.push(true); | ||
| continue; | ||
| }; | ||
| match steps.iter().try_fold(g, |g, to| Dataset::edit_from_lonlat_by(to, g, &none)) { | ||
| Ok(g) => { | ||
| src.features.set_geometry(r, Some(g)); | ||
| placed.push(true); | ||
| } | ||
| Err(_) => placed.push(false), | ||
| } | ||
| } | ||
| } | ||
| let unplaced = placed.iter().filter(|p| !**p).count(); | ||
| if unplaced > 0 { | ||
| let mut keep = placed.into_iter(); | ||
| src.features.retain_rows(|_| keep.next().unwrap_or(true)); | ||
| if src.features.is_empty() { | ||
| return Err(format!("Paste: the copied feature(s) have a place {} ({}) can't hold", l.name, own.label())); | ||
|
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. The wording reads as if the layer's name were a place: "the copied feature(s) have a place plain (Robinson) can't hold". Make the layer the subject, as the notice below does: Category: quality |
||
| } | ||
| } | ||
| // Ids for every feature the layer takes (one of another shape is left out below), above every id | ||
| // it has or keeps new rows above, refused before anything changes when they would run past the | ||
| // largest id. | ||
|
|
@@ -184,30 +224,11 @@ fn paste(s: &mut Session, p: &Value) -> CmdResult { | |
| // Per field, what converting the pasted values cut, and the values that aren't null but that | ||
| // the field can't hold. | ||
| let mut unfit = vec![(Cuts::default(), 0usize); l.dataset.fields.len()]; | ||
| // The features the layer takes, their shapes written in its own coordinates from the system | ||
| // the clipboard holds them in: as they are in a layer of that system (pasted where they were | ||
| // copied from, nothing moves), else converted by the operation between the two, which | ||
| // doesn't depend on the map. All converted before any is added. | ||
| let (from, own) = (src.coord_crs(), l.dataset.coord_crs()); | ||
| let mut taken: Vec<Feature> = src | ||
| let taken: Vec<Feature> = src | ||
| .features | ||
| .into_iter() | ||
| .filter(|ft| !ft.geometry.as_ref().is_some_and(|g| want != GeometryType::None && g.kind() != want)) | ||
| .collect(); | ||
| // Into Web Mercator by way of longitude/latitude, where the latitudes it can't hold are found. | ||
| let steps = if from == own { | ||
| vec![] | ||
| } else if own == Crs::WebMercator && from != Crs::LonLat { | ||
| vec![from.to(Crs::LonLat)?, Crs::LonLat.to(own)?] | ||
| } else { | ||
| vec![from.to(own)?] | ||
| }; | ||
| let none = rustgis_data::HeldPlaces::default(); | ||
| for ft in &mut taken { | ||
| for to in &steps { | ||
| ft.geometry = ft.geometry.take().map(|g| Dataset::edit_from_lonlat_by(to, g, &none)).transpose()?; | ||
| } | ||
| } | ||
| for ft in taken { | ||
| next = next.saturating_add(1); | ||
| let attrs = l | ||
|
|
@@ -234,6 +255,14 @@ fn paste(s: &mut Session, p: &Value) -> CmdResult { | |
| let name = l.name.clone(); | ||
| let features = |n: usize| if n == 1 { "1 feature".to_string() } else { format!("{n} features") }; | ||
| let mut notices = Vec::new(); | ||
| if unplaced > 0 { | ||
| let (have, they) = if unplaced == 1 { ("has", "it wasn't") } else { ("have", "they weren't") }; | ||
| notices.push(format!( | ||
| "Paste: {} {have} a place that layer {name} ({}) can't hold, so {they} pasted", | ||
| features(unplaced), | ||
| own.label() | ||
| )); | ||
| } | ||
| for (f, (cuts, n)) in l.dataset.fields.iter().zip(unfit) { | ||
| notices.extend(cuts.notices("Paste", &f.name)); | ||
| if n > 0 { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
feature_to_lonlatnamesself.name, the dataset's name, in its refusal. The file already notes that a layer's map name can differ from its data's name after a name clash (thenamedclosure incheck_topology, and the sync path usingown.name), and the PR's own topology test is written around that. This error can therefore name a different layer than the one the user sees on the map.Suggested fix: take the map layer name as a parameter from the callers (they already have
l.name), or document in the doc comment that the name is the data's name so callers that know the map name can replace it.Category: quality