After using sum line lengths, is there an automated way to update the resulting polygon layer when more lines are added without needing to delete the layer and re-run the sum line lengths algorithm?
Following snaileater's answer, this is a
Virtual Layer syntax to mimic
Sum line lengths assuming:
- the polygon layer name is
Polygonand it has unique
- the line layer name is
Line to your actual layer names.
SELECT Polygon.id AS id, Round(Sum(st_length(st_intersection(Line.geometry, Polygon.geometry))), 5) AS LENGTH, Count(st_intersection(Line.geometry, Polygon.geometry)) AS COUNT, Polygon.geometry AS geometry FROM Line INNER JOIN polygon ON st_intersects(Line.geometry, Polygon.geometry) GROUP BY Polygon.id ORDER BY Polygon.id
However, I would recommend to stick to
Sum line lengths tool, if you have already started building your database with this tool. You will never be satisfied with their consistency (including accuracy and repeatability), if you mix tools for length/area measurements.
This is how it looks when your layer name / field name fit into. Also please avoid name starting with numbers (e.g,
SELECT County.Cnty_NM AS id, Round(Sum(st_length(st_intersection(161kv.geometry, County.geometry))), 5) AS LENGTH, Count(st_intersection(161kv.geometry, County.geometry)) AS COUNT, County.geometry AS geometry FROM 161kv INNER JOIN County ON st_intersects(161kv.geometry, County.geometry) GROUP BY County.Cnty_NM ORDER BY County.Cnty_NM