2

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.

whyzar
  • 12,053
  • 23
  • 38
  • 72
MrKingsley
  • 1,443
  • 13
  • 26
  • 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 Answers2

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.

gene
  • 54,868
  • 3
  • 110
  • 187
whyzar
  • 12,053
  • 23
  • 38
  • 72
2

enter image description here

gene
  • 54,868
  • 3
  • 110
  • 187