Birgit,<div><br></div><div>Thanks for the reply. After reading my initial question, I think I could have been clearer. I'm not looking simply for an intersection, I'm trying to find a linestring that's contained within another linestring. For example, if I drive a mile in my car that would be r1. Then I have several shorter distances in s1, I want to find the shorter distances that are along the same linestring as r1. That's why I'm using the buffer, just to add a bit of fuzziness since I don't expect the exact points within all the linestrings to be the same. </div>
<div><br></div><div>With some further experimentation, I've discovered the big bottleneck appears to be the ST_Buffer call (it gets executed in a nested loop once a larger data set is involved). I've written a stored procedure that computes the ST_Buffer geometry once and stores it in a variable. With this approach, performance is much better. </div>
<div><br></div><div>Hopefully this makes the explanation of what I'm trying to accomplish a bit clearer, but I think I have a workable solution. If there's a better way, I'd definitely be interested in hearing it.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>--</div><div>Adam<br><br><div class="gmail_quote">On Mon, Feb 6, 2012 at 4:39 AM, Birgit Laggner <span dir="ltr"><<a href="mailto:birgit.laggner@vti.bund.de">birgit.laggner@vti.bund.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Hi Adam,<br>
    <br>
    why do you calculate a buffer for the first linestring? If you only
    want to know if there is any overlapping part of the two
    linestrings, I would expect that
    ST_Intersects(r1.geo_data,s1.geo_data) would do the job best. You
    could combine it with
    ST_Geometrytype(ST_Intersection(r1.geo_data,s1.geo_data))='ST_LineString'
    in order to to find out if they only cross or really overlap.<br>
    <br>
    Hope that helps,<br>
    <br>
    Birgit.<br>
    <br>
    <br>
    Am 03.02.2012 21:07, schrieb Adam McManus:
    <blockquote type="cite"><div><div class="h5">I'm looking for the fastest way to detect whether a
      given linestring overlaps another linestring. Here's my current
      approach.
      <div><br>
      </div>
      <div>Given two tables: r1 and s1, both containing a geo_data
        column of linestring, first narrow the data (taking advantage of
        gist index) with r1.geo_data && s1.geo_data, then use
        ST_Contains to see if s1 is overlapping r1, i.e. r1.geo_data
        && s1.geo_data
and ST_Contains(ST_Buffer(r1.geo_data,ST_Length(r1.geo_data)*.002),s1.geo_data)</div>
      <div><br>
      </div>
      <div>This approach works, but it's extremely CPU-intensive and
        slow. Is there a better approach?</div>
      <div><br>
      </div>
      <div>Thanks,</div>
      <div><br>
      </div>
      <div>--</div>
      <div>Adam McManus</div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
postgis-users mailing list
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a>
</pre>
    </blockquote>
  </div>

<br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br></div>