Skip to content

Commit

Permalink
length3D function: handle curved geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
agiudiceandrea authored and nyalldawson committed Feb 24, 2021
1 parent 3ebf915 commit 173732c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -1365,19 +1365,17 @@ static QVariant fcnLength3D( const QVariantList &values, const QgsExpressionCont
return QVariant();

if ( !geom.isMultipart() )
return QVariant( qgsgeometry_cast< const QgsLineString * >( geom.constGet() )->length3D() );
return QVariant( qgsgeometry_cast< const QgsCurve * >( geom.constGet() )->curveToLine()->length3D() );

if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() ) )
{
if ( collection->numGeometries() > 0 )
double sumLength3DParts = 0;
for ( int i = 0; i < collection->numGeometries(); ++i )
{
double sumLength3DParts = 0;
for ( int i = 0; i < collection->numGeometries(); ++i )
{
sumLength3DParts += qgsgeometry_cast< const QgsLineString * >( collection->geometryN( i ) )->length3D();
}
return QVariant( sumLength3DParts );
if ( const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( collection->geometryN( i ) ) )
sumLength3DParts += curve->curveToLine()->length3D();
}
return QVariant( sumLength3DParts );
}

return QVariant();
Expand Down

0 comments on commit 173732c

Please sign in to comment.