0

I am using the following query in SpatiaLite to find the closest road segment to a given GPS location:

SELECT id, Distance(segment, GeomFromText('POINT(-79.406166 43.666075)'),1) AS Distance
FROM rs
WHERE ROWID IN (
    SELECT ROWID FROM SpatialIndex
    WHERE f_table_name = 'rs'
      AND f_geometry_column = 'segment'
      AND search_frame = ST_Expand(MakePoint(--79.406166, 43.666075, 4326), .001)
    LIMIT 10
)
ORDER BY Distance ASC LIMIT 1;

Now I am having trouble at intersections because the GPS points are literarily closer to another segment than the one the car is travelling on. Examples below: enter image description here

enter image description here

As far as the query goes, what else can I add to it so that even at intersections it will choose the road I am actually traveling on?

1
  • Can you join some road id to the points by the highest point count, then add a where clause to only search for closest point where the joined id is matching the nearest road?
    – Bera
    Commented Mar 18 at 17:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.