I am curious how can I find all polygons that are touching with each other but are completely separate from the rest of the polygons is the same dataset, using PostGIS.
For better understanding I uploaded a picture.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI am curious how can I find all polygons that are touching with each other but are completely separate from the rest of the polygons is the same dataset, using PostGIS.
For better understanding I uploaded a picture.
As suggested in this answer, use ST_ClusterDBSCAN
to assign an id to each touching group of polygons:
SELECT *,
ST_ClusterDBSCAN(geom, 0, 1) OVER() AS clst_id
FROM poly_table;
You can merge touching polygons, see this answer:
https://stackoverflow.com/a/49970447/2816941
This will produce a layer for these "islands".
Then you can simply join back onto the islands from the original data using st_intersects(islands.geom, st_pointonsurface(original.geom))