I have a set of routes which are represented by LineStrings in my PostGIS database. These routes represent journeys that people make. I want to come up with routes that (a) overlap, and (b) have the same "direction" (orientation?). I.e., I want to figure out which journeys have the most in common.
To understand what I mean by direction, please see the figure below. The paths A (red) and B (green) start at the hollow markers and end at the solid markers respectively. They overlap to a considerable extent, but they have different directions and hence don't match.
I can find intersections using ST_Intersection(.). Now I need to filter out paths with opposite directions. How can I accomplish this?
EDIT: for now I have an approach based on angle between vectors from start to end points of the paths, but it can clearly fail if the paths intersect but are not "parallel" in their entirety. So I am still looking for answers.
Thanks in advance!