3

In QGIS, I made some custom SVG symbols for a project I’m working on and I’ve had success using parameters to control fill, stroke, and stroke width. However, I have text in the symbols that I would like to rotate to face straight up no matter what angle the whole symbol is facing.

So far the text object I’ve been working with has a matrix transformation applied to it.

transformation=“matrix(a,b,c,d,e,f)”

I tried applying a second transformation just for the rotation with no luck.

transformation=“matrix(a,b,c,d,e,f)” transformation=“rotate(param(textangle))”

I then tried adding a rotation to the existing transformation

transformation=“matrix(a,b,c,d,e,f) rotate(param(textangle))”

After this, I tried just using the rotate tag, which is supposed to rotate each character in the text independently

transformation=“matrix(a,b,c,d,e,f)” rotate=“param(textangle)”

I also tried adding the rotation to the group consisting of the circle and the text inside it with no luck.

Complex SVG with rotate added to the the  containing the circle and text inside it

I haven’t had a ton of time to play with it beyond that but I’m wondering is this just a limitation in the way that QGIS renders the SVG?

Just to test I made a standalone SVG with only one path and no other transformations to see if I could use a parameter to make it rotate.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="300" height="300" version="1.1" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
  <path fill="param(fill) #ff00ff" stroke="param(outline) #ff00ff" transform="rotate(param(angle)" d="m150 128.31-21.691 43.382h43.382z"/>
</svg>

The original image is a triangle with the point facing up. As you can see in this image I have added the expression with no change to the symbol.

Simple SVG with rotate parameter

4
  • Just to be sure: 1) do you have a non parametrizable SVG that works with matrix + rotation? 2) Have you followed the documentation and added an expression for the parameter? Oct 26, 2023 at 5:44
  • I'm not entirely sure what you mean by number one but I tested it with an SVG consisting of only a single path with no other transformations applied to it with no change in results. I updated the question to reflect this. In regards to number 2, yes I have added an expression for the parameter. I have added screenshots to the question just in case I'm doing something wrong however. Oct 26, 2023 at 10:41
  • Insted of adding the text to the SVG symbol, would using a label be an option?
    – Babel
    Oct 26, 2023 at 10:51
  • I thought about that but I’m not sure how much effort it would be to make sure the label stays in the center of that circle. These symbols are ideally going to be reused for multiple amplifiers in the same configuration so it’s not like I just have to line the label up with the symbol once. There could be 50 amplifiers in this same configuration but in different orientations. Oct 26, 2023 at 11:01

1 Answer 1

4

Found it!

https://github.com/qgis/QGIS/pull/40596/files#diff-a1f1db50aa4de9272401b6ec9b3b258c2273b5811ed205e45593b84f6af29c5bR605 enter image description here

QGIS is actually looking for the whole node. So instead of

transform="rotate(param(angle)"

do

transform="param(rotation)"

and have rotation defined with an expression as 'rotate(30)' or 'rotate('||my_field||')'

I created a modification of the QGIS docs: https://github.com/qgis/QGIS-Documentation/pull/8596

1
  • Using the parameter that way actually seems pretty obvious now that you mention it! I should be able to test it with my project tomorrow. I’ll update with my results. Nov 1, 2023 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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