[postgis-users] Finding all polygons crossing a large polygons boundary

Paul Ramsey pramsey at cleverelephant.ca
Tue Dec 5 14:33:16 PST 2023


Sort of ugly but…

CREATE TEMPORARY TABLE p_edges AS
  SELECT p.id <http://p.id/>,
  st_subdivide((st_dumprings((st_dump(geom)).geom)).geom) as geom
  FROM p;

CREATE INDEX p_edges_geom_x ON p_edges USING GIST (geom);

SELECT a.id <http://a.id/>, p.id
  FROM a 
  JOIN p_edges ON ST_Intersects(a.geom, p_edges.geom)

Dump P multipolygon to polygon, polygon to rings, subdivide rings into shorter edges, find all members of A that intersect those edges.



> On Dec 5, 2023, at 2:21 PM, Mats Taraldsvik via postgis-users <postgis-users at lists.osgeo.org> wrote:
> 
> Hi,
> 
> 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.
> 
> I have tried https://postgis.net/docs/ST_DumpSegments.html but it does generate a lot of geometries when the polygon has 100s or 1000s of points.
> 
> Are there more efficient approaches to this?
> 
> Regards,
> Mats Taraldsvik
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20231205/5bcfb1ca/attachment.htm>


More information about the postgis-users mailing list