[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] Extend linestring to snap to polygon
From:       Nicolas Ribot <nicolas.ribot () gmail ! com>
Date:       2018-10-15 8:03:16
Message-ID: CAGAwT=0HY+UNZOg29-UKnE6m4S12k2U7fZzCU=f7VHbek9S9Uw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/related)]

[Attachment #4 (multipart/alternative)]


(Line extension here is based on the shortest distance between line and
polygon. To extend in the direction on line segments, you can refer to this
list, message "Finding closet intersect point along direction of line",
april 10 2013)

Nicolas

On Mon, 15 Oct 2018 at 09:58, Nicolas Ribot <nicolas.ribot@gmail.com> wrote:

> Hi,
> 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:
>
> with pg as (
>   select 'POLYGON((0 0, 5 0, 3 5, 0 0))'::geometry as geom
> ), line as (
>      select 'LINESTRING(1 1, 2 1, 3.5 2)'::geometry as geom
> ) select st_addPoint(st_addPoint(
>            line.geom,
>            st_lineinterpolatepoint(
>              st_boundary(pg.geom),
>              st_lineLocatePoint(st_boundary(pg.geom), st_startpoint(line.geom))),
>            0),
>           st_lineinterpolatepoint(
>              st_boundary(pg.geom),
>              st_lineLocatePoint(st_boundary(pg.geom), st_endpoint(line.geom))),
>           st_numpoints(line.geom) + 1)
> from pg, line;
>
> (a smarter way must exist, but linear referencing function are quite
> efficient to find/build points)
>
> Nicolas
>
> [image: Screen Shot 2018-10-15 at 09.56.22.png]
>
> On Mon, 15 Oct 2018 at 08:25, Shane Carey <careyshan@gmail.com> wrote:
>
>> Hi there,
>>
>> Is there a way to extend a linestring on both sides until it reaches a
>> polygon.
>>
>> Thanks.
>> --
>> Le gach dea ghui,
>> *Shane Carey*
>> *GIS and Data Solutions Consultant*
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
>

[Attachment #7 (text/html)]

<div dir="ltr"><div dir="ltr">(Line extension here is based on the shortest distance \
between line and polygon. To extend in the direction on line segments, you can refer \
to this list, message &quot;Finding closet intersect point along direction of \
line&quot;, april 10 2013)</div><div \
dir="ltr"><br></div><div>Nicolas</div></div><br><div class="gmail_quote"><div \
dir="ltr">On Mon, 15 Oct 2018 at 09:58, Nicolas Ribot &lt;<a \
href="mailto:nicolas.ribot@gmail.com" target="_blank">nicolas.ribot@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><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&#39;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)">&#39;POLYGON((0 0, 5 0, 3 5, 0 0))&#39;</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)">&#39;LINESTRING(1 1, 2 1, 3.5 2)&#39;</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 &lt;<a \
href="mailto:careyshan@gmail.com" target="_blank">careyshan@gmail.com</a>&gt; \
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_-5325788529774971783m_2226319509150395856m_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>
 </blockquote></div>


["Screen Shot 2018-10-15 at 09.56.22.png" (image/png)]
[Attachment #9 (text/plain)]

_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic