[GIS] Using QGIS Geometry Generator to get rectangle from point

geometry-generatorqgis

I would like to translate a point (from a point layer) to a rectangle polygon using the new Geometry Generator from QGIS 2.14.

I know the length and the height of the resulting rectangle. The point should be the centroid.

enter image description here

Best Answer

While you can't do maths inside the WKT representation - you can use geom_from_wkt to turn a text string with maths in it back into a geometry. Something like:

geom_from_wkt( 
'POLYGON(('|| 
(x( centroid( $geometry) ) + 0.5)||' '||(y( centroid( $geometry) ) + 0.5)||','||
(x( centroid( $geometry) ) + 0.5)||' '||(y( centroid( $geometry) ) - 0.5)||','||
(x( centroid( $geometry) ) - 0.5)||' '||(y( centroid( $geometry) ) - 0.5)||','||
(x( centroid( $geometry) ) - 0.5)||' '||(y( centroid( $geometry) ) + 0.5)||','||
(x( centroid( $geometry) ) + 0.5)||' '||(y( centroid( $geometry) ) + 0.5)||','||
'))')
Related Question