ST_MaximumInscribedCircle — Computes the largest circle contained within a geometry.
(geometry, geometry, double precision) ST_MaximumInscribedCircle(geometry geom);
Finds the largest circle that is contained within a (multi)polygon, or which does not overlap any lines and points. Returns a record with fields:
center - center point of the circle
nearest - a point on the geometry nearest to the center
radius - radius of the circle
For polygonal inputs, the circle is inscribed within the boundary rings, using the internal rings as boundaries. For linear and point inputs, the circle is inscribed within the convex hull of the input, using the input lines and points as further boundaries.
Availability: 3.1.0.
Requires GEOS >= 3.9.0.
Maximum inscribed circle of a polygon. Center, nearest point, radius, circle, and radius line are returned.
WITH mic AS (
SELECT * FROM ST_MaximumInscribedCircle(
'POLYGON ((40 180,110 160,180 180,180 120,140 90,160 40,80 10,70 40,20 50,40 180),
(60 140,50 90,90 140,60 140))')
)
SELECT round(radius::numeric, 3) AS radius,
ST_SnapToGrid(center, 1) AS center,
ST_SnapToGrid(nearest, 1) AS nearest,
ST_SnapToGrid(ST_Buffer(center, radius), 1) AS circle,
ST_SnapToGrid(ST_MakeLine(center, nearest), 1) AS radius_line
FROM mic;
-[ RECORD 1 ]----- radius | 45.189 center | POINT(97 76) nearest | POINT(62 105) circle | POLYGON((142 76,141 68,139 59,135 51,129 44,122 39,114 35,106 32,97 31,88 32,80 35,72 39,65 44,59 51,55 59,53 68,52 76,53 85,55 94,59 101,65 108,72 114,80 118,88 121,97 122,106 121,114 118,122 114,129 108,135 101,139 94,141 85,142 76)) radius_line | LINESTRING(97 76,62 105)
Maximum inscribed circle of a MultiLineString.
WITH mic AS (
SELECT * FROM ST_MaximumInscribedCircle(
'MULTILINESTRING((100 40,10 150),(10 160,100 150),(190 150,80 40))')
)
SELECT round(radius::numeric, 3) AS radius,
ST_SnapToGrid(center, 1) AS center,
ST_SnapToGrid(nearest, 1) AS nearest,
ST_SnapToGrid(ST_Buffer(center, radius), 1) AS circle,
ST_SnapToGrid(ST_MakeLine(center, nearest), 1) AS radius_line
FROM mic;
-[ RECORD 1 ]----- radius | 39.924 center | POINT(94 110) nearest | POINT(63 85) circle | POLYGON((134 110,133 103,131 95,127 88,122 82,116 77,109 74,102 71,94 71,86 71,79 74,72 77,66 82,61 88,57 95,55 103,54 110,55 118,57 126,61 133,66 139,72 144,79 147,86 150,94 150,102 150,109 147,116 144,122 139,127 133,131 126,133 118,134 110)) radius_line | LINESTRING(94 110,63 85)