# Finding outermost border of set of geomertries (circles) using PostGIS?

I have a (large) set of geometries (circles) that overlap.! I would like to find the nearest location outside of this group from my current location. In this example my location is the black dot. In my scenario I would like to get out of this group of circles and find the edge / border of this group, do I can draw a point on (or just outside of it), this would be the red dot. Is there any way to achieve this using postgis without first having to draw an infinite amount of points to test against?

• Is this an operation that you need to repeat numerous times? Because one way of doing this would be to dissolve the circles into a geometry and check the distance of the vertices to the point of interest. However, if you need to repeat this operation millions of times, the efficiency of the dissolve would make this approach less feasible. – WhiteboxDev Dec 2 '14 at 13:06
• I don't need to repeat it per se, it's just that the users position (black dot) will be different each time. – Richard Vijgen Dec 2 '14 at 13:14
• Also, if i would check the individual vertices, how would I know if they are "border" vertices or vertices that are overlapping with other circles? – Richard Vijgen Dec 2 '14 at 13:15
• That's where the dissolve operation comes in. When you dissolve the circles, you'll end up with a geometry that is only the outer border of the group of circles. You can then check the distance to each vertex in that geometry to your POI, as an approximate. It should scale okay for thousands or millions of points. – WhiteboxDev Dec 2 '14 at 13:17
• For all POI that are not located within the convex lobe of an outer circle (border), the nearest point will always be one of the intersection points between two outer circles, and these vertices will certainly be part of the dissolve geometry. So the method I describe above will actually work quite well, and for efficiency you should check the distance to these key intersection points first. – WhiteboxDev Dec 2 '14 at 13:21

## 2 Answers

you could create the convex hull of your set of circles (ST_ConvexHull)

Then create your point by looking at the closest point on the boundary (ST_ExteriorRing) of the convex hull, using ST_ClosestPoint

• But the exterior boundary is a concave hull and not a convex hull. – WhiteboxDev Dec 2 '14 at 14:44
• On the image posted by the OP, it looks like the red point is on the convex hull. – radouxju Dec 2 '14 at 14:45
• I thought the same at first ;) – WhiteboxDev Dec 2 '14 at 14:48

Select st_closestpoint(st_boundary(st_union(geom)),point ) from table_of_circles

• `Select st_closestpoint(st_boundary(st_union(geom)), pt) from table_of_circles` I think you mean :D. – John Powell Dec 2 '14 at 15:27