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

Limit fixed interval classification to generate at most 999 classes #50290

Closed
wants to merge 6 commits into from

Conversation

uclaros
Copy link
Contributor

@uclaros uclaros commented Sep 22, 2022

Description

Fixed interval has a default value of 1 which can generate way too many classes, leading to crashes - see #49333.
This PR automatically changes the interval size to a value that will not cause more than 999 classes.
999 is the maximum number of classes that we allow for the other interval types so I used this as a ceiling.

Editing the Interval size line edit widget can be a little klutzy when trying to change the forced minimum value, but that's a way better side effect than what we have now (potential crash).
@nyalldawson is there a more elegant way to change the parameter's default value dynamically?

Fix #49333

@github-actions github-actions bot added this to the 3.28.0 milestone Sep 22, 2022
@uclaros uclaros added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 22, 2022
@nyalldawson
Copy link
Collaborator

@nyalldawson is there a more elegant way to change the parameter's default value dynamically?

I'd suggest we don't change the value at all, but instead just apply the limit internally. For bonus points we could add some error reporting capacity to calculateBreaks and then show a warning label in the gui that too many classes were generated and the classification was limited to 999 classes.

@github-actions github-actions bot added the GUI/UX Related to QGIS application GUI or User Experience label Sep 27, 2022
@github-actions
Copy link

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Oct 12, 2022
*/
void updateClasses( const QgsVectorLayer *vl, int nclasses );
void updateClasses( const QgsVectorLayer *vl, int nclasses, QString *error = nullptr );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void updateClasses( const QgsVectorLayer *vl, int nclasses, QString *error = nullptr );
void updateClasses( const QgsVectorLayer *vl, int nclasses, QString *error SIP_OUT = nullptr );

*/
QList<QgsClassificationRange> classes( const QgsVectorLayer *layer, const QString &expression, int nclasses );
QList<QgsClassificationRange> classes( const QgsVectorLayer *layer, const QString &expression, int nclasses, QString *error = nullptr );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
QList<QgsClassificationRange> classes( const QgsVectorLayer *layer, const QString &expression, int nclasses, QString *error = nullptr );
QList<QgsClassificationRange> classes( const QgsVectorLayer *layer, const QString &expression, int nclasses, QString *error SIP_PYARGREMOVE = nullptr );

We can't add this to the bindings, or the method will start returning a tuple and break existing scripts

@@ -335,7 +336,7 @@ class CORE_EXPORT QgsClassificationMethod SIP_ABSTRACT
* The maximum value is expected to be added at the end of the list, but not the minimum
*/
virtual QList<double> calculateBreaks( double &minimum, double &maximum,
const QList<double> &values, int nclasses ) = 0;
const QList<double> &values, int nclasses, QString *error = nullptr ) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const QList<double> &values, int nclasses, QString *error = nullptr ) = 0;
const QList<double> &values, int nclasses, QString *error SIP_PYARGREMOVE = nullptr ) = 0;

For the same reason as above... although, I'm unsure how sip will handle this with a virtual method 😱

Comment on lines +72 to +77
if ( breaks.length() >= 999 )
{
error->clear();
error->append( QObject::tr( "The specified interval would generate too many classes.\nOnly the first 999 classes are actually added." ) );
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if ( breaks.length() >= 999 )
{
error->clear();
error->append( QObject::tr( "The specified interval would generate too many classes.\nOnly the first 999 classes are actually added." ) );
break;
}
if ( breaks.length() >= 999 && error )
{
error = QObject::tr( "The specified interval would generate too many classes.\nOnly the first 999 classes are actually added." );
break;
}

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Oct 17, 2022
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Nov 1, 2022
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

While we hate to see this happen, this PR has been automatically closed because it has not had any activity in the last 21 days. If this pull request should be reconsidered, please follow the guidelines in the previous comment and reopen this pull request. Or, if you have any further questions, just ask! We love to help, and if there's anything the QGIS project can do to help push this PR forward please let us know how we can assist.

@nyalldawson
Copy link
Collaborator

Resurrected in #57722

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! GUI/UX Related to QGIS application GUI or User Experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fixed Interval classification needs a safe-guard against huge number of classes
2 participants