<div dir="ltr">Hi Steve,<div><br></div><div>Thanks a lot for your response.</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 24, 2015 at 1:55 AM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 6/23/2015 3:56 PM, Manikanta Kondeti wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I am writing a small application to get the route on the map. I am<br>
using openlayers.js on client and pgrouting as a backend routing library<br>
for my project. When a click is triggered I get a lat, lon, and I have<br>
the osm data in postgres which is loaded using osm2pgrouting. I'll pass<br>
this lat,lon to server and I have to find the nearest node id from this<br>
lat,lon. Can I query the database and get it done? Help me out.<br>
</blockquote>
<br></div></div>
Probably you want to do this in two steps:<br>
<br>
1. find the nearest edge<br>
2. find the nearest node along the edge<br>
<br>
Anyway your queries will be something like: <br></blockquote><div><br></div><div>This is working perfect and found the nearest edge. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-- get the closest edge<br>
select * from edges where st_dwithin(geom, st_setsrid(st_makepoint(long, lat), 4326), maxdist) order by st_distance(geom, st_setsrid(st_makepoint(long, lat), 4326)) asc limit 1;<br>
<br></blockquote><div><br></div><div>This is giving me syntax error. I've added the screenshot </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-- get closest node along edge<br>
select case when st_line_locate_point(geom,st_setsrid(st_makepoint(long, lat), 4326)) < 0.5 then source else target from edges edge_id=id<br>
<br>
<br>
<br></blockquote><div><br></div><div>This is not giving me any nearest nodes. I've this screenshot as well. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-- or search to just get the closest node<br>
select * from nodes where st_dwithin(geom, st_setsrid(st_makepoint(long, lat), 4326), maxdist) order by st_distance(geom, st_setsrid(st_makepoint(long, lat), 4326)) asc limit 1;<br>
<br>
<br>
where:<br>
<br>
maxdist - maximum distance to search for geometries in db units probably degrees<br>
<br>
long, lat - values for the location in question<br>
<br>
id - is the id of the closest edge found in the first query<br></blockquote><div><br></div><div><br></div><div><br></div><div>Let me know if I miss something. </div><div><br></div><div>Thanks, </div><div>Mani </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org" target="_blank">Pgrouting-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/pgrouting-users" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/pgrouting-users</a><br>
</blockquote></div><br></div></div>