6

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.

0
7

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: enter image description here

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

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 .

enter image description here

3
  • 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 Nov 29 '18 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? – bdelliott Mar 29 at 0:39
  • @Herb - I think you should click the green checkmark next to it to accept this answer. – PolyGeo Mar 31 at 3:19
2

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.