<HTML dir=ltr><HEAD><TITLE>RE: [postgis-users] match line with road segment</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2900.5583" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText39673 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Now you do your make line.  But you'll have to take into consideration what Paolo Rizzi said afterward.  Not sure the easiest way to do that.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>So basically your process should look something like the below where trip_id is some fied that uniquely identifies each trip.  The below snaps each point to closest road segment and then makes a line for each trip.  It assumes the pt.gid is in the order of time travel.  If you have a datetime field for each point, use that instead of the pt.gid.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr> SELECT trip_id, ST_MakeLine(snapped_point) As trip_route<PRE>(SELECT<BR>pt_id,<BR>ln_id,<BR><BR>ST_Line_Interpolate_Point(<BR> ln_geom,<BR> ST_Line_Locate_Point(ln_geom, pt_geom)<BR> ) As snapped_point,</PRE><PRE>travel_id<BR><BR>FROM<BR>(<BR>SELECT DISTINCT ON (pt.gid)<BR> ln.the_geom AS ln_geom,<BR> pt.the_geom AS pt_geom,<BR> ln.id AS ln_id,<BR> pt.gid AS pt_id,pt.trip_id<BR>FROM<BR>gps_points pt INNER JOIN<BR>road_table ln<BR>ON<BR>ST_DWithin(pt.the_geom, ln.the_geom, 10.0)<BR>ORDER BY<BR>pt.gid,ST_Distance(ln.the_geom, pt.the_geom)<BR>) AS subquery ORDER BY trip_id, pt_id) As snapped_points</PRE><PRE>GROUP BY travel_id;</PRE></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Hope that helps,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>Regina</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> postgis-users-bounces@postgis.refractions.net on behalf of searchelite<BR><B>Sent:</B> Thu 7/17/2008 10:23 AM<BR><B>To:</B> postgis-users@postgis.refractions.net<BR><B>Subject:</B> RE: [postgis-users] match line with road segment<BR></FONT><BR></DIV>
<DIV><BR><BR>
<P><FONT size=2>Paragon Corporation-2 wrote:<BR>><BR>> You may be better off snapping the points to the line first before you do<BR>> a<BR>> make line.  Take a look at Paul's blog entry. <BR>><BR>><BR>> <A href="http://blog.cleverelephant.ca/2008/04/snapping-points-in-postgis.html">http://blog.cleverelephant.ca/2008/04/snapping-points-in-postgis.html</A><BR>><BR>> Sounds similar to what you are trying to do.<BR>><BR>> Hope that helps,<BR>> Regina<BR>><BR>><BR><BR>Thanks for the reply...Yes, I already did that (snapping the point to the<BR>line)..so, is there any idea what should i do next?<BR>thanks<BR>--<BR>View this message in context: <A href="http://www.nabble.com/match-line-with-road-segment-tp18479996p18509643.html">http://www.nabble.com/match-line-with-road-segment-tp18479996p18509643.html</A><BR>Sent from the PostGIS - User mailing list archive at Nabble.com.<BR><BR>_______________________________________________<BR>postgis-users mailing list<BR>postgis-users@postgis.refractions.net<BR><A href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A><BR></FONT></P></DIV></BODY></HTML>
<HTML><BODY><P><hr size=1></P>
<P><STRONG>
The substance of this message, including any attachments, may be confidential, legally privileged and/or exempt from disclosure pursuant to Massachusetts law. It is intended solely for the addressee. If you received this in error, please contact the sender and delete the material from any computer.
</STRONG></P></BODY></HTML>

<P><hr size=1></P>
<P><STRONG><font size="2" color="339900"> Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper. </p> <p> </font></STRONG></P>