Friday 22 December 2017

labeling - Is it possible to write a label expression in qgis that displays the label at a given coordinate?


I am using the QGIS expression builder for the label properties of my data.


Is it possible to put different parts of the label in different coordinates on the map?


For instance I have a linestring and I would like to have "A" displayed in the beginning of the linestring and "B" in the end of it.



Answer



One method is to use Rule-based labelling and adding two rules for "A" and "B".




  1. Go to Layer Properties > Labels and change the option No labels to Rule-based labelling. Then add a rule by clicking the green plus icon:



    Rule-based labelling




  2. Set the relevant options as shown such as Label with (use something 'A') and the Coordinate X Y. For the x-coordinate, click Edit... and use $x_at(0) to place the label at the start of the linestring; for the y-coordinate, use $y_at(0).


    Rule options




  3. Repeat Step 2 for "B" but for the x-y-coordinates, use $x_at(-1) and $y_at(-1) respectively for the end of the linestring.





  4. When you click Apply, hopefully you should see something like this:


    Lines with labels




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...