B
B
beduin012017-04-12 11:49:47
PostgreSQL
beduin01, 2017-04-12 11:49:47

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;

I can't figure out how to use it. For example, I have coordinates:
lon, lat 37.72308, 55.47957 Should
I enter them in `ST_DISTANCE`? If so, in what form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2017-04-12
@beduin01

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 question

Ask a Question

731 491 924 answers to any question