I have linestrings that are each entirely within a polygon. I want to extend the first and last segments to touch the first rings of the polygon in line with them.
[GIS] Extending a linestring to the edge of an enclosing polygon in PostGIS
geometrylinestringpostgis
Related Question
- [GIS] How to calculate the “depth” of a linestring using postgis
- [GIS] Calculating length of just portion of linestring that intersect with polygon using PostGIS
- [GIS] Simplify the straight sections of (multi)Linestring in PostgreSQL/PostGIS leaving the curved sections untouched
- [GIS] PostGIS – Intersects feature to split into linestring
- [GIS] In PostGIS: how to split linestrings into their individual segments
Best Answer
I'm sure it could be prettier but I came up with getting the first and last segments, scaling them about the inner end of the segment so they are as long as the diagonal of the bounding box of the polygon then intersecting with the boundary of the polygon and selecting the points closest to the line endpoints then combining those new points with the existing linestring to give a new linestring.