I have polygons (blue) divided by lines (yellow) that are (more or less) parallel to the height contour lines. I want to calculate the height and width (i.e. bounding box) of the blue polygons in direction of the slope, i.e. perpendicular and parallel to the slope (represented by yellow line).
Judging from the name, the tool "oriented minimum bounding rectangle" sounded promising, but the orientation cannot be modified; it is always choosen in a way that minimizes the area of the polygon.
Is there a way to create a bounding box oriented in a specific direction, i.e. parallel to a line?
In below image, you see the "randomly" oriented bounding rectangles in magenta vs. sketched in dark green the result I would like (to ultimately calculate width and height of the polygon).
Best Answer
Credit to @geozelot for the concept
This expression is an implementation of geozelot's comment.
Breakdown of the expression
To clarify, the rotation angle is calculated per polygon, it is not a global value.
Geometry by Expression tool settings
The expression can be used in the Geometry by Expression tool, using the polygon layer as the input layer, and Polygon as the
Output geometry type
.Expression
Result
The red dotted outline is the generated bounding box, the solid blue outline is the oriented bounding box for comparison. The white points are the vertices used to obtain the mean azimuth of the contour segments.