I have a set of polylines (numbering in the 100s of thousands, with each polyline having about 200-300 vertices). These represent routes on a map (all taken from Google Maps API, if that helps). The vertices are latitude/longitude coordinates.
I am now given a query polyline, and I have to find the "overlaps" of the query polyline with any of the existing polylines. The results thus themselves will be polylines, sorted in the order of maximum to least overlap. I only need the first 100 results or so. An additional issue is that the overlap need not be exact, but can be approximate (i.e., portions of line segments that are deemed overlapping needn't lie on other another, but only need be "close" to each other).
To give a concrete representation, in the left portion of the image below, the blue polyline (polyline A) is a polyline in the database, and the red polyline (polyline B) is the query polyline. The algorithm should determine the polyline marked in thick black as shown in the right.
I am currently leaning towards using a spatial database (the option under consideration is PostgreSQL + PostGIS), but I am not sure that the latency would be acceptable - the query needs to return results near instantaneously. My computational-geometry-fu is admittedly weak, but I was wondering: are there any existing algorithms or approaches that might prove useful to solve this particular problem?
Many thanks in advance!