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

Processing port geometry tools #53787

Merged
merged 14 commits into from
Oct 9, 2023
Merged

Processing port geometry tools #53787

merged 14 commits into from
Oct 9, 2023

Conversation

alexbruy
Copy link
Contributor

Description

Port some Python algorithms to C++ as a part of QEP #271.

Voronoi polygons and Delaunay triangulation algorithms ported to C++ and use GEOS to compute operations. Old Python code removed.

Concave hull algorithm ported to C++, old Python code removed. K-nearest concave hull marked as deprecated, but still available to keep existing scripts/models working.

@alexbruy alexbruy added the Processing Relating to QGIS Processing framework or individual Processing algorithms label Jul 11, 2023
@github-actions github-actions bot added this to the 3.34.0 milestone Jul 11, 2023
@agiudiceandrea
Copy link
Member

agiudiceandrea commented Jul 11, 2023

Hi @alexbruy, does this also address the issue reported at #52172?

@lbartoletti
Copy link
Member

I'm +1 to port python processing to C++. But, please, can you make one PR by algorithm as possible?

@alexbruy alexbruy added the Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. label Jul 20, 2023
@qgis-bot
Copy link
Collaborator

@alexbruy
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

engine->prepareGeometry();
for ( const QgsFeatureId id : intersected )
{
if ( engine->intersects( index.geometry( id ).constGet() ) )
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be implied when querying the index built using single points -- we could save the cost here and also avoid storing the geometries in the index.

Potentially a big speed boost by using QgsSpatialIndexKDBush here too.

Copy link
Contributor Author

@alexbruy alexbruy Jul 25, 2023

Choose a reason for hiding this comment

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

Not sure I understand. We can't check for exact intersection with the geometry, index supports only intersection with the rectangle, so we need test whether point actually intersects geometry.

@nyalldawson
Copy link
Collaborator

Regarding concave hull -- can we ifdef in a geos version check and delegate the whole algorithm to geos on newer versions?

@alexbruy
Copy link
Contributor Author

Regarding concave hull -- can we ifdef in a geos version check and delegate the whole algorithm to geos on newer versions?

I might be wrong, but from my tests geos implementation creates concave hull using different approach. At least for me, not matter which threshold I use it always produces the same polygon covering all points.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 9, 2023
@wonder-sk wonder-sk removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 9, 2023
@alexbruy
Copy link
Contributor Author

I may be wrong, but seems old Python implementation produces incorrect results by not including all input points into concave hull polygon.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Sep 11, 2023
@qgis qgis deleted a comment from github-actions bot Sep 12, 2023
@qgis qgis deleted a comment from github-actions bot Sep 12, 2023
@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Sep 12, 2023
Copy link
Contributor

@uclaros uclaros left a comment

Choose a reason for hiding this comment

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

Nice! Just some minor comments

{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ), QList< int >() << QgsProcessing::TypeVectorPoint ) );
std::unique_ptr<QgsProcessingParameterNumber> toleranceParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "TOLERANCE" ), QObject::tr( "Tolerance" ), QgsProcessingParameterNumber::Double, 0, true, 0 );
toleranceParam->setHelp( QObject::tr( "Specifies an optional snapping tolerance which can be used to improve the robustness of the triangulation" ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow! I didn't know you could do this! Why is it only used on 6 algorithms? This should be everywhere!

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's relatively new, introduced after the bulk of the algorithms were already made

Copy link
Collaborator

Choose a reason for hiding this comment

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

But yes, should be everywhere 😁

@nyalldawson nyalldawson added the Freeze Exempt Feature Freeze exemption granted label Sep 15, 2023
@uclaros uclaros closed this Sep 15, 2023
@uclaros uclaros reopened this Sep 15, 2023
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

@alexbruy
A documentation ticket has been opened at qgis/QGIS-Documentation#8548
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@nirvn
Copy link
Contributor

nirvn commented Oct 9, 2023

Nice one @alexbruy

Comment on lines +82 to +92
QgsFields fields;
if ( addAttributes )
{
fields.append( QgsField( QStringLiteral( "POINTA" ), QVariant::LongLong ) );
fields.append( QgsField( QStringLiteral( "POINTB" ), QVariant::LongLong ) );
fields.append( QgsField( QStringLiteral( "POINTC" ), QVariant::LongLong ) );
}
else
{
fields.append( QgsField( QStringLiteral( "id" ), QVariant::LongLong ) );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexbruy I'm on my way to document this PR and wonder if it is deliberate that the output layer contains either an id field or the IDs from the input point. Why not always have the generated id field in the output layer (and add or not the original points)? I guess, something like:

  QgsFields fields;
  fields.append( QgsField( QStringLiteral( "id" ), QVariant::LongLong ) );
  if ( addAttributes )
  {
    fields.append( QgsField( QStringLiteral( "POINTA" ), QVariant::LongLong ) );
    fields.append( QgsField( QStringLiteral( "POINTB" ), QVariant::LongLong ) );
    fields.append( QgsField( QStringLiteral( "POINTC" ), QVariant::LongLong ) );
  }

Same applies to Voronoi afaict. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is intentional, this is behaviour of the original Python implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Freeze Exempt Feature Freeze exemption granted Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants