Skip to content
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

[digitizing] Split features: always give largest geometry to original feature #59806

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

JuhoErvasti
Copy link
Contributor

@JuhoErvasti JuhoErvasti commented Dec 10, 2024

Fixes #53696. Backport to 3.40 requested.

split

Funded by the National Land Survey of Finland.

@github-actions github-actions bot added this to the 3.42.0 milestone Dec 10, 2024
@JuhoErvasti JuhoErvasti changed the title [digitizing] Split features: add a way to sort split features before they are added to the layer [digitizing] Split features: allow sorting split features before they are added to the layer Dec 10, 2024
@JuhoErvasti JuhoErvasti force-pushed the 53696_keep_id_of_largest_feature branch from 5639f14 to 1716ddb Compare December 10, 2024 14:07
Copy link

github-actions bot commented Dec 10, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit c9981ad)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit c9981ad)

@nyalldawson
Copy link
Collaborator

@JuhoErvasti do you currently have a use case for this beyond that described by #53696 ? If there's no concrete use case for custom sorting, then I'd avoid the complexity and just ALWAYS use the largest part (as described in #53696)

@JuhoErvasti
Copy link
Contributor Author

@nyalldawson
Not immediately, there was a concern that #53696 could be too specific to the funder and therefore a solution would require giving options to different users. I reached out to Oslandia's devs and @troopa81 suggested the idea to use expressions.

If this is not necessary, I can of course change it. In this case since you can split a feature an arbitrary number of times should all of them still be sorted by area/length or just that the original feature will get the largest geometry?

@nyalldawson
Copy link
Collaborator

@JuhoErvasti

I'm wondering if instead it'd make more sense to handle this in the split tool itself, so that users can interactively pick on a split-by-split basis which feature is the "reference" feature.

Eg maybe something like ctrl+click with the tool sets the reference point, and then after the split the part closest to the reference point becomes the reference (original) feature geometry.

@JuhoErvasti
Copy link
Contributor Author

JuhoErvasti commented Dec 12, 2024

@nyalldawson
That'd definitely make it quite flexible, but I think it also adds more complexity, at least from the user's perspective. For example in the use case behind #53696 there are rules for managing the lifecycle of features, one of which would be that when splitting the biggest geometry goes to the original feature.

You'd then have to remember to set the reference point each time and in some cases it can be difficult to eyeball which is the biggest feature, making it more error-prone. Also potentially if there's different rules for different layers you'd have to remember them and keep track of that as well.

I think that feature would work for some situations, but I think there's also a very solid case for being able to set a layer-level rule to avoid manual work and mistakes.

Edit: I do understand that this implementation does add complexity. We wanted make it an option preemptively in case other users/organizations have different needs. Would it be better from the complexity perspective if instead of an expression there were preset options (a bit similar to the Attributes Form split/duplicate policies?

Copy link
Contributor

@troopa81 troopa81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to complete @JuhoErvasti, my concerns was that user would be continuously asking for different way of choosing the reference feature according to their needs, so better have an expression and maybe a list of classic order (area, length).

Regarding the PR, not sure sorting order is needed. Because you can order in ascending with $area, and descending with 1/$area, no?

@nyalldawson Your proposal is interesting but it makes the UI a little bit complex with even more click when it is not (always) needed.

@nyalldawson
Copy link
Collaborator

@JuhoErvasti
@troopa81

That'd definitely make it quite flexible, but I think it also adds more complexity, at least from the user's perspective. For example in the use case behind #53696 there are rules for managing the lifecycle of features, one of which would be that when splitting the biggest geometry goes to the original feature.

You'd then have to remember to set the reference point each time and in some cases it can be difficult to eyeball which is the biggest feature, making it more error-prone. Also potentially if there's different rules for different layers you'd have to remember them and keep track of that as well.

What I'm proposing are two changes:

  1. Default to ALWAYS retaining the biggest part. That becomes the standard behaviour, no GUI for changing or controlling it. This fixes the situation immediately and transparently for 99% of users, with no added complexity.
  2. Add some way of picking the reference part in the GUI in an opt-in way, which doesn't change the tool at all for users who don't care about picking the reference part and are happy with the biggest-part logic to apply. That's why I'm thinking something like a ctrl+click in advance, as it's only ever going to be required/used in advanced circumstances and won't change any existing workflows at all

@JuhoErvasti
Copy link
Contributor Author

@nyalldawson

Well, that would take care of the use case I'm trying to address. I'm okay to make that change if is no need for custom sorting. If I could then ask a few more questions:

  • Would it be enough to just implement the behavior in #53696 to start with, and create a separate feature request for the CTRL+click behaviour?
    • If yes, could it also be backported into 3.40? Or would it be considered a new feature?
  • Should the behavior be that if you're splitting the feature to more than 2 parts the split geometries are sorted or just that it finds the biggest geometry and that will be the original feature and the rest created in the random(ish) order like right now?

@troopa81

Regarding the PR, not sure sorting order is needed. Because you can order in ascending with $area, and descending with 1/$area, no?

That would work, I thought I'd add it for consistency since some other sorting features in the GUI have it as well (at least feature rendering order).

@nyalldawson
Copy link
Collaborator

@JuhoErvasti

Would it be enough to just implement the behavior in #53696 to start with, and create a separate feature request for the CTRL+click behaviour?

That's fine by me! I don't personally think the second part is a requirement, I just think it's a better approach to handling advanced situations vs the expression. So if you just want to do the "always biggest part" logic only, that's perfectly reasonable.

If yes, could it also be backported into 3.40? Or would it be considered a new feature?

I think it can be considered a bug fix, yes.

Should the behavior be that if you're splitting the feature to more than 2 parts the split geometries are sorted or just that it finds the biggest geometry and that will be the original feature and the rest created in the random(ish) order like right now?

I'm fine with just the single biggest part being treated special, and the rest in random order. Ordering for adding features usually isn't important anyway.

@JuhoErvasti JuhoErvasti force-pushed the 53696_keep_id_of_largest_feature branch from 1716ddb to b2d4fc8 Compare December 16, 2024 11:25
@JuhoErvasti JuhoErvasti changed the title [digitizing] Split features: allow sorting split features before they are added to the layer [digitizing] Split features: always give largest geometry to original feature Dec 16, 2024
@JuhoErvasti
Copy link
Contributor Author

JuhoErvasti commented Dec 16, 2024

@nyalldawson

I've force-pushed the change to just always give the biggest geom to the original feature and also updated the description if you want to take look.

I had to modify some existing tests, some of them were retrieving the new feature by a hard-coded number and the change also affected the split policy test.

- This change was made to match the change in b2d4fc8
  where the largest geometry is now inherited by the original feature when
  splitting features.
- This caused the test to fail for the 'field_unset' and 'field_ratio' attributes
  since the largest feature with the largest 'field_ratio' attribute
  also had the original 'field_unset' value and the others had an unset
  attribute
@nyalldawson
Copy link
Collaborator

@JuhoErvasti looks good to me, thanks!

@nyalldawson
Copy link
Collaborator

We'll wait for @troopa81's feedback before merging

@JuhoErvasti
Copy link
Contributor Author

@nyalldawson @troopa81

Thank you! Could this be tagged for a backport to 3.40 as well? 🙏

@troopa81
Copy link
Contributor

LGTM

@troopa81 troopa81 merged commit e6134fd into qgis:master Dec 17, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep the id of the largest feature when splitting features
3 participants