• Skip to primary navigation
  • Skip to main content

North River Geographic Systems Inc

Spatial Problem Solving

  • Home
  • About NRGS
  • Blog
  • Resources
    • Guides for using TN Data with QGIS
    • QGIS Resources
    • Tutorials
  • Services
    • Support
    • NRGS Geo Suite
    • Tennessee NG911 Server
    • Data Analysis
    • Training
  • Portfolio
  • Show Search
Hide Search
You are here: Home / GIS / QGIS Leader Lines for Labels

QGIS Leader Lines for Labels

rjhale · May 7, 2019 ·

So way back when…..I was working in a production map shop and I had to make a map of a Nuclear Plant. The fun part being it was all manual. So we would use a lettering machine to place the labels and legend on the enlarged photo. We would manually trace all the features on an overlay.

Flash forward and we’re using ArcINFO and placing annotation and then drawing leader lines pointing to the features on an OrthoPhoto.

Last week and I had the chance to do something I don’t normally get to do: make a cartographic map in QGIS. I needed to make leader/callout lines from the labels back to the polygons. I didn’t want to manually draw in leader lines. Searching led me to two posts:

  • https://kartoza.com/en/blog/how-to-make-beautiful-lollipop-call-out-labels-in-qgis/
  • https://gist.github.com/kgjenkins/1af82a8ffdc3c99bb886e6cd9cdc298f

I ended up running with the kartoza example although both helped me understand how to get this working. So for the not too faint of heart……Here goes. I have some polygons on which I need to “cleanup labels” and leader lines would help in that regard. I could pull the labels away from the very small polygons I have and attach them back with a line.

The key to all of this ais Geometry Generators. The basics are you can use code and expressions in QGIS to draw Geometry. So I’m going to draw leader lines from my label to my polygon with some code (that I copied from Kartoza’s example – Hey to Kartoza). My data is Categorized. So I’m starting off with this:

So I’m going to click on Conservation Easement and add a symbol. The symbol will be a geometry generator. Just as a little background – I’m stacking symbology. So I’m adding another symbol to my yellow symbol by using the plus button on the symbol selector. I’m defining the type as a Geometry Generator and the Geometry Type as a line.

 

So what happens with the code I so skillfully pasted into the symbol selector?

make_line(
closest_point($geometry,
make_point( “auxiliary_storage_labeling_positionx” , “auxiliary_storage_labeling_positiony” )),
make_point( “auxiliary_storage_labeling_positionx” , “auxiliary_storage_labeling_positiony” )
)

The code says make a line using the closest point on the polygon and anchor it with the location of the label. Now something happens when I use the label toolbar to move my labels away from the polygons:

Now I have leader or callout lines back to my polygon. I’ll need to add a geometry generator to each category to give me lines for every category. The picky side of me is thinking for 100% control I should manually draw them in (but I’m not). If you read Kartoza’s post they have a more elegant final solution to deal with lines running over your labels. Looking at this now I need to move 210 back to the center of it’s polygon since it’s drawing the leader line under the polygon.Overall – Not bad.

 

Share this:

  • Email
  • Print
  • Twitter
  • Facebook
  • Pocket
  • Tumblr
  • LinkedIn
  • Reddit
  • Pinterest
  • WhatsApp

GIS Cartography, QGIS

Reader Interactions

Comments

  1. Springfield Harrison says

    May 14, 2019 at 8:30 pm

    Excellent tip, Randal. But you still have to move the labels?

    What if they are offset with the various placement/rendering options?
    Thanks again . . .

    • rjhale says

      May 15, 2019 at 10:32 am

      I think if they were offset you’d be fine – but I had no clue how these needed to move so I did it all manually.

Trackbacks

  1. @QGIS Leader Lines for Labels – GeoNe.ws says:
    May 9, 2019 at 12:25 pm

    […] https://www.northrivergeographic.com/archives/qgis-leader-lines-for-labels […]

Contact

  • (423) 653-3611
  • info@northrivergeographic.com

Copyright © 2019 · Monochrome Pro on Genesis Framework · WordPress · Log in

  • Home
  • About NRGS
  • Blog
  • Resources
  • Services
  • Portfolio
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.