6

In Geometry Generator in Symbology in Layer Properties, the following expression works, but the result is not satisfactory due to the middle point fixed coefficient 1,1:

make_line (
     start_point(make_point("Origin Longitude", "Origin Latitude")), 
     translate(centroid($geometry), 1, 1), 
     end_point(make_point("Dest Longitude", "Dest Latitude")))

Using the $length function as below doesn't work. Why no lines are displayed?

make_line (
     start_point(make_point("Origin Longitude", "Origin Latitude")), 
     translate(centroid($geometry), $length, $length),
     end_point(make_point("Dest Longitude", "Dest Latitude")))

Using the length() function as below works, but while some lines are displayed OK (e.g. India -> Bangladesh), some are way too curvy (e.g. Bangladesh -> India). How can I make all of them just slightly curved like the India -> Bangladesh one?

make_line(
     start_point(make_point("Origin Longitude", "Origin Latitude")), 
     translate(centroid($geometry), 
     length(
           make_line(
                make_point("Origin Longitude", "Origin Latitude"), 
                make_point("Dest Longitude", "Dest Latitude")
           )
     )/5000000,
     length((
           make_line(
                make_point ("Origin Longitude", "Origin Latitude"), 
                make_point("Dest Longitude", "Dest Latitude")
                )
     ))/5000000), 
     end_point(make_point("Dest Longitude", "Dest Latitude"))
)

QGIS version: 3.4.6

example

1
  • A manual work around would be to adjust them using node select. I use that approach to do flow maps....and applaud you for having a solution which gets most of the lines curved programmatically! Sep 25 '19 at 8:03
3

You can use this expression, details in comments :

-- create a start point variable
with_variable(
    'start_point', -- name
    make_point("Origin Longitude", "Origin Latitude"), -- expression for start point

-- create an end point variable
with_variable(
    'end_point', -- name
    make_point("Dest Longitude", "Dest Latitude"), -- expression for end point

-- create a base line (start to end) variable
with_variable(
    'base_line', -- name
    make_line(
        @start_point, -- call start point variable
        @end_point -- call end point variable
    ), -- expression for base line

    -- expression for create the arrow
    -- create a line with 3 points : start point, offset centroid and end point
    make_line(
        @start_point,
        centroid(
            offset_curve(
                @base_line,
                -- 10 is curve coefficient, adjust-it
                -- a bigger number (e.g. 15) flatten the curve
                -- a lower number (e.g. 5) round the curve
                length(@base_line) / 10
            )
        ),
        @end_point
    )
)))

Go to the layer properties > symbology > choose the Geometry Generator for symbol type > choose Polyline / Multi-Polyline as Geometry Type and paste the code above.

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.