Great, thanks Daniel. So, if the route returned from postgis doesn't overlap the start/end points (ie, ST_Line_Locate_Point returns 0 or 1), is there an elegant way to add another linestring / multilinestring to the beginning or end of the route? I considered manually constructing a LINESTRING with my point and the first or last point of the route, but that wouldn't include things like the street name, source and target from the ways table.<br>
<br><div class="gmail_quote">On Mon, Nov 14, 2011 at 6:32 PM, Daniel Kastl <span dir="ltr"><<a href="mailto:daniel@georepublic.de">daniel@georepublic.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<div><br></div><div>When you run your routing query you unfortunately don't know yet which direction it will take. So when you start from the nearest road link, it's either "too much" or a small part is missing.</div>
<div>The workshop example is kept very simple. There are other PostGIS functions, that can help you to locate the nearest point on the road link and then return a substring:</div><div><ul><li><a href="http://postgis.refractions.net/docs/ST_Line_Locate_Point.html" target="_blank">http://postgis.refractions.net/docs/ST_Line_Locate_Point.html</a></li>
<li><a href="http://postgis.refractions.net/docs/ST_Line_Substring.html" target="_blank">http://postgis.refractions.net/docs/ST_Line_Substring.html</a></li></ul></div><div>So after you got your route you need to check which direction it went and which substring to add.</div>
<div><br></div><div>Daniel</div><div><br></div><div><br><br><div class="gmail_quote"><div><div class="h5">On Tue, Nov 15, 2011 at 3:09 AM, John Williams <span dir="ltr"><<a href="mailto:jdwilliams1982@gmail.com" target="_blank">jdwilliams1982@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">This may be obvious, but for whatever reason, I'm not able to figure it out. When calculating driving directions with pgrouting, to find the starting and ending points for the path finding algorithm, I'm using the sample "findNearestEdge" function from pgrouting's website, which looks like this:<br>
<br>function findNearestEdge($lonlat) {<br><br> $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER);<br><br> $sql = "SELECT gid, source, target, the_geom,<br> distance(the_geom, GeometryFromText(<br>
'POINT(".$lonlat[0]." ".$lonlat[1].")', 4326)) AS dist<br> FROM ".TABLE."<br> WHERE the_geom && setsrid(<br> 'BOX3D(".($lonlat[0]-0.1)."<br>
".($lonlat[1]-0.1).",<br> ".($lonlat[0]+0.1)."<br> ".($lonlat[1]+0.1).")'::box3d, 4326)<br> ORDER BY dist LIMIT 1";<br>
<br> $query = pg_query($con,$sql);<br><br> $edge['gid'] = pg_fetch_result($query, 0, 0);<br> $edge['source'] = pg_fetch_result($query, 0, 1);<br> $edge['target'] = pg_fetch_result($query, 0, 2);<br>
$edge['the_geom'] = pg_fetch_result($query, 0, 3);<br><br> pg_close($con);<br><br> return $edge;<br>}<br><br><br>What I'd like to do is adjust the starting and ending points so they match up exactly with my lat/lon beginning/ending points. For example, the way it works now if my destination is mid-way down a particular street and I plot the route on a map, it may look like the route takes you to the end of the block, when it should have stopped earlier, or vice-versa. I hope that makes sense...<br>
<br>My lack of expertise with pgrouting keeps me from understanding some other posts I've seen about this topic. Could someone point me in the right direction... thanks a lot.<br>
<br></div></div>_______________________________________________<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" target="_blank">http://lists.osgeo.org/mailman/listinfo/pgrouting-users</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">Georepublic UG & Georepublic Japan<br>
eMail: <a href="mailto:daniel.kastl@georepublic.de" style="color:rgb(66, 99, 171)" target="_blank">daniel.kastl@georepublic.de</a><br>
Web: <a href="http://georepublic.de/" style="color:rgb(66, 99, 171)" target="_blank">http://georepublic.de</a></span><br>
</font></span></div>
<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" target="_blank">http://lists.osgeo.org/mailman/listinfo/pgrouting-users</a><br>
<br></blockquote></div><br>