This topic goes into making polygons based on point locations; Using QGIS Geometry Generator to get rectangle from point? Is there a way to apply a rotation to the geometry generated? I have a field that contains a 0-360 degree rotation value and would like to rotate my built geometries based on that value.
I would suggest using shapely which is provided as a python package. You would interested in the rotate function:
shapely.affinity.rotate(geom, angle, origin='center', use_radians=False)¶ Returns a rotated geometry on a 2D plane. The angle of rotation can be specified in either degrees (default) or radians by setting use_radians=True. Positive angles are counter-clockwise and negative are clockwise rotations. The point of origin can be a keyword ‘center’ for the bounding box center (default), ‘centroid’ for the geometry’s centroid, a Point object or a coordinate tuple (x0, y0). The affine transformation matrix for 2D rotation is: / cos(r) -sin(r) xoff | sin(r) cos(r) yoff | 0 0 1 / where the offsets are calculated from the origin Point(x0, y0)
This thread provides an example possible setup
Also, this is a C++ solution you can check out as well.
- if you don't know Python, you can directly use the Affine Transformations or the Vector Transformation plugins (and others as Scaling and rotating vector layers in qgis using qgsAffine for example)
- if you know Python, before using Shapely, you can use the
rotatefunction of a QgsGeometry in PyQGIS (Rotación de archivos vectoriales con método ‘rotate’ de QgsGeometry en PyQGIS, in Spanish but the scripts are universal) or the Affine Python module.