Skip to content
Permalink
Browse files

Add straightDistance2d and sinuosity measures to QgsCurve

  • Loading branch information
nyalldawson committed Mar 10, 2018
1 parent 05fb8f7 commit 6c179059a5222da52a733234d8743b91c06c3656
Showing with 54 additions and 0 deletions.
  1. +20 −0 python/core/geometry/qgscurve.sip.in
  2. +14 −0 src/core/geometry/qgscurve.cpp
  3. +20 −0 src/core/geometry/qgscurve.h
@@ -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:
@@ -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();
@@ -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

/**

0 comments on commit 6c17905

Please sign in to comment.
You can’t perform that action at this time.