I want to be able to identify the closest roads to two points that are generated through geocoding (a start and end address). The points will likely be near a linestring. Two approaches that I have been experimenting with are:
-- Method 1:
SELECT
id
FROM
routing
WHERE
ST_DWithin(ST_Transform(ST_Setsrid(ST_Makepoint(-6.17706680000, 53.300791),4326), 900913), geom, 50.0)
ORDER BY ,
ST_distance(geom_way, ST_Transform(ST_Setsrid(ST_Makepoint(-6.17706680000, 53.300791),4326), 900913))
LIMIT 1;
--Time: 228 ms
-- Method 2:
SELECT
id
FROM
routing
WHERE
ST_Intersects(geom, ST_buffer(ST_Transform(ST_Setsrid(ST_Makepoint(-6.17706680000, 53.300791),4326), 900913), 50))
ORDER BY ,
ST_Distance(geom, ST_Transform(ST_Setsrid(ST_Makepoint(-6.17706680000, 53.300791),4326), 900913))
LIMIT 1;
--Time: 248 ms
While both of these are quite fast, I'm unsure if this is the best way of performing this calculation. Both methods assume that the geo-coded point will be <50m away from a road. I also want to figure out the best way of finding two roads and cannot think of an alternative, other than to run to separate queries sequentially, which would mean that it takes ~0.5 seconds in total using the current set-up.
