I'm looking to create a line from centroid of a circle and label it with the radius using the geometry generator but don't know where to start. QGIS 2.18.15. I'm using the Ovals, Rectangles plugin to draw the circle.
-
Just FYI, I ran across this warning when searching for info on this plugin: "Be wary... That plugin has known issues and will cause your QGIS to get slower and slower over time." – ndawson– cskCommented May 15, 2018 at 18:05
-
You can also create circles by buffering a point layer, if you want to avoid any issues this plugin may cause.– cskCommented May 15, 2018 at 18:06
1 Answer
Draw line from centroid to edge
Add a symbol layer to the polygon layer style.
Style the new symbol layer as Geometry Generator type (line), with this expression:
make_line( centroid( $geometry), end_point( $geometry))
Label the line with the circle's radius
Label the layer with this expression:
distance( centroid( $geometry), end_point( $geometry))
Adjust label placement to suit your preference. Show here with
- placement: offset from centroid
- quadrant: upper right
More labeling tips:
use the round() function to reduce the number of decimal places
round(distance( centroid( $geometry), end_point( $geometry)),2)
add units using the concatenate symbol ||
distance( centroid( $geometry), end_point( $geometry)) || ' meters'