File tree 3 files changed +54
-0
lines changed
3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,26 @@ Returns the y-coordinate of the specified node in the line string.
186
186
Returns a QPolygonF representing the points.
187
187
%End
188
188
189
+ double straightDistance2d() const;
190
+ %Docstring
191
+ Returns the straight distance of the curve, i.e. the direct/euclidean distance
192
+ between the first and last vertex of the curve. (Also known as
193
+ "as the crow flies" distance).
194
+
195
+ .. versionadded:: 3.2
196
+ %End
197
+
198
+ double sinuosity() const;
199
+ %Docstring
200
+ Returns the curve sinuosity, which is the ratio of the curve length() to curve
201
+ straightDistance2d(). Larger numbers indicate a more "sinuous" curve (i.e. more
202
+ "bendy"). The minimum value returned of 1.0 indicates a perfectly straight curve.
203
+
204
+ If a curve isClosed(), it has infinite sinuosity and will return NaN.
205
+
206
+ .. versionadded:: 3.2
207
+ %End
208
+
189
209
190
210
191
211
protected:
Original file line number Diff line number Diff line change @@ -200,6 +200,20 @@ QPolygonF QgsCurve::asQPolygonF() const
200
200
return points;
201
201
}
202
202
203
+ double QgsCurve::straightDistance2d () const
204
+ {
205
+ return startPoint ().distance ( endPoint () );
206
+ }
207
+
208
+ double QgsCurve::sinuosity () const
209
+ {
210
+ double d = straightDistance2d ();
211
+ if ( qgsDoubleNear ( d, 0.0 ) )
212
+ return std::numeric_limits<double >::quiet_NaN ();
213
+
214
+ return length () / d;
215
+ }
216
+
203
217
void QgsCurve::clearCache () const
204
218
{
205
219
mBoundingBox = QgsRectangle ();
Original file line number Diff line number Diff line change @@ -168,6 +168,26 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
168
168
*/
169
169
QPolygonF asQPolygonF () const ;
170
170
171
+ /* *
172
+ * Returns the straight distance of the curve, i.e. the direct/euclidean distance
173
+ * between the first and last vertex of the curve. (Also known as
174
+ * "as the crow flies" distance).
175
+ *
176
+ * \since QGIS 3.2
177
+ */
178
+ double straightDistance2d () const ;
179
+
180
+ /* *
181
+ * Returns the curve sinuosity, which is the ratio of the curve length() to curve
182
+ * straightDistance2d(). Larger numbers indicate a more "sinuous" curve (i.e. more
183
+ * "bendy"). The minimum value returned of 1.0 indicates a perfectly straight curve.
184
+ *
185
+ * If a curve isClosed(), it has infinite sinuosity and will return NaN.
186
+ *
187
+ * \since QGIS 3.2
188
+ */
189
+ double sinuosity () const ;
190
+
171
191
#ifndef SIP_RUN
172
192
173
193
/* *
You can’t perform that action at this time.
0 commit comments