-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Transect swap orientation #64359
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
base: master
Are you sure you want to change the base?
Transect swap orientation #64359
Conversation
|
@lbartoletti 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. Thank you! |
🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. 🍎 MacOS Qt6 buildsDownload MacOS Qt6 builds of this PR for testing. |
|
Thank you @lbartoletti! |
Yes, it makes sense. |
29dcb8b to
d3acfe7
Compare
|
|
||
| addParameter( new QgsProcessingParameterEnum( QStringLiteral( "SIDE" ), QObject::tr( "Side to create the transects" ), QStringList() << QObject::tr( "Left" ) << QObject::tr( "Right" ) << QObject::tr( "Both" ), false, 2 ) ); | ||
|
|
||
| auto direction = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "DIRECTION" ), QObject::tr( "Direction" ), QStringList() << QObject::tr( "Left to Right" ) << QObject::tr( "Right to Left" ), false, 0 ); |
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.
Do you think this should be marked 'optional' to maintain compatibility with older scripts?
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.
indeed, good idea.
d3acfe7 to
f186cbc
Compare
| // Direction determines the line orientation: | ||
| // - LeftToRight: line goes from pLeft to pRight (default) | ||
| // - RightToLeft: line goes from pRight to pLeft (hydraulic convention - perpendicular from stream bank looking downstream) | ||
| if ( direction == QgsTransectAlgorithmBase::RightToLeft ) | ||
| { | ||
| line.append( pRight ); | ||
| line.append( pLeft ); | ||
| } | ||
| else | ||
| { | ||
| line.append( pLeft ); | ||
| line.append( pRight ); | ||
| } |
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.
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.
So, it should be:
if ( direction == QgsTransectAlgorithmBase::RightToLeft )
{
line.append( pLeft );
line.append( pRight );
}
else
{
line.append( pRight );
line.append( pLeft );
}
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.
I believe so
and rename pLeft and pRight ?
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.
Can't write a suggestion but here is what I would do:
QgsGeometry QgsTransectAlgorithmBase::calcTransect( const QgsPoint &point, const double angleAtVertex, const double length, const QgsTransectAlgorithmBase::Side orientation, const double angle, const QgsTransectAlgorithmBase::Direction direction )
{
// Transect is built from right to left relative to the reference line direction.
QgsPoint pStart; // start point of the transect
QgsPoint pEnd; // end point of the transect
QgsPolyline transect;
switch ( orientation )
{
case QgsTransectAlgorithmBase::Right:
pStart = point.project( length, angle + 180.0 / M_PI * angleAtVertex );
pEnd = point;
break;
case QgsTransectAlgorithmBase::Left:
pEnd = point.project( -length, angle + 180.0 / M_PI * angleAtVertex );
pStart = point;
break;
case QgsTransectAlgorithmBase::Both:
pStart = point.project( length, angle + 180.0 / M_PI * angleAtVertex );
pEnd = point.project( -length, angle + 180.0 / M_PI * angleAtVertex );
break;
}
// Direction determines the transect orientation relative to the reference line direction:
// - RightToLeft: transect goes from pStart to pEnd (default)
// - LeftToRight: transect goes from pEnd to pStart (hydraulic convention - from left bank to right bank looking downstream)
if ( direction == QgsTransectAlgorithmBase::RightToLeft )
{
transect.append( pStart );
transect.append( pEnd );
}
else
{
transect.append( pEnd );
transect.append( pStart );
}
return QgsGeometry::fromPolyline( transect );
}- Do not mention
lineto avoid confusion with the line from which we are creating transects, mentiontransectinstead - Use
pStartandpEndduring transect construction (mention at beginning that transect is built from right to left relative to the reference line direction.
|
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
|

Description
@nicogodet Follow up our discussion on #61545
@DelazJ after this pr, we can rewrite the documentation 😉
I'm not sure about the wording here.