Re: [postgis-users] Length of a line above polygon

2012-07-03 Thread Denis Rouzaud
Messages crossed, but seems we agree ;) On 07/04/2012 08:51 AM, Matej Mailing wrote: I think I have just found it out. I just add ST_Intersection to have a query like: SELECT areas.id, SUM( ST_Length( ST_Intersection(lines.geometry, areas.geometry) ) ) FROM lines,areas WHERE ST_Intersects(line

Re: [postgis-users] Length of a line above polygon

2012-07-03 Thread Denis Rouzaud
Yes, you're right. This should solve this problem: SELECT areas.id, SUM( ST_Length( ST_Intersection( lines.geometry , areas.geometry ) ) ) FROM lines,areas GROUP BY areas.id ; ST_intersects returns true if there is an intersection and ST_Intersection returns the share geometry. Greetings,

Re: [postgis-users] Length of a line above polygon

2012-07-03 Thread Matej Mailing
I think I have just found it out. I just add ST_Intersection to have a query like: SELECT areas.id, SUM( ST_Length( ST_Intersection(lines.geometry, areas.geometry) ) ) FROM lines,areas WHERE ST_Intersects(lines.geometry,areas.geometry) GROUP BY areas.id ; Now the numbers seem to be correct :-) Hop

Re: [postgis-users] Length of a line above polygon

2012-07-03 Thread Matej Mailing
Hi, Thank you for the answer. However, I don't get the right result. For example, when there is a line that is long 500 meters and it crosses 5 polygons (on each of them maybe just a meter or few meters, except one where lies a majority of the line), I get the full length of the lines for correspo

Re: [postgis-users] Length of a line above polygon

2012-07-03 Thread Denis Rouzaud
Hi, You can use something like SELECT areas.id, SUM( ST_Length( lines.geometry) ) FROM lines,areas WHERE ST_Intersects(lines.geometry,areas.geometry) GROUP BY areas.id ; Greetings, Denis On 07/03/2012 01:36 PM, Matej Mailing wrote: Hi all, We have a layer that contains polygons and anothe

[postgis-users] Length of a line above polygon

2012-07-03 Thread Matej Mailing
Hi all, We have a layer that contains polygons and another that contains lines that lie on them. Parts of the lines are laying "inside" the polygons and I would like to get a sum of all the lengths of lines that lie on the polygons. What is the easiest way to achieve this? TIA, Matej