ST_LabelPoint computes and returns a label point for a given polygon or geometry collection. The label point is chosen to be sufficiently far from boundaries of the geometry. For a regular Polygon this will be the centroid.
polygon_to_anchor, an approximate solution for label point generation, designed to be faster than optimal algorithms like polylabel. It searches for a “good enough” label point within a limited number of iterations. For geometry collections, only the largest Polygon by area is considered. While ST_Centroid is a fast algorithm to calculate the center of mass of a (Multi)Polygon, it may place the point outside of the Polygon or near a boundary for concave shapes, polygons with holes, or MultiPolygons.
ST_LabelPoint takes up to 3 arguments,
geometry: input geometry (e.g., a Polygon or GeometryCollection) for which the anchor point is to be calculated.gridResolution(Optional, default is 16): Controls the resolution of the search grid for refining the label point. A higher resolution increases the grid density, providing a higher chance of finding a good enough result at the cost of runtime. For example, a gridResolution of 16 divides the bounding box of the polygon into a 16x16 grid.goodnessThreshold(Optional, default is 0.2): Determines the minimum acceptable “goodness” value for the anchor point. Higher thresholds prioritize points farther from boundaries but may require more computation.
ST_LabelPointthrows anIllegalArgumentExceptionif the input geometry has an area of zero or less.- Holes within polygons are respected. Points within a hole are given a goodness of 0.
- For GeometryCollections, only the largest polygon by area is considered.
Signatures
Parameters
Geometry
required
The input geometry.
Integer
The grid resolution value.
Double
The goodness threshold value.
Return type
The resulting geometry.

