I have to develop a map-matching algorithm. At the moment I only match GPS points with the closest road segment. I'm looking for a way to compare the directions between a GPS point and a road to improve the matching. I have already looked at many subjects and I found a way to compare the directions but I've an issue for getting the direction of each GPS point.
I use PostGIS to store and manipulate my data, and I want to compute the azimuth of each GPS point. My problem is to have the set of points which can be used to build a line and calculate the azimuth of this line with:
My idea was to take all GPS points inside an area around the current GPS point to build a line and finally give the direction of this line to the current GPS point. My problem is to get the actual GPS point, currentPoint in the query below:
SELECT degrees(ST_Azimuth(ST_StartPoint(new_line),ST_EndPoint(new_line))) FROM ( SELECT DISTINCT ON(gps.gid) gps.gid, ST_MakeLine(gps.geom ORDER BY gps.gid) AS new_line FROM gps WHERE ST_DWITHIN( currentPoint?, gps.geom, 50) ) AS query;