Answer the question
In order to leave comments, you need to log in
How to find the nearest street to a GPS point?
There are GPS coordinates. You need to find the nearest street to each GPS point. I found an example of such a request:
SELECT p.id AS point_id, b.id AS road_id, ST_DISTANCE(b.geom, p.geom) AS distance
FROM points p
CROSS JOIN LATERAL (
SELECT r.id AS id, r.geom AS geom
FROM roads r
ORDER BY r.geom <-> p.geom
LIMIT 1
) b;
Answer the question
In order to leave comments, you need to log in
Yes, ST_POINT right there .
But in general, a strange request. Usually build a buffer of 100, 200, etc. meters, and look at which road got into it closer.
And you can do it without a buffer if you only need a name:
SELECT osm_id, highway, name, tags, ST_DISTANCE(way, point) AS Distance
FROM public.planet_osm_line
INNER JOIN (SELECT ST_TRANSFORM( ST_SetSRID(ST_POINT(48.323, 54.263), 4326), 900913) AS point ) AS p
ON ST_DWithin(point, way, 200)
WHERE highway IS NOT NULL AND name IS NOT NULL
ORDER BY Distance
LIMIT 1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question