Labels with leaders in QGIS












2















I used the following link to create labels with leaders, but since I have a polyline layer I used a different expression for the Geometry Generator:



make_line(
centroid($geometry),
make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony")
)


It appears to work, but looks quite ugly, where some of the leaders go past the geometry centroid as follows:



Example_1



And others fail to reach it:



Example_2



Why does this occur and how can I fix it?










share|improve this question





























    2















    I used the following link to create labels with leaders, but since I have a polyline layer I used a different expression for the Geometry Generator:



    make_line(
    centroid($geometry),
    make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony")
    )


    It appears to work, but looks quite ugly, where some of the leaders go past the geometry centroid as follows:



    Example_1



    And others fail to reach it:



    Example_2



    Why does this occur and how can I fix it?










    share|improve this question



























      2












      2








      2








      I used the following link to create labels with leaders, but since I have a polyline layer I used a different expression for the Geometry Generator:



      make_line(
      centroid($geometry),
      make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony")
      )


      It appears to work, but looks quite ugly, where some of the leaders go past the geometry centroid as follows:



      Example_1



      And others fail to reach it:



      Example_2



      Why does this occur and how can I fix it?










      share|improve this question
















      I used the following link to create labels with leaders, but since I have a polyline layer I used a different expression for the Geometry Generator:



      make_line(
      centroid($geometry),
      make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony")
      )


      It appears to work, but looks quite ugly, where some of the leaders go past the geometry centroid as follows:



      Example_1



      And others fail to reach it:



      Example_2



      Why does this occur and how can I fix it?







      qgis labeling






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 12 hours ago









      Taras

      2,0702624




      2,0702624










      asked 12 hours ago









      user32882user32882

      1,10611127




      1,10611127






















          1 Answer
          1






          active

          oldest

          votes


















          3














          The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.



          You could use the middle of the line instead.






          share|improve this answer
























          • What is the expression to get the middle of the line?

            – user32882
            12 hours ago






          • 1





            @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

            – Taras
            12 hours ago








          • 2





            Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

            – user32882
            12 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312607%2flabels-with-leaders-in-qgis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.



          You could use the middle of the line instead.






          share|improve this answer
























          • What is the expression to get the middle of the line?

            – user32882
            12 hours ago






          • 1





            @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

            – Taras
            12 hours ago








          • 2





            Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

            – user32882
            12 hours ago
















          3














          The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.



          You could use the middle of the line instead.






          share|improve this answer
























          • What is the expression to get the middle of the line?

            – user32882
            12 hours ago






          • 1





            @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

            – Taras
            12 hours ago








          • 2





            Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

            – user32882
            12 hours ago














          3












          3








          3







          The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.



          You could use the middle of the line instead.






          share|improve this answer













          The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.



          You could use the middle of the line instead.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 hours ago









          ErikErik

          3,223322




          3,223322













          • What is the expression to get the middle of the line?

            – user32882
            12 hours ago






          • 1





            @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

            – Taras
            12 hours ago








          • 2





            Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

            – user32882
            12 hours ago



















          • What is the expression to get the middle of the line?

            – user32882
            12 hours ago






          • 1





            @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

            – Taras
            12 hours ago








          • 2





            Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

            – user32882
            12 hours ago

















          What is the expression to get the middle of the line?

          – user32882
          12 hours ago





          What is the expression to get the middle of the line?

          – user32882
          12 hours ago




          1




          1





          @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

          – Taras
          12 hours ago







          @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.

          – Taras
          12 hours ago






          2




          2





          Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

          – user32882
          12 hours ago





          Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )

          – user32882
          12 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312607%2flabels-with-leaders-in-qgis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Magento 2 controller redirect on button click in phtml file

          Polycentropodidae