<div dir="ltr">I think Humbert is right.<div><br></div><div>If you don't use any condition, the query will try to preform <span style="font-family:arial,sans-serif;font-size:13px">ST_Intersection</span> in every possible combination of rows from <span style="font-family:arial,sans-serif;font-size:13px">bacini and </span><span style="font-family:arial,sans-serif;font-size:13px">colture, basicly 327x</span><span style="font-family:arial,sans-serif;font-size:13px">614000 combinations</span><span style="font-family:arial,sans-serif;font-size:13px">.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">I'm not sure if you need both && and the St_intersects() tho.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">If I'm not wrong, && operator check if the boundary boxes of two features interect, but if you are using indexes in both columns St_Intersects will preform the same with the boundaries before doing it with the real geometries.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Alexandre Neto</span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Mar 13, 2014 at 2:42 PM, Humberto Cereser Ibanez <span dir="ltr"><<a href="mailto:humberto@pastoraldacrianca.org.br" target="_blank">humberto@pastoraldacrianca.org.br</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Pietro Rossin,<br>
<br>
<br>
Em Qui, 2014-03-13 ās 06:59 -0700, Pietro Rossin escreveu:<br>
<div class="">> Hi all<br>
> I'm trying to query 2 vector layers;<br>
> b) bacini_elementari that is river basins - 327 elements<br>
> b) particellepac2006 colture parcels - 614000 elements<br>
><br>
> I want to intersect these two layers and get the sum of the area of each<br>
> kind of colture for each river basin.<br>
> To reduce the number of colture vectorial features I made a collect query<br>
> (grouping by kind of colture) and I made a intersection between this<br>
> geometry aggregation and all 327 basins.<br>
><br>
> My query is:<br>
><br>
> SELECT sum(st_area(ST_Intersection(bacini.geom,colture.geom))) as<br>
> areacoltura, codice_bac, nome, codice_cor, colture.descrizione<br>
>   FROM idrologia.bacini_elementari as bacini,<br>
>   (SELECT st_collect(geom) as geom, descrizione<br>
>   FROM varie.particellepac2006<br>
>   group by 2) as colture<br>
>   group by 2,3,4,5<br>
><br>
> it's 5000000ms that the query is running and I don't have any result yet...<br>
><br>
> The two geometry column have an index (but I think it's not used in this<br>
> query)<br>
><br>
</div>my guess is to include && and st_intersects operators as a condition on<br>
your query:<br>
<br>
where bacini.geom && colture.geom and st_intersects(bacini.geom,<br>
colture.geom)<br>
<br>
I have done this on a similar work.<br>
lgsc.geom_buffer_0 && lgp.geom_buffer_0 and<br>
st_intersects(lgsc.geom_buffer_0, lgp.geom_buffer_0)<br>
<br>
<br>
Best regards,<br>
<br>
Humberto Cereser Ibanez<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a></div></div></blockquote></div><br></div>