Is there a possibility to get the centroid of each line?

enter image description here

When using Vector > Analysis Tools > Mean Coordinates I always get a centroid of the whole lines. What I need is the centroid of each line without having to select individual lines.

3 Answers 3


In tool "Mean coordinate(s)" from the QGIS's Processing Toolbox (Ctrl+Alt+T) use Unique "ID" field.

enter image description here

enter image description here


In the Field Calculator, create a new String field and set the length to be something high like 99. Then use the expression:


This should give centroid coordinate values like Point (-4.28930643 55.86506837).

  • @MaFo - Most welcome, glad it was helpful :)
    – Joseph
    Mar 29, 2017 at 11:43

There is a possibility using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

Let's assume there is a polyline layer called 'lines_test2', see image below.


With the following query, it is possible * to get the centroid of each line*.

    st_centroid(geometry) AS geom

The output point layer with its attribute table will look like:


However, keep in mind the difference between Centroid | Midpoint | Center, more details here: Getting the line middle point with SQL in QGIS.


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.