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.
Asked
Active
Viewed 2,092 times
2
-
I think I asked my question wrong, sorry. I am looking to use the geometry generator in the styles dialog to build polygons from points with attributes for "length" and "width". I can build the polygons using the answer provided in the link but my point file has an additional field called "rotation". I would like to rotate the polygons generated based on the rotation field in the attributes for each feature. – MrKingsley Aug 30 '17 at 18:05
2 Answers
2
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.
2
- 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.
gene
- 54,868
- 3
- 110
- 187
