How to calculate line complexity index

I'm wondering if there is any suitable algorithm that can I use to calculate line complexity index (or indicator)? By "line complexity" I mean how many bends (direction changes) that line contains and how sharp they are.

I want to use that index to correct driving speed of road network segments. Lots of road segments in my dataset have speed defined according to road type, which is not even close to the real achievable speed. For example, mountain pass road has a speed limit of 90kph, but in real life, 60kph is more realistic due to curvature of that road.

I'm primarily interested in a solution for PostGIS/PostgreSQL.

The best solution i have come up so far is something like this:

st_area(st_polygonize(st_union(st_simplify(geom, 10), geom)) / st_length(geom)

It calculates how much space (area) per unit of length is between the original and simplified version of geometry. Bigger index means more complex shape, thus bigger speed penalty. Simplification threshold (10 in my example) was chosen by trial and error, also how it will be applied to adjust speed is not clear at this point.

Is this feasible, or is there a better approach?

• You could compare line length to euclidian distance from startpoint to endpoint. But that might be over simplifying it
– BERA
Sep 12 '19 at 8:12
• I don't have a solution, but maybe an idea to build on if you would also be willing to work with QGIS: you could try to measure angles at each vertex with the expression-editor and the angle_at_vertex function. You could add all the values (be aware how to deal with positive and negative values) and relate the result to the total length. Like this you get a measure for the sinuosity of the road. Of course, you could simple calculate the proportion of total road-length to the length of a straight line from the beginning to the end (first to last vertex) of your line. Sep 12 '19 at 8:12
• And still another approach, depending on how detailed your data is: simply count the number of vertices (per distance): a straight-line section will contain much less vertices than a curved road. For other solutions, google for sinuosity and the tool you want to use (i.e. PostGIS/PostgreSQL) Sep 12 '19 at 8:19
• as an addition to the sinuosity; you should be able to use ST_SetEffectiveArea to derive statistics about a lines per-vertex curvature; it's a common simplification method, but it's values can be used to measure curvature properties. Sep 12 '19 at 9:36