Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.