Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have 2 tables : wgo (lines) and wbn (polygons) With this code, I can display the length of each road inside a polygon. If I have a polygon with 2 roads in it, as a result I get 2 rows with the 2 lengths displayed.

But what I really want, is the total length of roads in the polygon, so I want to SUM them up.. How can this be done ?

SELECT wbn_uidn, wgo_uidn, ST_Length(ST_Intersection(wgo_geom,wbn_geom))
FROM wbn, wgo
WHERE ST_Intersects(wgo_geom,wbn_geom)='t' 
share|improve this question

1 Answer 1

SELECT wbn_uidn, sum(ST_Length(ST_Intersection(wgo_geom,wbn_geom)))
FROM wbn, wgo
WHERE ST_Intersects(wgo_geom,wbn_geom) 
GROUP BY wbn_uidn;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.