I am using PostGIS and I need to find where linear features (mylines) intersect only the buffer of polygon features (mypoly). I used the following code, which works, but it is taking 13.369 seconds to complete the query. This does not sound like much, but I am using a relatively small dataset and the time will increase dramatically as the dataset gets larger. Is there a way to improve the performance of this query. I have spent a week on this and I just cannot improve the performance. Appreciate any and all help!
SELECT id, clipped_geom
FROM ( SELECT (ST_Intersection((ST_Multi(ST_Difference((ST_Buffer(ST_Transform((ST_MakeValid(a.geom)),26913),50)),ST_Transform(ST_MakeValid(a.geom),26913)))),ST_Transform(mylines.geom,26913))) AS clipped_geom
FROM mypoly AS a
JOIN mylines ON st_intersects(ST_Transform(a.geom,26913),ST_Transform(mylines.geom,26913)))