Hack to adjust map symbols location in QGIS

EN | PT

Now and then I get too many map symbols (points) in the same place, and I thought how nice it would be if we could drag n’ drop them around without messing with their geometries position, just like we do with labels. That thought gave me an idea for a cool hack.

Choose your point layer and start by creating two new fields called symbX and symbY (Type: Decimal number; Size: 20; Precision: 5). Now go the layer properties and in the Style tab edit your symbol. For each level of your symbol select “map units” as the offset units, and set the following expression in the offset data define properties option:


CASE WHEN symbX IS NOT NULL AND symbY IS NOT NULL THEN
    tostring($x - symbX) + ',' + tostring($y - symbY)
ELSE
    '0,0'
END

Screenshot from 2015-02-22 18:18:43

Be aware that, if your coordinates have negative values, you need to adapt the code. E.g., If you have negative values in X you should use “tostring(symbX -$x)” instead.

Now, temporarly  label your layer with a small convenient text (I used a centered ‘+’ (plus sign) with a white buffer) and set its coordinates to data defined using the symbX and symbY Fields.

Screenshot from 2015-02-22 22:42:07

From this point on, when you use the move label tool, not only the label position change but also the actual symbol! Pretty cool, isn’t it?

anim

Notice that the features geometries are not changed during the process. Also, remember that in this case you can also add leading lines to connect the symbols to the original position of the points.

5 thoughts on “Hack to adjust map symbols location in QGIS

  1. What a great hack, thanks!
    I am facing an issue, maybe you may help?
    When including the map in a composer whith an angle, the X and Y placement are wrong (I suppose because of the lack of coincidence between lat/long and angle in degrees). Do you think that it would be possible to include the angle in your function?
    Thanks again!
    CS

    Like

  2. Bravo!!!! what a good remedy! It’s great. Thank you so much for sharing it.
    To perfect it, I would like to contribute a grain of sand. Since when moving the + the symbol does not stay centered with it. For the symbol to be perfectly centered with the small cross +, add to Allignment Horizontal-> ‘Center’ and Allignment Vertical-> ‘Half’

    Like

Leave a comment