Add straightDistance2d and sinuosity measures to QgsCurve

This commit is contained in:
Nyall Dawson 2018-03-11 08:16:00 +10:00
parent 05fb8f7349
commit 6c179059a5
3 changed files with 54 additions and 0 deletions

View File

@ -186,6 +186,26 @@ Returns the y-coordinate of the specified node in the line string.
Returns a QPolygonF representing the points.
%End
double straightDistance2d() const;
%Docstring
Returns the straight distance of the curve, i.e. the direct/euclidean distance
between the first and last vertex of the curve. (Also known as
"as the crow flies" distance).
.. versionadded:: 3.2
%End
double sinuosity() const;
%Docstring
Returns the curve sinuosity, which is the ratio of the curve length() to curve
straightDistance2d(). Larger numbers indicate a more "sinuous" curve (i.e. more
"bendy"). The minimum value returned of 1.0 indicates a perfectly straight curve.
If a curve isClosed(), it has infinite sinuosity and will return NaN.
.. versionadded:: 3.2
%End
protected:

View File

@ -200,6 +200,20 @@ QPolygonF QgsCurve::asQPolygonF() const
return points;
}
double QgsCurve::straightDistance2d() const
{
return startPoint().distance( endPoint() );
}
double QgsCurve::sinuosity() const
{
double d = straightDistance2d();
if ( qgsDoubleNear( d, 0.0 ) )
return std::numeric_limits<double>::quiet_NaN();
return length() / d;
}
void QgsCurve::clearCache() const
{
mBoundingBox = QgsRectangle();

View File

@ -168,6 +168,26 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
*/
QPolygonF asQPolygonF() const;
/**
* Returns the straight distance of the curve, i.e. the direct/euclidean distance
* between the first and last vertex of the curve. (Also known as
* "as the crow flies" distance).
*
* \since QGIS 3.2
*/
double straightDistance2d() const;
/**
* Returns the curve sinuosity, which is the ratio of the curve length() to curve
* straightDistance2d(). Larger numbers indicate a more "sinuous" curve (i.e. more
* "bendy"). The minimum value returned of 1.0 indicates a perfectly straight curve.
*
* If a curve isClosed(), it has infinite sinuosity and will return NaN.
*
* \since QGIS 3.2
*/
double sinuosity() const;
#ifndef SIP_RUN
/**