It's a minimum-oriented bounding box for the LineString geometry contained within it, I generated it using QGIS. Actually, there are many more of these, but let's use this one as an example.
This polygon is part of a georeferenced Shapefile (the CRS is
EPSG:32632, WGS 84/UTM zone 32N), and as WKT it looks like
POLYGON ((505317.38000976015 4344246.695509137, 505316.6889838772 4344247.481812444, 505316.7475176216 4344247.533253576, 505317.43854350504 4344246.746950269, 505317.38000976015 4344246.695509137))
Points are ordered as such: top-left, top-right, bottom-right, bottom-left, top-left (to close the geometry)
I want to pad it on the sides so that I have something like:
where the blue box is ultimately what I want to obtain (it's not a precise drawing of course but I hope it gives a clear enough idea)
So, I tried using shapely's affine transformations of rotation, scaling and skewing, since I also know the angle of rotation of the original green box. Here's my code.
from shapely import affinity def scale_obb(geometry, angle, yfactor, xskew, yskew): rotated_a = affinity.rotate(geometry, -angle) scaled_obb = affinity.scale(rotated_a, yfact=yfactor) rotated_b = affinity.rotate(scaled_obb, angle) skewed_obb = affinity.skew(rotated_b, xs=xskew, ys=yskew)
angle here is exactly
yskew are variables. The idea is to rotate the polygon such that it is horizontal, then scale it on the y-axis, then rotate it back and if needed, correct the skewness. However, for example using a
yfactor = 3,
xskew = -13, and
yskew = 0, I get:
which is kind of close to what I want, but not quite. How can I straighten this blue box to look sort of like the rectangle I want? I have tinkered a bit with
yskew but haven't found the right values so far. Maybe I need different transformations?