How can I get the length (brown marked part) of the "Road 7" inside the red polygon?
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?
It's necessary to calculate the actual intersection, e.g. http://postgis.net/docs/ST_Intersection.html
SELECT ST_Length(ST_Intersection(line,polygon))
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);