Measuring / calculating curvature of linestring using QGIS?

How can I measure/calculate the curvature of a linestring?

I need just a boolean value: is curved or is not curved.

At the moment, I don't find a working strategy for that.

• Does "not curved" for you mean all the points are on a straight line? – Spacedman Jun 27 '19 at 14:53
• Yes it does. My problem is that a straight line does not necessarily have to have two points. In my application a polygon line has been created from many points. This was divided into different segments depending on a defined length value. Each segment is a line string and consists of at least two points. One point is at the beginning and one point at the end of this line. However, other points can also lie between them. The preparatory work was done by a colleague. I shall now extend the individual segments with information, e.g. curvature. Translated with www.DeepL.com/Translator – md118 Jun 27 '19 at 15:11
• I don't understand your first solution, but it's working. – md118 Jul 1 '19 at 8:05
• look up what a "convex hull" of a set of points is. Then you can see that the convex hull of a straight line of points is a polygon that is a straight line - it has no width. This will have zero area. – Spacedman Jul 1 '19 at 10:19

Some of many (somewhat hacky) solutions using the field calculator:

• select to add a field with type `BOOLEAN`
• use one of the expressions (returning `true` when line is curved)

``````area( convex_hull( \$geometry ) ) > 0 AND area( convex_hull( \$geometry ) ) IS NOT NULL
``````

or, probably better performing

``````length( \$geometry ) > distance( start_point( \$geometry ), end_point( \$geometry ) )
``````

or many more...

• Why do you have to catch NULL in the first example? – Spacedman Jun 27 '19 at 18:16
• @Spacedman either a LineString is invalid for the `convex_hull` function or, more likely, the `area` function doesn't like invalid polygon, didn't check (you might even use a different syntax, but then you'd necessarily add a `NOT` comparison. or use a is_straight column). the expression returned `NULL` for straight lines when I validated (QGIS 3.8, Linux). I should have emphasized the second approach anyways I guess, calculating the convey hull for more complex geometries is way more expensive. – ThingumaBob Jun 27 '19 at 20:52
• Will the length test work for a straight line that jumps back on itself? eg a LINESTRING from A to B and then back to the midpoint between A and B? I think overlapping and intersecting LINESTRINGS are valid simple features... – Spacedman Jun 27 '19 at 21:52
• although it may be that a line feature that jumps back on itself is "curved" with a 180 degree curve and should therefore be classed as "curved"... depends on the use case. Two nice hacks anyway. – Spacedman Jun 27 '19 at 22:12
• @Spacedman that's indeed an edge case...most angle based computations will result in this case being `True`. the matrix determinant of the slope functions between vertices would return `False`, or you could rotate the line so that the end point has the same Y, then check if any vertice is above or below. way more involved anyways... – ThingumaBob Jun 28 '19 at 6:28