<div dir="ltr">Sorry...<div><br></div><div>It's this!</div><div><br></div><div>SELECT source, target, id, percentual from (SELECT the_geom, ST_GeometryFromText('POINT(%.4f %.4f)', 4326) as point, osm_name, source, target, id, ST_LineLocatePoint(the_geom,ST_GeometryFromText('POINT(%.4f %.4f)', 4326)) as percentual FROM ruas ORDER BY the_geom <#> ST_GeometryFromText('POINT(%.4f %.4f)', 4326) LIMIT 100)a order by st_distance(point, the_geom) limit 1;<br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">..<br><b><font face="'arial black', sans-serif">Omar Fernando Pessôa</font></b><br><a href="http://www.opessoa.com" target="_blank">http://www.opessoa.com</a><br>Desenvolvedor de sistemas<br>Programador C# e C++</div></div>
<br><div class="gmail_quote">2015-06-24 8:30 GMT-03:00  <span dir="ltr"><<a href="mailto:pgrouting-users-request@lists.osgeo.org" target="_blank">pgrouting-users-request@lists.osgeo.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send Pgrouting-users mailing list submissions to<br>
        <a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<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>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:pgrouting-users-request@lists.osgeo.org">pgrouting-users-request@lists.osgeo.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:pgrouting-users-owner@lists.osgeo.org">pgrouting-users-owner@lists.osgeo.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Pgrouting-users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: Reg: Get nearest node in osm data (Manikanta Kondeti)<br>
   2. Re: Pgrouting-users Digest, Vol 81, Issue 2 (Omar Fernando Pess?a)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Wed, 24 Jun 2015 05:02:52 +0530<br>
From: Manikanta Kondeti <<a href="mailto:mani.iiit123@gmail.com">mani.iiit123@gmail.com</a>><br>
To: pgRouting users mailing list <<a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a>><br>
Subject: Re: [pgrouting-users] Reg: Get nearest node in osm data<br>
Message-ID:<br>
        <CAMxCCEaqSjAQX+5T0WigOeSWoM+e21cFM5zgq=<a href="mailto:TRQdV5AQ-egw@mail.gmail.com">TRQdV5AQ-egw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Sorted it.<br>
<br>
After small correction:<br>
         select case when<br>
st_line_locate_point(the_geom,st_setsrid(st_makepoint(67.338263167225,<br>
-17.1189713223), 4326)) < 0.5 then (source) else (target) END AS node FROM<br>
ways WHERE gid=400280;<br>
<br>
Thank you,<br>
Mani<br>
<br>
On Wed, Jun 24, 2015 at 2:33 AM, Manikanta Kondeti <<a href="mailto:mani.iiit123@gmail.com">mani.iiit123@gmail.com</a>><br>
wrote:<br>
<br>
> Hi Steve,<br>
><br>
> Thanks a lot for your response.<br>
><br>
> On Wed, Jun 24, 2015 at 1:55 AM, Stephen Woodbridge <<br>
> <a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a>> wrote:<br>
><br>
>> On 6/23/2015 3:56 PM, Manikanta Kondeti wrote:<br>
>><br>
>>> 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>
>>><br>
>><br>
>> 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>
>><br>
><br>
> This is working perfect and found the nearest edge.<br>
><br>
><br>
>> -- get the closest edge<br>
>> select * from edges where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
>> lat), 4326), maxdist) order by st_distance(geom,<br>
>> st_setsrid(st_makepoint(long, lat), 4326)) asc limit 1;<br>
>><br>
>><br>
> This is giving me syntax error. I've added the screenshot<br>
><br>
><br>
>> -- get closest node along edge<br>
>> select case when st_line_locate_point(geom,st_setsrid(st_makepoint(long,<br>
>> lat), 4326))  < 0.5 then source else target from edges edge_id=id<br>
>><br>
>><br>
>><br>
>><br>
> This is not giving me any nearest nodes. I've this screenshot as well.<br>
><br>
><br>
>> -- or search to just get the closest node<br>
>> select * from nodes where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
>> lat), 4326), maxdist) order by st_distance(geom,<br>
>> 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<br>
>> 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>
>><br>
><br>
><br>
><br>
> Let me know if I miss something.<br>
><br>
> Thanks,<br>
> Mani<br>
><br>
><br>
><br>
>> _______________________________________________<br>
>> Pgrouting-users mailing list<br>
>> <a href="mailto:Pgrouting-users@lists.osgeo.org">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>
>><br>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/6654cb35/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/6654cb35/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Wed, 24 Jun 2015 08:30:39 -0300<br>
From: Omar Fernando Pess?a <<a href="mailto:omar.pessoa@gmail.com">omar.pessoa@gmail.com</a>><br>
To: <a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a><br>
Subject: Re: [pgrouting-users] Pgrouting-users Digest, Vol 81, Issue 2<br>
Message-ID:<br>
        <<a href="mailto:CAOikBm5NrioWTdRUjDBOYQygDokH-gGnM73PCrwDadaopyc6cQ@mail.gmail.com">CAOikBm5NrioWTdRUjDBOYQygDokH-gGnM73PCrwDadaopyc6cQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
You can find the nearest point using <#> operator. It's faster.<br>
<br>
SELECT source, target, id, ST_LineLocatePoint(the_geom,<br>
ST_GeometryFromText('POINT(%.4f %.4f)',4326)) as percentual FROM<br>
vertex_ruas ORDER BY the_geom <#> ST_GeometryFromText('POINT(%.4f<br>
%.4f)',4326) LIMIT 1;<br>
<br>
..<br>
*Omar Fernando Pess?a*<br>
<a href="http://www.opessoa.com" rel="noreferrer" target="_blank">http://www.opessoa.com</a><br>
Desenvolvedor de sistemas<br>
Programador C# e C++<br>
<br>
2015-06-23 18:04 GMT-03:00 <<a href="mailto:pgrouting-users-request@lists.osgeo.org">pgrouting-users-request@lists.osgeo.org</a>>:<br>
<br>
> Send Pgrouting-users mailing list submissions to<br>
>         <a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a><br>
><br>
> To subscribe or unsubscribe via the World Wide Web, visit<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>
> or, via email, send a message with subject or body 'help' to<br>
>         <a href="mailto:pgrouting-users-request@lists.osgeo.org">pgrouting-users-request@lists.osgeo.org</a><br>
><br>
> You can reach the person managing the list at<br>
>         <a href="mailto:pgrouting-users-owner@lists.osgeo.org">pgrouting-users-owner@lists.osgeo.org</a><br>
><br>
> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of Pgrouting-users digest..."<br>
><br>
><br>
> Today's Topics:<br>
><br>
>    1. Reg: Get nearest node in osm data (Manikanta Kondeti)<br>
>    2. Re: Reg: Get nearest node in osm data (Stephen Woodbridge)<br>
>    3. Re: Reg: Get nearest node in osm data (Manikanta Kondeti)<br>
><br>
><br>
> ----------------------------------------------------------------------<br>
><br>
> Message: 1<br>
> Date: Wed, 24 Jun 2015 01:26:32 +0530<br>
> From: Manikanta Kondeti <<a href="mailto:mani.iiit123@gmail.com">mani.iiit123@gmail.com</a>><br>
> To: pgRouting users mailing list <<a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a>><br>
> Subject: [pgrouting-users] Reg: Get nearest node in osm data<br>
> Message-ID:<br>
>         <CAMxCCEbigsduMLqQXQUsd=SzBi76F1ZZy1bcFhd9DG=<br>
> <a href="mailto:WKvT_wg@mail.gmail.com">WKvT_wg@mail.gmail.com</a>><br>
> Content-Type: text/plain; charset="utf-8"<br>
><br>
> Hi,<br>
><br>
>  I am writing a small application to get the route on the map. I am using<br>
> openlayers.js on client and pgrouting as a backend routing library for my<br>
> project. When a click is triggered I get a lat, lon, and I have the osm<br>
> data in postgres which is loaded using osm2pgrouting. I'll pass this<br>
> 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>
><br>
> Thank you,<br>
> Mani<br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <<br>
> <a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/b561eb58/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/b561eb58/attachment-0001.html</a><br>
> ><br>
><br>
> ------------------------------<br>
><br>
> Message: 2<br>
> Date: Tue, 23 Jun 2015 16:25:53 -0400<br>
> From: Stephen Woodbridge <<a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a>><br>
> To: <a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a><br>
> Subject: Re: [pgrouting-users] Reg: Get nearest node in osm data<br>
> Message-ID: <<a href="mailto:5589C0D1.3080809@swoodbridge.com">5589C0D1.3080809@swoodbridge.com</a>><br>
> Content-Type: text/plain; charset=windows-1252; format=flowed<br>
><br>
> On 6/23/2015 3:56 PM, Manikanta Kondeti wrote:<br>
> > 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>
><br>
> 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>
><br>
> -- get the closest edge<br>
> select * from edges where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
> lat), 4326), maxdist) order by st_distance(geom,<br>
> st_setsrid(st_makepoint(long, lat), 4326)) asc limit 1;<br>
><br>
> -- get closest node along edge<br>
> select case when st_line_locate_point(geom,st_setsrid(st_makepoint(long,<br>
> lat), 4326))  < 0.5 then source else target from edges edge_id=id<br>
><br>
><br>
><br>
> -- or search to just get the closest node<br>
> select * from nodes where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
> lat), 4326), maxdist) order by st_distance(geom,<br>
> 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<br>
> 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>
><br>
><br>
> ------------------------------<br>
><br>
> Message: 3<br>
> Date: Wed, 24 Jun 2015 02:33:57 +0530<br>
> From: Manikanta Kondeti <<a href="mailto:mani.iiit123@gmail.com">mani.iiit123@gmail.com</a>><br>
> To: pgRouting users mailing list <<a href="mailto:pgrouting-users@lists.osgeo.org">pgrouting-users@lists.osgeo.org</a>><br>
> Subject: Re: [pgrouting-users] Reg: Get nearest node in osm data<br>
> Message-ID:<br>
>         <CAMxCCEZpdrsYZh=QXHkZaU2gbAtBgC8jvoTLQm=V=<br>
> <a href="mailto:O1jc6YwVA@mail.gmail.com">O1jc6YwVA@mail.gmail.com</a>><br>
> Content-Type: text/plain; charset="utf-8"<br>
><br>
> Hi Steve,<br>
><br>
> Thanks a lot for your response.<br>
><br>
> On Wed, Jun 24, 2015 at 1:55 AM, Stephen Woodbridge <<br>
> <a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a><br>
> > wrote:<br>
><br>
> > On 6/23/2015 3:56 PM, Manikanta Kondeti wrote:<br>
> ><br>
> >> 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>
> >><br>
> ><br>
> > 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>
> ><br>
><br>
> This is working perfect and found the nearest edge.<br>
><br>
><br>
> > -- get the closest edge<br>
> > select * from edges where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
> > lat), 4326), maxdist) order by st_distance(geom,<br>
> > st_setsrid(st_makepoint(long, lat), 4326)) asc limit 1;<br>
> ><br>
> ><br>
> This is giving me syntax error. I've added the screenshot<br>
><br>
><br>
> > -- get closest node along edge<br>
> > select case when st_line_locate_point(geom,st_setsrid(st_makepoint(long,<br>
> > lat), 4326))  < 0.5 then source else target from edges edge_id=id<br>
> ><br>
> ><br>
> ><br>
> ><br>
> This is not giving me any nearest nodes. I've this screenshot as well.<br>
><br>
><br>
> > -- or search to just get the closest node<br>
> > select * from nodes where st_dwithin(geom, st_setsrid(st_makepoint(long,<br>
> > lat), 4326), maxdist) order by st_distance(geom,<br>
> > 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<br>
> > 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>
> ><br>
><br>
><br>
><br>
> Let me know if I miss something.<br>
><br>
> Thanks,<br>
> Mani<br>
><br>
><br>
><br>
> > _______________________________________________<br>
> > Pgrouting-users mailing list<br>
> > <a href="mailto:Pgrouting-users@lists.osgeo.org">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>
> ><br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <<br>
> <a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment.html</a><br>
> ><br>
> -------------- next part --------------<br>
> A non-text attachment was scrubbed...<br>
> Name: Screen Shot 2015-06-24 at 2.30.06 AM.png<br>
> Type: image/png<br>
> Size: 29586 bytes<br>
> Desc: not available<br>
> URL: <<br>
> <a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment.png" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment.png</a><br>
> ><br>
> -------------- next part --------------<br>
> A non-text attachment was scrubbed...<br>
> Name: Screen Shot 2015-06-24 at 2.33.45 AM.png<br>
> Type: image/png<br>
> Size: 78018 bytes<br>
> Desc: not available<br>
> URL: <<br>
> <a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment-0001.png" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/e0c842f9/attachment-0001.png</a><br>
> ><br>
><br>
> ------------------------------<br>
><br>
> _______________________________________________<br>
> Pgrouting-users mailing list<br>
> <a href="mailto:Pgrouting-users@lists.osgeo.org">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>
><br>
> End of Pgrouting-users Digest, Vol 81, Issue 2<br>
> **********************************************<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/1fadf753/attachment.html" rel="noreferrer" target="_blank">http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20150624/1fadf753/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org">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>
<br>
End of Pgrouting-users Digest, Vol 81, Issue 3<br>
**********************************************<br>
</blockquote></div><br></div>