ST_LargestEmptyCircle
What is ST_LargestEmptyCircle?
ST_LargestEmptyCircle is a PostGIS function that finds the largest circle containing no points of the input "obstacle" geometry, optionally constrained to lie within a boundary polygon. It returns the circle's centre, its closest point on the obstacles, and the radius.
ST_LargestEmptyCircle(geometry geom, double precision tolerance = 0.0, geometry boundary = POLYGON EMPTY) → record (center geometry, nearest geometry, radius double precision)tolerance controls convergence precision; boundary restricts where the centre can lie.
When would you use ST_LargestEmptyCircle?
Use ST_LargestEmptyCircle to find the largest gap in a distribution — the biggest empty area inside a city that is not served by an existing facility, the widest clearing in a forest of obstacles, or the optimal location to place a new tower that is as far as possible from existing transmitters. It is the dual of ST_MaximumInscribedCircle: one looks for the centre farthest from edges, this one for the centre farthest from obstacles.
1SELECT (circle).center AS proposed_site, (circle).radius
2FROM (
3 SELECT ST_LargestEmptyCircle(
4 ST_Collect(geom),
5 1.0,
6 (SELECT geom FROM city_boundary WHERE id = 1)
7 ) AS circle
8 FROM existing_towers
9) t;FAQs
What counts as an obstacle?
Every vertex and edge of the input geom is an obstacle. The algorithm places the circle so it contains no obstacle geometries inside — it does not avoid arbitrary interiors, so polygonal obstacles should typically be supplied as their boundary lines.
Why does the boundary parameter matter?
Without a boundary, the largest empty circle could grow unbounded off to infinity where there are no obstacles. The boundary constrains the centre to a meaningful region (a city limit, a study area, a parcel). Pass a polygon for the search area.
How does this compare to ST_MaximumInscribedCircle?
ST_MaximumInscribedCircle fits the largest circle inside a polygon using the polygon's boundary as the constraint. ST_LargestEmptyCircle fits the largest circle around obstacles, with a separately specified boundary. They solve related but distinct problems.
What units is the radius in?
The same units as the input SRID. For accurate metre-based radii, work in a projected CRS like UTM or EPSG:3857; for EPSG:4326 the radius will be in degrees, which is rarely what you want.