<div dir="ltr"><div>Hi Paul,</div><div><br></div><div>Thank you for the swift response and sorry for the late reply. </div><div><br></div><div>I have tested your solution, but it does hit all the polygons contained inside P as well, which I want to avoid (because it takes _a lot_ of time).<br></div><div><br></div><div>My apologies since my description was very brief and didn't give a good description of what I want to achieve. I'll try again below :)</div><div><br></div><div>What I have had most success with so far is the following (envelope is an indexed geometry column):<br></div><div><br>SELECT ... FROM ST_DumpSegments(ST_Boundary(geom)) AS x(path, geom) JOIN ... ON (envelope && geom AND ST_Intersects(envelope, geom))</div><div><br></div><div>For some reason, I need the envelope && geom AND before ST_Intersects - for the query to complete quickly.<br></div><div><br></div><div>I do think it could go faster if I didn't need to split the ring-linestring into every segment, but perhaps provide (max) number of vertices in each segment/linestring or if postgis could help  me split the ring into an appropriate number of segments (minimizing the resulting bboxes and number of segments).<br></div><div><br></div><div>Ideally, the query would find polygons crossing the inner rings as well.</div><div><br></div><div>Mats<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 5, 2023 at 11:33 PM Paul Ramsey <<a href="mailto:pramsey@cleverelephant.ca">pramsey@cleverelephant.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Sort of ugly but…<div><br></div><div>CREATE TEMPORARY TABLE p_edges AS</div><div>  SELECT <a href="http://p.id" target="_blank">p.id</a>,</div><div>  st_subdivide((st_dumprings((st_dump(geom)).geom)).geom) as geom</div><div>  FROM p;</div><div><br></div><div>CREATE INDEX p_edges_geom_x ON p_edges USING GIST (geom);</div><div><br></div><div>SELECT <a href="http://a.id" target="_blank">a.id</a>, <a href="http://p.id" target="_blank">p.id</a></div><div>  FROM a </div><div>  JOIN p_edges ON ST_Intersects(a.geom, p_edges.geom)</div><div><div><br></div><div>Dump P multipolygon to polygon, polygon to rings, subdivide rings into shorter edges, find all members of A that intersect those edges.</div><div><br></div><div><br></div><div><br><blockquote type="cite"><div>On Dec 5, 2023, at 2:21 PM, Mats Taraldsvik via postgis-users <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>> wrote:</div><br><div><div dir="ltr"><div>Hi,</div><div><br></div><div>I have a large polygon P in a query against a table A where I'm only interested in A's polygons that touch/crosses the boundary of P.</div><div><br></div><div>I have tried <a href="https://postgis.net/docs/ST_DumpSegments.html" target="_blank">https://postgis.net/docs/ST_DumpSegments.html</a> but it does generate a lot of geometries when the polygon has 100s or 1000s of points.</div><div><br></div><div>Are there more efficient approaches to this?</div><div><br></div><div>Regards,</div><div>Mats Taraldsvik<br></div></div>
_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br></div></blockquote></div><br></div></div></blockquote></div>