ST_SimplifyPolygonHull — Computes a simplified topology-preserving outer or inner hull of a polygonal geometry.
geometry ST_SimplifyPolygonHull(geometry param_geom, float vertex_fraction, boolean is_outer = true);
Computes a simplified topology-preserving outer or inner hull of a polygonal geometry. An outer hull completely covers the input geometry. An inner hull is completely covered by the input geometry. The result is a polygonal geometry formed by a subset of the input vertices. MultiPolygons and holes are handled and produce a result with the same structure as the input.
The reduction in vertex count is controlled by the vertex_fraction parameter,
which is a number in the range 0 to 1.
Lower values produce simpler results, with smaller vertex count and less concaveness.
For both outer and inner hulls a vertex fraction of 1.0 produces the original geometry.
For outer hulls a value of 0.0 produces the convex hull (for a single polygon);
for inner hulls it produces a triangle.
The simplification process operates by progressively removing concave corners that contain the least amount of area, until the vertex count target is reached. It prevents edges from crossing, so the result is always a valid polygonal geometry.
To get better results with geometries that contain relatively long line segments, it might be necessary to "segmentize" the input, as shown below.
Performed by the GEOS module.
Availability: 3.3.0.
Requires GEOS >= 3.11.0.
Outer hull of a Polygon.
SELECT ST_SimplifyPolygonHull( 'POLYGON ((131 158,136 163,161 165,173 156,179 148,169 140,186 144,190 137,185 131,174 128,174 124,166 119,158 121,158 115,165 107,161 97,166 88,166 79,158 57,145 57,112 53,111 47,93 43,90 48,88 40,80 39,68 32,51 33,40 31,39 34,49 38,34 38,25 34,28 39,36 40,44 46,24 41,17 41,14 46,19 50,33 54,21 55,13 52,11 57,22 60,34 59,41 68,75 72,62 77,56 70,46 72,31 69,46 76,52 82,47 84,56 90,66 90,64 94,56 91,33 97,36 100,23 100,22 107,29 106,31 112,46 116,36 118,28 131,53 132,59 127,62 131,76 130,80 135,89 137,87 143,73 145,80 150,88 150,85 157,99 162,116 158,115 165,123 165,122 170,134 164,131 158))'::geometry, 0.3 );
POLYGON((161 165,173 156,186 144,190 137,185 131,174 124,166 119,166 79,158 57,68 32,40 31,25 34,17 41,14 46,11 57,56 91,33 97,23 100,22 107,28 131,80 135,73 145,85 157,99 162,122 170,161 165))
Inner hull of a Polygon.
SELECT ST_SimplifyPolygonHull( 'POLYGON ((131 158,136 163,161 165,173 156,179 148,169 140,186 144,190 137,185 131,174 128,174 124,166 119,158 121,158 115,165 107,161 97,166 88,166 79,158 57,145 57,112 53,111 47,93 43,90 48,88 40,80 39,68 32,51 33,40 31,39 34,49 38,34 38,25 34,28 39,36 40,44 46,24 41,17 41,14 46,19 50,33 54,21 55,13 52,11 57,22 60,34 59,41 68,75 72,62 77,56 70,46 72,31 69,46 76,52 82,47 84,56 90,66 90,64 94,56 91,33 97,36 100,23 100,22 107,29 106,31 112,46 116,36 118,28 131,53 132,59 127,62 131,76 130,80 135,89 137,87 143,73 145,80 150,88 150,85 157,99 162,116 158,115 165,123 165,122 170,134 164,131 158))'::geometry, 0.3, false );
POLYGON((131 158,116 158,99 162,89 137,76 130,59 127,28 131,46 116,36 100,64 94,75 72,41 68,33 54,68 32,90 48,112 53,145 57,158 57,161 97,158 115,158 121,190 137,169 140,179 148,161 165,131 158))
Outer hull simplification of a MultiPolygon, with segmentization.
WITH letters AS (
SELECT ST_Letters('xt') AS geom
)
SELECT geom AS input,
ST_SimplifyPolygonHull(ST_Segmentize(geom, 2.0), 0.1) AS outer_hull
FROM letters;
MULTIPOLYGON(((18.3 57.6,20.7 51,23.3 41.9,26 51,28.4 57.6,45.4 57.6,33.1 28.8,46.6 0,29.5 0,26.6 6.7,23.3 16.3,19.8 6.3,17.1 0,0 0,13.5 28.8,1.3 57.6,18.3 57.6)),((77.808 15.2,82.208 15.2,83.508 16,83.508 -0.9,82.108 -0.2,76.808 -0.2,76.108 -0.2,75.408 -0.2,74.608 -0.1,73.908 -0.1,73.208 0,72.508 0,71.808 0.1,71.108 0.2,70.408 0.3,69.708 0.5,69.008 0.6,68.408 0.9,67.708 1.1,67.008 1.4,66.408 1.7,65.708 2,65.108 2.4,64.408 2.8,63.808 3.2,63.208 3.7,62.608 4.1,62.108 4.7,61.508 5.2,61.008 5.8,60.508 6.4,60.008 7.1,59.508 7.8,59.108 8.6,58.708 9.5,58.308 10.4,57.908 11.3,57.608 12.3,57.608 42.7,52.208 42.7,51.108 41.8,51.108 58.9,52.208 57.9,57.608 57.9,57.608 74.4,56.508 75.4,74.408 75.4,73.308 74.2,73.308 57.9,81.408 57.9,82.508 58.9,82.508 41.8,81.408 42.7,73.308 42.7,73.308 17.7,73.408 17.4,73.608 17.2,73.808 16.9,74.008 16.7,74.208 16.5,74.408 16.3,74.708 16.1,75.008 15.9,75.308 15.7,75.608 15.6,76.008 15.5,76.308 15.4,76.708 15.3,77.008 15.2,77.408 15.2,77.808 15.2))) | MULTIPOLYGON(((45.4 57.6,44.631 55.8,33.869 30.6,46.6 0,29.5 0,19.8 6.3,18.45 3.15,17.1 0,0 0,10.969 23.4,9.688 37.8,2.062 55.8,1.3 57.6,45.4 57.6)),((83.508 16,83.508 -0.9,72.508 0,71.108 0.2,70.408 0.3,69.008 0.6,67.708 1.1,67.008 1.4,65.708 2,64.408 2.8,63.808 3.2,62.608 4.1,61.508 5.2,60.508 6.4,59.508 7.8,59.108 8.6,58.308 10.4,57.908 11.3,57.608 12.3,51.108 41.8,51.108 58.9,56.508 75.4,74.408 75.4,82.508 58.9,83.508 16)))