# Sum line length with clip intersect? [closed]

SELECT sum(st_length(st_intersection(POLY.geom, LINE.geom))) AS sum_line_length... Is this function OK to calculate the sum of lines length? Wonder if it do the clip line where one line go from one polgon to another or it just sum the line length to polygon from witch the line started? Thanks for answer. Best regards.

• Are you looking for a PostGIS solution? – underdark Feb 19 '13 at 15:06

? if Postgis tag missing?

geometry ST_Intersection( geometry geomA , geometry geomB ); Description Returns a geometry that represents the point set intersection of the Geometries.

boolean ST_Intersects(geom, geom)

```SELECT sum(st_length(LINE.geom))) AS sum_line_length
from LINE as LINE , poly as poly
WHERE poly.id =1 AND ST_Intersects(poly.geom, LINE.geom)
```

That would return sum of all lines which intersect polygon in poly table with id 1

If you want to clip line with polygon and get sum of those lines code would be something like yours. im not sure if st_intersections returns line or point collection containing intersection points

• Yep - not shure too. :-) My Query in Manifold looks like: SELECT [POLYGON].[KO], Round(Sum (Length(ClipIntersect([Water_pipe Table].[ID], [POLYGON].[ID]), "m")),1) AS Length_in_M FROM [Water_pipe Table] INNER JOIN [POLYGON] ON Touches([POLYGON].[ID], [Water_pipe Table].[ID]) Group by [POLYGON].[KO] - it works OK. Now try to test in QGis. – Andrej Feb 19 '13 at 12:09