7

I use the "Offset Point Symbol" tool and a geometry generator symbology to create dynamic leader lines. A sample file is available at http://hub.qgis.org/issues/15201 (Add snapping for 'Offset Point Symbol' tool).

Because I need a circle symbology without fill in some projects, I want to shorten the leader lines by the radius of the cirle symbology.

enter image description here

Can anyone help me with the expression? Symbology units are in meter ('Map units').

make_line (
make_point(
$x + regexp_substr("offset", '([^,]*)'),
$y - regexp_substr("offset", '([^,]*$)')
),
$geometry
)

Based on the answer posted by underdark I've created an expression that works properly:

-- radius = 2m

difference(
    make_line (
        make_point(
            $x + regexp_substr("offset", '([^,]*)'),
            $y - regexp_substr("offset", '([^,]*$)')
        ),
        $geometry
    ),
    buffer(make_point(
            $x + regexp_substr("offset", '([^,]*)'),
            $y - regexp_substr("offset", '([^,]*$)')
        ), 2)
  ) 
7

Your requirements seem to be similar to the requirements I had for a flow map a while ago. To shorten the lines at the start and at the end, I used geometric difference functions as shown here:

difference(
  difference(
    $geometry,
    buffer( start_point($geometry), 10000 )
  ),
  buffer( end_point( $geometry), 10000 )
)

enter image description here

3

What you need to do is find the ratio of the diagonal you need vs the one you have. You're essentially finding a similar right triangle to the one you already have so if the diagonal needs to be 78% shorter, you can multiply your x and y by 78%.

Note this diagram (sorry for hand drawn, on my phone)

enter image description here

So for x offset you need something like:

(sqrt("x offset"^2 + "y offset"^2) - "radius")
/sqrt("x offset"^2 + "y offset"^2) * x

You'll need to know the radius of the circle in meters. If it's set to 'map units' for its radius that's easy, if it's set to mm you'll need to multiply by your scale (convert mm to meters)

So if your circle is 5mm radius you could do something like 0.005 * @map_scale

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.