15

How can I get the length (brown marked part) of the "Road 7" inside the red polygon?

a busy cat

My start:

SELECT ST_Length(way)
FROM lines
WHERE road = "Road 7" AND ST_Intersects(line, polygon)

with that, I get only the total length. Someone has an idea?

2 Answers 2

17

It's necessary to calculate the actual intersection, e.g. http://postgis.net/docs/ST_Intersection.html

SELECT ST_Length(ST_Intersection(line,polygon)) 
1
  • You beat me to it. +1 this should do it. Commented Jun 12, 2012 at 11:26
1

An alternavite method for the mulitpoints in polygon

 SELECT
    sum(ST_LENGTH(ST_Intersection(tr.geom, pd.geom), false)/1000) as km
    FROM roads as tr,
    polygon as pd
    WHERE ST_Intersects(pd.geom, tr.geom);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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