<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle18
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:536353101;
        mso-list-type:hybrid;
        mso-list-template-ids:380289216 -1945199570 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level4
        {mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level7
        {mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span lang=EN-GB>Hi,<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>I am using pgRouting for my road routing.
However, the results are not correct enough. The results starts from the start
of the road (MULTILINESTRING) where the source Point is and finish till the end
of the road (MULTILINESTRING) where the destination Point is.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>What I would like to do is :<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo2'><![if !supportLists]><span
lang=EN-GB><span style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>         
</span></span></span><![endif]><span lang=EN-GB>Add a point to the starting of
the MULTILINESTRING (thus to its first LINESTRING), so as to have a line
between the source POINT till the Starting Point of the mentioned
MULTILINESTRING.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>This is what I tried to achieve :<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>      var_id := 1;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>      FOR
rec_shooting_star IN<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>      
        
    EXECUTE var_text_shootingstar<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>       
LOOP<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
IF var_id = 1 THEN<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
RAISE NOTICE '--CHANGING the Starting Point--';<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
RAISE NOTICE 'Geometry type working on is : %, and as text :
%',geometrytype(rec_shooting_star.the_geom),
astext(rec_shooting_star.the_geom);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
var_num_geoms := NumGeometries(rec_shooting_star.the_geom);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
RAISE NOTICE 'Total Number of Geometries : %',var_num_geoms;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
FOR var_i IN 1 .. var_num_geoms <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                           
LOOP<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
RAISE NOTICE 'Inside the Geometry array filling';<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                                               
array_geoms[var_i] := geometryN (rec_shooting_star.the_geom, var_i);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                           
END LOOP;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
var_first_linestring := geometryN (rec_shooting_star.the_geom, 1);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
        RAISE NOTICE 'Old start point is :
%',astext(startpoint(var_first_linestring));<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
var_start_point :=  addpoint(var_first_linestring, var_source_geom, 0 ); <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
RAISE NOTICE 'New start point is : %',astext(startpoint(var_first_linestring));<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.id       := var_id ;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.gid      := rec_shooting_star.gid;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
final_geom := Collect ( var_first_linestring , geometryN
(rec_shooting_star.the_geom, 2)  );<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
FOR var_i IN 2 .. var_num_geoms<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                           
LOOP<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
final_geom := Collect ( geometryN (rec_shooting_star.the_geom, var_i) ,
geometryN (rec_shooting_star.the_geom, var_i+1) );<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                           
END LOOP;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
rec_path_result.the_geom := final_geom;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                       
RETURN NEXT rec_path_result;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>               
<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
ELSE<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>               
<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.id       := rec_shooting_star.id;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
RAISE NOTICE 'Working on ID : % <><> And stored as
%',rec_shooting_star.id, rec_path_result.id;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.gid      := rec_shooting_star.gid;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.the_geom := rec_shooting_star.the_geom; <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                      
                        
<o:p></o:p></span></p>

<p class=MsoNormal style='margin-left:72.0pt;text-indent:36.0pt'><span
lang=EN-GB>RAISE NOTICE 'New Geometry is : %',astext(final_geom);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
rec_path_result.the_geom := final_geom;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                                               
RETURN NEXT rec_path_result;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
END IF;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>                               
var_id := var_id + 1;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>       
END LOOP;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>Which can be seen better here : <a
href="http://yancho.pastebin.com/fcabc96">http://yancho.pastebin.com/fcabc96</a>
(Syntax highlighted). <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>The problem is it is resulting in this :<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  --CHANGING the Starting
Point--<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  Geometry type working on is :
MULTILINESTRING, and as text : MULTILINESTRING((638719.79994641
229671.605809093,638724.201247709 229706.542025738,638731.190301309
229766.511648145,638736.856451988 229811.628146638,638739.718554099 229843.373135036))<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  Total Number of Geometries :
1<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  Inside the Geometry array
filling<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  Old start point is :
POINT(638719.79994641 229671.605809093)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  New start point is :
POINT(638719.79994641 229671.605809093)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>NOTICE:  New Geometry is :
LINESTRING(638719.79994641 229671.605809093,638724.201247709
229706.542025738,638731.190301309 229766.511648145,638736.856451988
229811.628146638,638739.718554099 229843.373135036)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>So the errors are :<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>1) The new point is not being set<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>2) The result is being given as a
LINESTRING instead of a MULTILINESTRING<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>Problem is there are some MULTILINESTRINGS
which are formed by just 1 LINESTRING but I have also ones which are formed by
more than 1.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>Any idea on how to fix this problem is
extremely appreciated, since I am really not sure what I should change else.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>Thanks and regards<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-GB>Matthew <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p>

<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'>

<hr size=2 width="100%" align=center>

</span></div>

<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>I
am using the free version of SPAMfighter for private users.<br>
It has removed 26496 spam emails to date.<br>
Paying users do not have this message in their emails.<br>
Try <a href="http://www.spamfighter.com/len">SPAMfighter</a> for free now!<o:p></o:p></span></p>

</div>

</body>

</html>