You can use QGIS expressions with Geometry generator or Geometry by expression (see here for details on these two options) to automatically shift your polygons.
Let's assume you have several polygons that should be shifted the a set of points. You need to have a common attribute to associate a point to each polygon - in my case it's the field id, which contain a common, unique value on both layers.
Use the following expression - it shifts (translate
) each polygon ($geometry
) in a certain distance in x and y direction. The value for the shift in x/y direction is calclulated as follows: get the x
/y
value of each point (the geometry of the layer named points
: geometry (get_feature_by_id ('points', [n]))
) with the same id as the current polygon (thus repleace [n]
from before with $id
). From this x
/y
value subtract the x
/y
value of the current polygon's centroid (centroid ($geometry)
) - all together:
translate(
$geometry,
x(
geometry (
get_feature_by_id (
'points',
$id
)
)
)-
x (centroid ($geometry)),
y(
geometry (
get_feature_by_id (
'points',
$id
)
)
)-
y (centroid ($geometry))
)
Screenshot: orange=original polygons, white dots= points where the shifted polygons should be centered; blue=polygons shifted with the expression from above (using geometry generator):
