PostGIS – How to Use ST_ConvexHull() Perpendicular to a Line

postgispostgresql

I have a rather special requirement for a PostGIS geometry manipulation.

Consider the following case:

enter image description here

I have a polygon and a line feature. If I do a ST_ConvexHull() or ST_ConcaveHull() I would get something like on the left side. However, what I need is the area that encloses the polygon and the line where its perpendicular lines touch the polygon. Is there a function or another multiple step way to achieve this in PostGIS?

I think with ST_ShortestLine() from each vertex of the polygon to the line it may be possible. However, I still don't know, how I can get the area from the set of shortest lines.

Best Answer

OK. I figured it out myself. By doing a ST_ShortestLine() on each vertex of the polygon and then a ST_Convexhull() on this set of lines and a final ST_Difference() between that area and the area of the polygon I will get what I need.