Hi Steve,<br>What indexes can I put on the linestring column? Is there an option of using a R-Tree index?<br><br>Thanks,<br>Ed<br><br><div class="gmail_quote">On Wed, Jun 6, 2012 at 4:54 PM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 6/6/2012 9:57 AM, Ed Linde wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
Simple question. I have a table with half a million linestring<br>
geometries, and I want to compute the<br>
intersection points and also the linestring pairs that intersect with<br>
each other.<br>
How can I do this? Is there an index that can avoid having to do a<br>
self-join and computing<br>
the intersections?<br>
</blockquote>
<br></div></div>
Create a spatial index on your table of linestrings and do a self join<br>
<br>
select a.gid, b.gid, st_intersection(a.the_geom, b.the_geom)<br>
  from linestrings a, linestrings b<br>
 where a.the_geom && b.the_geom and st_intersects(a.the_geom, b.the_geom);<br>
<br>
You might get away with using this instead for the where:<br>
<br>
 where st_dwithin(a.the_geom, b.the_geom, 0.0);<br>
<br>
Which might be faster.<br>
<br>
The result will potentially be a collection if there is more then one intersection and/or might be a linestring if the intersection is an overlap along some part of the two strings.<br>
<br>
-Steve<div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.<u></u>refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.<u></u>net/mailman/listinfo/postgis-<u></u>users</a><br>
</div></div></blockquote></div><br>