Skip to content

Commit

Permalink
add straight distance expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Koyaani authored and nyalldawson committed Aug 23, 2021
1 parent f7ffa42 commit bffaabe
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -3603,6 +3603,21 @@ static QVariant fcnSinuosity( const QVariantList &values, const QgsExpressionCon
return QVariant( curve->sinuosity() );
}

static QVariant fcnStraightDistance2d( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom.constGet() );
if ( !curve )
{
parent->setEvalErrorString( QObject::tr( "Function `straight_distance_2d` requires a line geometry." ) );
return QVariant();
}

return QVariant( curve->straightDistance2d() );
}



static QVariant fcnFlipCoordinates( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
Expand Down Expand Up @@ -7042,7 +7057,9 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
<< new QgsStaticExpressionFunction( QStringLiteral( "m_min" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ),
fcnMMin, QStringLiteral( "GeometryGroup" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "sinuosity" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ),
fcnSinuosity, QStringLiteral( "GeometryGroup" ) );
fcnSinuosity, QStringLiteral( "GeometryGroup" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "straight_distance_2d" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ),
fcnStraightDistance2d, QStringLiteral( "GeometryGroup" ) );


QgsStaticExpressionFunction *orderPartsFunc = new QgsStaticExpressionFunction( QStringLiteral( "order_parts" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) )
Expand Down

0 comments on commit bffaabe

Please sign in to comment.