You polygons must have a unique identifier in the attributes, in my case the field named fid
. I also presume the line layer has the name line
. If you have other names, change it in the following expressions accordingly.
Be aware: the expression overlay_nearest
is available since QGIS 3.16, see visual changelog. For older versions, use the refFunctions plugin instead.
For every vertex of the polygon layer, find the nearest point on the line layer using this expression with Menu Processing / Toolbox / Gemonetry by expression
, set the vertices as input and output geometry type as points: closest_point (array_first (overlay_nearest( 'line', $geometry)), $geometry)
. As output, you get the red dots (see screenshot).
Select all features from the vertices layer, copy and paste them to the point layer changed_geometries
- the output from step 1 (red dots).
Run Menu Processing / Toolbox / Minimum bounding geometry
set changed_geometries
(output from step 2) as Input layer
and select fid
as Field (optional, set if features should be grouped by class)
. As geometry type
, select Minimum Oriented Rectangle
. If you run the tool, you get the blue polygons as output:
Variants:
You can use the point layer output from step 1 (skip step 2/copying vertices), than in step 3 select Convex hull
instead of Minimum Oriented Rectangle
, see result:
And this is the output you get including step 2, but selecting Convex hull
in step 3: