<div dir="ltr">Hi,<div>you can extract the exterior of the polygon (st_boundary),  use linear referencing function st_lineLocatePoint to find the projection of line's start and end points then add the points to the line:</div><div><br></div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:Consolas"><font size="1"><span style="color:rgb(204,120,50);font-weight:bold">with </span>pg <span style="color:rgb(204,120,50);font-weight:bold">as </span>(<br>  <span style="color:rgb(204,120,50);font-weight:bold">select </span><span style="color:rgb(106,135,89)">'POLYGON((0 0, 5 0, 3 5, 0 0))'</span>::<span style="color:rgb(204,120,50);font-weight:bold">geometry as </span>geom<br>)<span style="color:rgb(204,120,50)">, </span>line <span style="color:rgb(204,120,50);font-weight:bold">as </span>(<br>     <span style="color:rgb(204,120,50);font-weight:bold">select </span><span style="color:rgb(106,135,89)">'LINESTRING(1 1, 2 1, 3.5 2)'</span>::<span style="color:rgb(204,120,50);font-weight:bold">geometry as </span>geom<br>) <span style="color:rgb(204,120,50);font-weight:bold">select </span><span style="color:rgb(255,198,109);font-style:italic">st_addPoint</span>(<span style="color:rgb(255,198,109);font-style:italic">st_addPoint</span>(<br>           line.geom<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">           </span><span style="color:rgb(255,198,109);font-style:italic">st_lineinterpolatepoint</span>(<br>             <span style="color:rgb(255,198,109);font-style:italic">st_boundary</span>(pg.geom)<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">             </span><span style="color:rgb(255,198,109);font-style:italic">st_lineLocatePoint</span>(<span style="color:rgb(255,198,109);font-style:italic">st_boundary</span>(pg.geom)<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(255,198,109);font-style:italic">st_startpoint</span>(line.geom)))<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">           </span><span style="color:rgb(104,151,187)">0</span>)<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">          </span><span style="color:rgb(255,198,109);font-style:italic">st_lineinterpolatepoint</span>(<br>             <span style="color:rgb(255,198,109);font-style:italic">st_boundary</span>(pg.geom)<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">             </span><span style="color:rgb(255,198,109);font-style:italic">st_lineLocatePoint</span>(<span style="color:rgb(255,198,109);font-style:italic">st_boundary</span>(pg.geom)<span style="color:rgb(204,120,50)">, </span><span style="color:rgb(255,198,109);font-style:italic">st_endpoint</span>(line.geom)))<span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">          </span><span style="color:rgb(255,198,109);font-style:italic">st_numpoints</span>(line.geom) + <span style="color:rgb(104,151,187)">1</span>)<br><span style="color:rgb(204,120,50);font-weight:bold">from </span>pg<span style="color:rgb(204,120,50)">, </span>line<span style="color:rgb(204,120,50)">;</span></font></pre></div><div>(a smarter way must exist, but linear referencing function are quite efficient to find/build points)</div><div><br></div><div>Nicolas</div><div><br></div><div><img src="cid:ii_jna090xk0" alt="Screen Shot 2018-10-15 at 09.56.22.png" width="173" height="161" style="margin-right: 0px;"><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 15 Oct 2018 at 08:25, Shane Carey <<a href="mailto:careyshan@gmail.com">careyshan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Hi there,</div><div dir="auto"><br></div><div dir="auto">Is there a way to extend a linestring on both sides until it reaches a polygon. </div><div dir="auto"><br></div><div dir="auto">Thanks. </div><div dir="ltr">-- <br></div><div class="m_2413956620965797705gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Le gach dea ghui,<br></div><div><span style="color:rgb(61,133,198)"><b><span style="background-color:rgb(255,255,255)"><i>Shane Carey</i></span></b></span></div><div><span style="color:rgb(61,133,198)"><b><span style="background-color:rgb(255,255,255)"><i>GIS and Data Solutions Consultant</i></span></b></span><br></div></div></div></div></div></div></div>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></blockquote></div>