2

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.

enter image description here

Is there any way to achieve this using postgis without first having to draw an infinite amount of points to test against?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • 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 02 '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 02 '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 02 '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 02 '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 02 '14 at 13:21
  • By dissolve, are you referring to the ST_Union operation, or another method? – Richard Vijgen Dec 02 '14 at 13:25
  • I can't say that I'm very familiar with postgis but union is often the same thing as dissolve. Although if it doesn't eliminate the interior edges of the group of geometries, then you should look for an alternative. I know that in JTS-land, you could do a buffer with a buffer width of 0 to achieve this operation. Are your circles lines or polygons? – WhiteboxDev Dec 02 '14 at 13:32
  • they are polygons – Richard Vijgen Dec 02 '14 at 13:39
  • I found a dissolve function in Qgis, that i'm going to try. This seems like a good strategy. Thanks so much for your help! – Richard Vijgen Dec 02 '14 at 13:54
  • St_union is what you want. It removes the interior borders. Then checking the distances to the vertexes is not enough since the correct answer might be on an edge between. St_closestpoint will check both vertex points and edges – Nicklas Avén Dec 02 '14 at 19:03

2 Answers2

1

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

radouxju
  • 49,636
  • 2
  • 71
  • 144
1

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

Nicklas Avén
  • 13,241
  • 1
  • 39
  • 48