# Centering polygon on specific coordinates using QGIS

I need to place a set of polygons onto a set of points, so that each polygon is centered on its corresponding point.

How do I do that?

In MapInfo I can just manually edit the coordinates of the center, but there does not seem to be an equivalent in QGIS.

This answer is for QGIS 3.4.

See this answer for earlier versions: Moving vectors to specified coordinates in QGIS?

I was able to do this by creating a centroid for a polygon:

Then moving the polygon feature with the move tool--you can snap to centroid that you just added:

Then move to the target point, again snapping (this answer describes how to configure snapping in QGIS 3: https://gis.stackexchange.com/a/278376/31 .

• Thank you Jay! Had to upgrade to 3.4 (snapping to the centroid didn't work in 2.18), but this solves my problem perfectly.
– Herb
Commented Nov 29, 2018 at 22:29
• Is there any way to do this (moving a polygon from its centroid location to a new location - hopefully lat and long) programmatically or via a data table? Commented Mar 29, 2021 at 0:39
• @Herb - I think you should click the green checkmark next to it to accept this answer.
– PolyGeo
Commented Mar 31, 2021 at 3:19

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):