Is there a possibility to get the centroid of each line?
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.
Is there a possibility to get the centroid of each line?
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.
In the Field Calculator, create a new String field and set the length to be something high like 99. Then use the expression:
geomToWKT(centroid($geometry))
This should give centroid coordinate values like Point (-4.28930643 55.86506837).
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*.
SELECT
"id",
st_centroid(geometry) AS geom
FROM
"lines_test2"
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.
References: