These functions compute geometric constructions, or alter geometry size or shape.

# Geometry Processing

ST_Buffer

Returns a geometry covering all points within a given distance from a geometry.

                        geometry ST_Buffer
                        geometry  g1
                        float  radius_of_buffer
                        text  buffer_style_parameters = ''

                        geometry ST_Buffer
                        geometry  g1
                        float  radius_of_buffer
                        integer  num_seg_quarter_circle

                        geography ST_Buffer
                        geography  g1
                        float  radius_of_buffer
                        text  buffer_style_parameters

                        geography ST_Buffer
                        geography  g1
                        float  radius_of_buffer
                        integer  num_seg_quarter_circle

### Description

Returns a geometry/geography that represents all points whose distance from this Geometry/geography is less than or equal to distance.

Geometry: Calculations are in the Spatial Reference System of the geometry. Introduced in 1.5 support for different end cap and mitre settings to control shape.

Negative radii: For polygons, a negative radius can be used, which will shrink the polygon rather than expanding it.

Geography: For geography this is really a thin wrapper around the geometry implementation. It first determines the best SRID that fits the bounding box of the geography object (favoring UTM, Lambert Azimuthal Equal Area (LAEA) north/south pole, and falling back on mercator in worst case scenario) and then buffers in that planar spatial ref and retransforms back to WGS84 geography.

For geography this may not behave as expected if object is sufficiently large that it falls between two UTM zones or crosses the dateline

Enhanced: 2.5.0 - ST_Buffer geometry support was enhanced to allow for side buffering specification `side=both|left|right`.

Availability: 1.5 - ST_Buffer was enhanced to support different endcaps and join types. These are useful for example to convert road linestrings into polygon roads with flat or square edges instead of rounded edges. Thin wrapper for geography was added.

The optional third parameter (currently only applies to geometry) can either specify number of segments used to approximate a quarter circle (integer case, defaults to 8) or a list of blank-separated key=value pairs (string case) to tweak operations as follows:

- 'quad_segs=#' : number of segments used to approximate a quarter circle (defaults to 8).

- 'endcap=round|flat|square' : endcap style (defaults to "round"). 'butt' is also accepted as a synonym for 'flat'.

- 'join=round|mitre|bevel' : join style (defaults to "round"). 'miter' is also accepted as a synonym for 'mitre'.

- 'mitre_limit=#.#' : mitre ratio limit (only affects mitered join style). 'miter_limit' is also accepted as a synonym for 'mitre_limit'.

- 'side=both|left|right' : 'left' or 'right' performs a single-sided buffer on the geometry, with the buffered side relative to the direction of the line. This is only really relevant to LINESTRING geometry and does not affect POINT or POLYGON geometries. By default end caps are square.

Units of radius are measured in units of the spatial reference system.

The inputs can be POINTS, MULTIPOINTS, LINESTRINGS, MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS, and GeometryCollections.

This function ignores the third dimension (z) and will always give a 2-d buffer even when presented with a 3d-geometry.

Performed by the GEOS module.

&sfs_compliant; s2.1.1.3

&sqlmm_compliant; SQL-MM 3: 5.1.17

People often make the mistake of using this function to try to do radius searches. Creating a buffer to a radius search is slow and pointless. Use ST_DWithin instead.

### Examples

quad_segs=8 (default)
    SELECT ST_Buffer(
     ST_GeomFromText('POINT(100 90)'),
     50, 'quad_segs=8');
| quad_segs=2 (lame)
    SELECT ST_Buffer(
     ST_GeomFromText('POINT(100 90)'),
     50, 'quad_segs=2');
endcap=round join=round (default)
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'endcap=round join=round');
| endcap=square
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'endcap=square join=round');
| endcap=flat
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'endcap=flat join=round');
join=bevel
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'join=bevel');
| join=mitre mitre_limit=5.0 (default mitre limit)
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'join=mitre mitre_limit=5.0');
| join=mitre mitre_limit=1
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'join=mitre mitre_limit=1.0');
side=left
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'side=left');
| side=right
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'side=right');
| side=left join=mitre
    SELECT ST_Buffer(
     ST_GeomFromText(
      'LINESTRING(50 50,150 150,150 50)'
     ), 10, 'side=left join=mitre');
right-hand-winding, polygon boundary side=left
    SELECT ST_Buffer(
    ST_ForceRHR(
    ST_Boundary(
     ST_GeomFromText(
    'POLYGON ((50 50, 50 150, 150 150, 150 50, 50 50))'))),
     ), 20, 'side=left');
| right-hand-winding, polygon boundary side=right
    SELECT ST_Buffer(
    ST_ForceRHR(
    ST_Boundary(
     ST_GeomFromText(
    'POLYGON ((50 50, 50 150, 150 150, 150 50, 50 50))'))
    ), 20,'side=right')

    --A buffered point approximates a circle
    -- A buffered point forcing approximation of (see diagram)
    -- 2 points per quarter circle is poly with 8 sides (see diagram)
    SELECT ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50)) As promisingcircle_pcount,
    ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50, 2)) As lamecircle_pcount;

    promisingcircle_pcount | lamecircle_pcount
    ------------------------+-------------------
                 33 |                9

    --A lighter but lamer circle
    -- only 2 points per quarter circle is an octagon
    --Below is a 100 meter octagon
    -- Note coordinates are in NAD 83 long lat which we transform
    to Mass state plane meter and then buffer to get measurements in meters;
    SELECT ST_AsText(ST_Buffer(
    ST_Transform(
    ST_SetSRID(ST_MakePoint(-71.063526, 42.35785),4269), 26986)
    ,100,2)) As octagon;
    ----------------------
    POLYGON((236057.59057465 900908.759918696,236028.301252769 900838.049240578,235
    957.59057465 900808.759918696,235886.879896532 900838.049240578,235857.59057465
    900908.759918696,235886.879896532 900979.470596815,235957.59057465 901008.759918
    696,236028.301252769 900979.470596815,236057.59057465 900908.759918696))

### See Also

ST_Collect, ST_DWithin, ST_SetSRID, ST_Transform, ST_Union

ST_BuildArea

Creates a polygonal geometry formed by the linework of a geometry.

                    geometry ST_BuildArea
                    geometry  geom

### Description

Creates an areal geometry formed by the constituent linework of the input geometry. The input can be LINESTRINGS, MULTILINESTRINGS, POLYGONS, MULTIPOLYGONS, and GeometryCollections. The result is a Polygon or MultiPolygon, depending on input. If the input linework does not form polygons, NULL is returned.

This function assumes all inner geometries represent holes

Input linework must be correctly noded for this function to work properly

Availability: 1.1.0

### Examples

These will create a donut
    --using polygons
    SELECT ST_BuildArea(ST_Collect(smallc,bigc))
    FROM (SELECT
        ST_Buffer(
          ST_GeomFromText('POINT(100 90)'), 25) As smallc,
        ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50) As bigc) As foo;
    --using linestrings
    SELECT ST_BuildArea(ST_Collect(smallc,bigc))
    FROM (SELECT
        ST_ExteriorRing(ST_Buffer(
          ST_GeomFromText('POINT(100 90)'), 25)) As smallc,
        ST_ExteriorRing(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50)) As bigc) As foo;

### See Also

ST_Node, ST_MakePolygon, ST_MakeValid, ST_BdPolyFromText, ST_BdMPolyFromText (wrappers to this function with standard OGC interface)

ST_Centroid

Returns the geometric center of a geometry.

              geometry ST_Centroid

              geometry
              g1

                    geography ST_Centroid

                    geography
                    g1
                    boolean
                    use_spheroid=true

### Description

Computes a point which is the geometric center of mass of a geometry. For [`MULTI`]`POINT`s, the centroid is the arithmetic mean of the input coordinates. For [`MULTI`]`LINESTRING`s, the centroid is computed using the weighted length of each line segment. For [`MULTI`]`POLYGON`s, the centroid is computed in terms of area. If an empty geometry is supplied, an empty `GEOMETRYCOLLECTION` is returned. If `NULL` is supplied, `NULL` is returned. If `CIRCULARSTRING` or `COMPOUNDCURVE` are supplied, they are converted to linestring wtih CurveToLine first, then same than for `LINESTRING`

For mixed-dimension input, the result is equal to the centroid of the component Geometries of highest dimension (since the lower-dimension geometries contribute zero "weight" to the centroid).

New in 2.3.0 : support `CIRCULARSTRING` and `COMPOUNDCURVE` (using CurveToLine)

Availability: 2.4.0 support for geography was introduced.

&sfs_compliant;

&sqlmm_compliant; SQL-MM 3: 8.1.4, 9.5.5

### Examples

In the following illustrations the green dot is the centroid of the source geometry.

Centroid of a `MULTIPOINT` | Centroid of a `LINESTRING`
Centroid of a `POLYGON` | Centroid of a `GEOMETRYCOLLECTION`

    SELECT ST_AsText(ST_Centroid('MULTIPOINT ( -1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1, 2 0, 6 0, 7 8, 9 8, 10 6 )'));
                    st_astext
    ------------------------------------------
     POINT(2.30769230769231 3.30769230769231)
    (1 row)

    SELECT ST_AsText(ST_centroid(g))
    FROM  ST_GeomFromText('CIRCULARSTRING(0 2, -1 1,0 0, 0.5 0, 1 0, 2 1, 1 2, 0.5 2, 0 2)')  AS g ;
    ------------------------------------------
    POINT(0.5 1)

    SELECT ST_AsText(ST_centroid(g))
    FROM  ST_GeomFromText('COMPOUNDCURVE(CIRCULARSTRING(0 2, -1 1,0 0),(0 0, 0.5 0, 1 0),CIRCULARSTRING( 1 0, 2 1, 1 2),(1 2, 0.5 2, 0 2))' ) AS g;
    ------------------------------------------
    POINT(0.5 1)

### See Also

ST_PointOnSurface, ST_GeometricMedian

ST_ConcaveHull

Computes a possibly concave geometry that encloses all input geometry vertices

                geometry ST_ConcaveHull
                geometry  geom
                float  target_percent
                boolean  allow_holes = false

### Description

The concave hull of a geometry represents a possibly concave geometry that encloses the input geometry. The result is a single polygon, line or point. It will not contain holes unless the optional `allow_holes` argument is specified as true.

The `target_percent` is the target percent of area of convex hull the PostGIS solution will try to approach before giving up or exiting. One can think of the concave hull as the geometry you get by vacuum sealing a set of geometries. The target_percent of 1 will give you the same answer as the convex hull. A target_percent between 0 and 0.99 will give you something that should have a smaller area than the convex hull. This is different from a convex hull which is more like wrapping a rubber band around the set of geometries.

It is usually used with MULTI and Geometry Collections. It is not an aggregate function, but can be used with ST_Collect or ST_Union to get the concave hull of a set of points/linestring/polygons (e.g. `ST_ConcaveHull(ST_Collect(somepointfield), 0.80)`.

It is slower to compute than the convex hull but generally has a smaller result area and represents a more natural bounds of the input geometry.

Note - If you are using with points, linestrings, or geometry collections use ST_Collect. If you are using with polygons, use ST_Union since it may fail with invalid geometries.

Note - The smaller you make the target percent, the longer it takes to process the concave hull and more likely to run into topological exceptions. Also the more floating points and number of points you accrue. First try a 0.99 which does a first hop, is usually very fast, sometimes as fast as computing the convex hull, and usually gives much better than 99% of shrink since it almost always overshoots. Second hope of 0.98 it slower, others get slower usually quadratically. To reduce precision and float points, use ST_SimplifyPreserveTopology or ST_SnapToGrid after ST_ConcaveHull. ST_SnapToGrid is a bit faster, but could result in invalid geometries where as ST_SimplifyPreserveTopology almost always preserves the validity of the geometry.

More real world examples and brief explanation of the technique are shown http://www.bostongis.com/postgis_concavehull.snippet

Also check out Simon Greener's article on demonstrating ConcaveHull introduced in Oracle 11G R2. http://www.spatialdbadvisor.com/oracle_spatial_tips_tricks/172/concave-hull-geometries-in-oracle-11gr2. The solution we get at 0.75 target percent of convex hull is similar to the shape Simon gets with Oracle SDO_CONCAVEHULL_BOUNDARY.

Performed by the GEOS module

Availability: 2.0.0

### Examples

    --Get estimate of infected area based on point observations
    SELECT d.disease_type,
        ST_ConcaveHull(ST_Collect(d.pnt_geom), 0.99) As geom
        FROM disease_obs As d
        GROUP BY d.disease_type;

ST_ConcaveHull of 2 polygons encased in target 100% shrink concave hull
    -- geometries overlaid with concavehull
    -- at target 100% shrink (this is the same as convex hull - since no shrink)
    SELECT
        ST_ConcaveHull(
            ST_Union(ST_GeomFromText('POLYGON((175 150, 20 40,
                50 60, 125 100, 175 150))'),
            ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20)
            ), 1)
         As convexhull;
| -- geometries overlaid with concavehull at target 90% of convex hull area
    -- geometries overlaid with concavehull at target 90% shrink
    SELECT
        ST_ConcaveHull(
            ST_Union(ST_GeomFromText('POLYGON((175 150, 20 40,
                50 60, 125 100, 175 150))'),
            ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20)
            ), 0.9)
         As target_90;
L Shape points overlaid with convex hull
    -- this produces a table of 42 points that form an L shape
    SELECT (ST_DumpPoints(ST_GeomFromText(
    'MULTIPOINT(14 14,34 14,54 14,74 14,94 14,114 14,134 14,
    150 14,154 14,154 6,134 6,114 6,94 6,74 6,54 6,34 6,
    14 6,10 6,8 6,7 7,6 8,6 10,6 30,6 50,6 70,6 90,6 110,6 130,
    6 150,6 170,6 190,6 194,14 194,14 174,14 154,14 134,14 114,
    14 94,14 74,14 54,14 34,14 14)'))).geom
        INTO TABLE l_shape;

    SELECT ST_ConvexHull(ST_Collect(geom))
    FROM l_shape;
| ST_ConcaveHull of L points at target 99% of convex hull
    SELECT ST_ConcaveHull(ST_Collect(geom), 0.99)
        FROM l_shape;
Concave Hull of L points at target 80% convex hull area
        -- Concave Hull L shape points
        -- at target 80% of convexhull
        SELECT ST_ConcaveHull(ST_Collect(geom), 0.80)
        FROM l_shape;
| multilinestring overlaid with Convex hull multilinestring with overlaid with Concave hull of linestrings at 99% target -- first hop
    SELECT ST_ConcaveHull(ST_GeomFromText('MULTILINESTRING((106 164,30 112,74 70,82 112,130 94,
        130 62,122 40,156 32,162 76,172 88),
    (132 178,134 148,128 136,96 128,132 108,150 130,
    170 142,174 110,156 96,158 90,158 88),
    (22 64,66 28,94 38,94 68,114 76,112 30,
    132 10,168 18,178 34,186 52,184 74,190 100,
    190 122,182 148,178 170,176 184,156 164,146 178,
    132 186,92 182,56 158,36 150,62 150,76 128,88 118))'),0.99)

### See Also

ST_Collect, ST_ConvexHull, ST_SimplifyPreserveTopology, ST_SnapToGrid

ST_ConvexHull

Computes the convex hull of a geometry.

                geometry ST_ConvexHull
                geometry  geomA

### Description

Computes the convex hull of a geometry. The convex hull is the smallest convex geometry that encloses all geometries in the input.

In the general case the convex hull is a Polygon. The convex hull of two or more collinear points is a two-point LineString. The convex hull of one or more identical points is a Point.

It is usually used with Multi* and GeometryCollections. It is not an aggregate function. To compute the convex hull of a set of geometries, use ST_Collect to aggregate them.

One can think of the convex hull as the geometry obtained by wrapping an elastic band around a set of geometries. This is different from a concave hull which is analogous to "shrink-wrapping" the geometries. A convex hull is often used to determine an affected area based on a set of point observations.

Performed by the GEOS module

&sfs_compliant; s2.1.1.3

&sqlmm_compliant; SQL-MM 3: 5.1.16

&Z_support;

### Examples

Convex Hull of a MultiLinestring and a MultiPoint

    SELECT ST_AsText(ST_ConvexHull(
        ST_Collect(
            ST_GeomFromText('MULTILINESTRING((100 190,10 8),(150 10, 20 30))'),
                ST_GeomFromText('MULTIPOINT(50 5, 150 30, 50 10, 10 10)')
                )) );
    ---st_astext--
    POLYGON((50 5,10 8,10 10,100 190,150 30,150 10,50 5))

Using with ST_Collect to compute the convex hulls of geometry sets.

    --Get estimate of infected area based on point observations
    SELECT d.disease_type,
        ST_ConvexHull(ST_Collect(d.the_geom)) As the_geom
        FROM disease_obs As d
        GROUP BY d.disease_type;

### See Also

ST_Collect, ST_ConcaveHull, ST_MinimumBoundingCircle

ST_DelaunayTriangles

Returns the Delaunay triangulation of the vertices of a geometry.

                    geometry ST_DelaunayTriangles
                    geometry  g1
                    float  tolerance
                    int4  flags

### Description

Return the Delaunay triangulation of the vertices of the input geometry. Output is a COLLECTION of polygons (for flags=0) or a MULTILINESTRING (for flags=1) or TIN (for flags=2). The tolerance, if any, is used to snap input vertices together.

Performed by the GEOS module.

Availability: 2.1.0

&Z_support;

&T_support;

### 2D Examples

Original polygons
    -- our original geometry --
        ST_Union(ST_GeomFromText('POLYGON((175 150, 20 40,
                50 60, 125 100, 175 150))'),
            ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20)
            )
ST_DelaunayTriangles of 2 polygons: delaunay triangle polygons each triangle themed in different color
    -- geometries overlaid multilinestring triangles
    SELECT
        ST_DelaunayTriangles(
            ST_Union(ST_GeomFromText('POLYGON((175 150, 20 40,
                50 60, 125 100, 175 150))'),
            ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20)
            ))
         As  dtriag;
-- delaunay triangles as multilinestring
    SELECT
        ST_DelaunayTriangles(
            ST_Union(ST_GeomFromText('POLYGON((175 150, 20 40,
                50 60, 125 100, 175 150))'),
            ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20)
            ),0.001,1)
         As  dtriag;
-- delaunay triangles of 45 points as 55 triangle polygons
    -- this produces a table of 42 points that form an L shape
    SELECT (ST_DumpPoints(ST_GeomFromText(
    'MULTIPOINT(14 14,34 14,54 14,74 14,94 14,114 14,134 14,
    150 14,154 14,154 6,134 6,114 6,94 6,74 6,54 6,34 6,
    14 6,10 6,8 6,7 7,6 8,6 10,6 30,6 50,6 70,6 90,6 110,6 130,
    6 150,6 170,6 190,6 194,14 194,14 174,14 154,14 134,14 114,
    14 94,14 74,14 54,14 34,14 14)'))).geom
        INTO TABLE l_shape;
    -- output as individual polygon triangles
    SELECT ST_AsText((ST_Dump(geom)).geom) As wkt
    FROM ( SELECT ST_DelaunayTriangles(ST_Collect(geom)) As geom
    FROM l_shape) As foo;

    ---wkt ---
    POLYGON((6 194,6 190,14 194,6 194))
    POLYGON((14 194,6 190,14 174,14 194))
    POLYGON((14 194,14 174,154 14,14 194))
    POLYGON((154 14,14 174,14 154,154 14))
    POLYGON((154 14,14 154,150 14,154 14))
    POLYGON((154 14,150 14,154 6,154 14))
    :
    :

### 3D Examples

    -- 3D multipoint --
    SELECT ST_AsText(ST_DelaunayTriangles(ST_GeomFromText(
    'MULTIPOINT Z(14 14 10,
    150 14 100,34 6 25, 20 10 150)'))) As wkt;

    -----wkt----
    GEOMETRYCOLLECTION Z (POLYGON Z ((14 14 10,20 10 150,34 6 25,14 14 10))
     ,POLYGON Z ((14 14 10,34 6 25,150 14 100,14 14 10)))

### See Also

ST_ConstrainedDelaunayTriangles, ST_ConcaveHull, ST_Dump, ST_Tesselate

ST_FilterByM

Removes vertices based on their M value

                geometry ST_FilterByM
                geometry geom
                double precision min
                double precision max = null
                boolean returnM = false

### Description

Filters out vertex points based on their M-value. Returns a geometry with only vertex points that have a M-value larger or equal to the min value and smaller or equal to the max value. If max-value argument is left out only min value is considered. If fourth argument is left out the m-value will not be in the resulting geometry. If resulting geometry have too few vertex points left for its geometry type an empty geometry will be returned. In a geometry collection geometries without enough points will just be left out silently.

This function is mainly intended to be used in conjunction with ST_SetEffectiveArea. ST_EffectiveArea sets the effective area of a vertex in its m-value. With ST_FilterByM it then is possible to get a simplified version of the geometry without any calculations, just by filtering

There is a difference in what ST_SimplifyVW returns when not enough points meet the criteria compared to ST_FilterByM. ST_SimplifyVW returns the geometry with enough points while ST_FilterByM returns an empty geometry

Note that the returned geometry might be invalid

This function returns all dimensions, including the Z and M values

Availability: 2.5.0

### Examples

A linestring is filtered

    SELECT ST_AsText(ST_FilterByM(geom,30)) simplified
    FROM (SELECT  ST_SetEffectiveArea('LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)'::geometry) geom) As foo;
    -result
             simplified
    ----------------------------
     LINESTRING(5 2,7 25,10 10)

### See Also

ST_SetEffectiveArea, ST_SimplifyVW

ST_GeneratePoints

Generates random points contained in a Polygon or MultiPolygon.

                geometry ST_GeneratePoints

                    g
                    geometry

                    npoints
                    integer

                geometry ST_GeneratePoints
                 geometry g
                 integer npoints
                 integer seed

### Description

ST_GeneratePoints generates a given number of pseudo-random points which lie within the input area. The optional `seed` is used to regenerate a deterministic sequence of points, and must be greater than zero.

Availability: 2.3.0

Enhanced: 3.0.0, added seed parameter

### Examples

Original Polygon | Generated 12 Points overlaid on top of original polygon using a random seed value 1996
    SELECT ST_GeneratePoints(geom, 12, 1996)
    FROM (
        SELECT ST_Buffer(
            ST_GeomFromText(
            'LINESTRING(50 50,150 150,150 50)'),
            10, 'endcap=round join=round') AS geom
    ) AS s;

ST_GeometricMedian

Returns the geometric median of a MultiPoint.

                geometry ST_GeometricMedian

                 geometry geom
                float8 tolerance = NULL
                int max_iter = 10000
                boolean fail_if_not_converged = false

### Description

Computes the approximate geometric median of a MultiPoint geometry using the Weiszfeld algorithm. The geometric median is the point minimizing the sum of distances to the input points. It provides a centrality measure that is less sensitive to outlier points than the centroid (center of mass).

The algorithm iterates until the distance change between successive iterations is less than the supplied `tolerance` parameter. If this condition has not been met after `max_iterations` iterations, the function produces an error and exits, unless `fail_if_not_converged` is set to `false` (the default).

If a `tolerance` argument is not provided, the tolerance value is calculated based on the extent of the input geometry.

If present, the input point M values are interpreted as their relative weights.

Availability: 2.3.0

Enhanced: 2.5.0 Added support for M as weight of points.

&Z_support;

&M_support;

### Examples

Comparison of the centroid (turquoise point) and geometric median (red point) of a four-point MultiPoint (yellow points).

    WITH test AS (
    SELECT 'MULTIPOINT((0 0), (1 1), (2 2), (200 200))'::geometry geom)
    SELECT
      ST_AsText(ST_Centroid(geom)) centroid,
      ST_AsText(ST_GeometricMedian(geom)) median
    FROM test;
          centroid      |                 median
    --------------------+----------------------------------------
     POINT(50.75 50.75) | POINT(1.9761550281255 1.9761550281255)
    (1 row)

### See Also

ST_Centroid

ST_MaximumInscribedCircle

Computes the largest circle that is fully contained within a geometry.

                (geometry, geometry, double precision) ST_MaximumInscribedCircle
                geometry  geom

### Description

Finds the largest circle that is fully contained within a geometry. Returns a record with the center point of the circle, a point on the geometry that is nearest to the center, and the radius of the circle.

For polygonal inputs, the circle is inscribed within the external ring, 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 as further boundaries.

Availability: 3.1.0 - requires GEOS >= 3.9.0.

### See Also

ST_MinimumBoundingCircle

### Examples

    SELECT radius, ST_AsText(center) AS center, ST_AsText(nearest) AS nearest
        FROM ST_MaximumInscribedCircle('POLYGON ((50 50, 150 50, 150 150, 50 150, 50 50))')

     radius |     center     |    nearest
    --------+----------------+---------------
         50 | POINT(100 100) | POINT(100 50)

Maximum inscribed circle of a triangle polygon. Center, nearest point, and radius are returned.

Maximum inscribed circle of a multi-linestring. Center, nearest point, and radius are returned.

### See Also

ST_Collect, ST_MinimumBoundingRadius

ST_MinimumBoundingCircle

Returns the smallest circle polygon that contains a geometry.

                geometry ST_MinimumBoundingCircle
                geometry  geomA
                integer  num_segs_per_qt_circ=48

### Description

Returns the smallest circle polygon that contains a geometry.

The circle is approximated by a polygon with a default of 48 segments per quarter circle. Because the polygon is an approximation of the minimum bounding circle, some points in the input geometry may not be contained within the polygon. The approximation can be improved by increasing the number of segments, with little performance penalty. For applications where a polygonal approximation is not suitable, ST_MinimumBoundingRadius may be used.

It is often used with MULTI and Geometry Collections. Although it is not an aggregate - you can use it in conjunction with ST_Collect to get the minimum bounding circle of a set of geometries. ST_MinimumBoundingCircle(ST_Collect(somepointfield)).

The ratio of the area of a polygon divided by the area of its Minimum Bounding Circle is often referred to as the Roeck test.

Performed by the GEOS module.

Availability: 1.4.0

### See Also

ST_Collect, ST_MinimumBoundingRadius

### Examples

    SELECT d.disease_type,
        ST_MinimumBoundingCircle(ST_Collect(d.the_geom)) As the_geom
        FROM disease_obs As d
        GROUP BY d.disease_type;

Minimum bounding circle of a point and linestring. Using 8 segs to approximate a quarter circle

    SELECT ST_AsText(ST_MinimumBoundingCircle(
            ST_Collect(
                ST_GeomFromText('LINESTRING(55 75,125 150)'),
                    ST_Point(20, 80)), 8
                    )) As wktmbc;
    wktmbc
    -----------
    POLYGON((135.59714732062 115,134.384753327498 102.690357210921,130.79416296937 90.8537670908995,124.963360620072 79.9451031602111,117.116420743937 70.3835792560632,107.554896839789 62.5366393799277,96.6462329091006 56.70583703063,84.8096427890789 53.115246672502,72.5000000000001 51.9028526793802,60.1903572109213 53.1152466725019,48.3537670908996 56.7058370306299,37.4451031602112 62.5366393799276,27.8835792560632 70.383579256063,20.0366393799278 79.9451031602109,14.20583703063 90.8537670908993,10.615246672502 102.690357210921,9.40285267938019 115,10.6152466725019 127.309642789079,14.2058370306299 139.1462329091,20.0366393799275 150.054896839789,27.883579256063 159.616420743937,
    37.4451031602108 167.463360620072,48.3537670908992 173.29416296937,60.190357210921 176.884753327498,
    72.4999999999998 178.09714732062,84.8096427890786 176.884753327498,96.6462329091003 173.29416296937,107.554896839789 167.463360620072,
    117.116420743937 159.616420743937,124.963360620072 150.054896839789,130.79416296937 139.146232909101,134.384753327498 127.309642789079,135.59714732062 115))

### See Also

ST_Collect, ST_MinimumBoundingRadius

ST_MinimumBoundingRadius

Returns the center point and radius of the smallest circle that contains a geometry.

                    (geometry, double precision) ST_MinimumBoundingRadius
                    geometry geom

### Description

Returns a record containing the center point and radius of the smallest circle that contains a geometry.

Use in conjunction with ST_Collect to get the minimum bounding circle of a set of geometries.

Availability - 2.3.0

### See Also

ST_Collect, ST_MinimumBoundingCircle

### Examples

    SELECT ST_AsText(center), radius FROM ST_MinimumBoundingRadius('POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))');

                    st_astext                 |      radius
    ------------------------------------------+------------------
     POINT(26284.8418027133 65267.1145090825) | 247.436045591407

ST_OrientedEnvelope

Returns a minimum-area rectangle containing a geometry.

                        geometry ST_OrientedEnvelope

                            geometry
                            geom

### Description

Returns the mimimum-area rotated rectangle enclosing a geometry. Note that more than one such rectangle may exist. May return a Point or LineString in the case of degenerate inputs.

Availability: 2.5.0

### See Also

ST_Envelope ST_MinimumBoundingCircle

### Examples

                    SELECT ST_AsText(ST_OrientedEnvelope('MULTIPOINT ((0 0), (-1 -1), (3 2))'));

                    st_astext
                    ------------------------------------------------
                    POLYGON((3 2,2.88 2.16,-1.12 -0.84,-1 -1,3 2))

Oriented envelope of a point and linestring.

    SELECT ST_AsText(ST_OrientedEnvelope(
            ST_Collect(
                ST_GeomFromText('LINESTRING(55 75,125 150)'),
                    ST_Point(20, 80))
                    )) As wktenv;
    wktenv
    -----------
    POLYGON((19.9999999999997 79.9999999999999,33.0769230769229 60.3846153846152,138.076923076924 130.384615384616,125.000000000001 150.000000000001,19.9999999999997 79.9999999999999))

ST_OffsetCurve

Returns an offset line at a given distance and side from an input line.

                    geometry ST_OffsetCurve
                    geometry  line
                    float  signed_distance
                    text  style_parameters=''

### Description

Return an offset line at a given distance and side from an input line. All points of the returned geometries are not further than the given distance from the input geometry. Useful for computing parallel lines about a center line.

For positive distance the offset is on the left side of the input line and retains the same direction. For a negative distance it is on the right side and in the opposite direction.

Note that output may be a MULTILINESTRING or EMPTY for some jigsaw-shaped input geometries.

Performed by the GEOS module.

Availability: 2.0

Enhanced: 2.5 - added support for GEOMETRYCOLLECTION and MULTILINESTRING

The optional third parameter allows specifying a list of blank-separated key=value pairs to tweak operations as follows:

- 'quad_segs=#' : number of segments used to approximate a quarter circle (defaults to 8).

- 'join=round|mitre|bevel' : join style (defaults to "round"). 'miter' is also accepted as a synonym for 'mitre'.

- 'mitre_limit=#.#' : mitre ratio limit (only affects mitred join style). 'miter_limit' is also accepted as a synonym for 'mitre_limit'.

Units of distance are measured in units of the spatial reference system.

Performed by the GEOS module.

This function ignores the third dimension (z) and will always give a 2-d result even when presented with a 3d-geometry.

### Examples

Compute an open buffer around roads

    SELECT ST_Union(
     ST_OffsetCurve(f.the_geom,  f.width/2, 'quad_segs=4 join=round'),
     ST_OffsetCurve(f.the_geom, -f.width/2, 'quad_segs=4 join=round')
    ) as track
    FROM someroadstable;

15, 'quad_segs=4 join=round' original line and its offset 15 units.
    SELECT ST_AsText(ST_OffsetCurve(ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)'),
        15, 'quad_segs=4 join=round'));
    --output --
    LINESTRING(164 1,18 1,12.2597485145237 2.1418070123307,
        7.39339828220179 5.39339828220179,
        5.39339828220179 7.39339828220179,
        2.14180701233067 12.2597485145237,1 18,1 195)
| -15, 'quad_segs=4 join=round' original line and its offset -15 units
    SELECT ST_AsText(ST_OffsetCurve(geom,
        -15, 'quad_segs=4 join=round')) As notsocurvy
        FROM ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)') As geom;
    -- notsocurvy --
    LINESTRING(31 195,31 31,164 31)
double-offset to get more curvy, note the first reverses direction, so -30 + 15 = -15
    SELECT ST_AsText(ST_OffsetCurve(ST_OffsetCurve(geom,
        -30, 'quad_segs=4 join=round'), -15, 'quad_segs=4 join=round')) As morecurvy
        FROM ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)') As geom;
    -- morecurvy --
    LINESTRING(164 31,46 31,40.2597485145236 32.1418070123307,
    35.3933982822018 35.3933982822018,
    32.1418070123307 40.2597485145237,31 46,31 195)
| double-offset to get more curvy,combined with regular offset 15 to get parallel lines. Overlaid with original.
    SELECT ST_AsText(ST_Collect(
        ST_OffsetCurve(geom, 15, 'quad_segs=4 join=round'),
        ST_OffsetCurve(ST_OffsetCurve(geom,
        -30, 'quad_segs=4 join=round'), -15, 'quad_segs=4 join=round')
        )
    ) As parallel_curves
        FROM ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)') As geom;
    -- parallel curves  --
    MULTILINESTRING((164 1,18 1,12.2597485145237 2.1418070123307,
    7.39339828220179 5.39339828220179,5.39339828220179 7.39339828220179,
    2.14180701233067 12.2597485145237,1 18,1 195),
    (164 31,46 31,40.2597485145236 32.1418070123307,35.3933982822018 35.3933982822018,
    32.1418070123307 40.2597485145237,31 46,31 195))
15, 'quad_segs=4 join=bevel' shown with original line
    SELECT ST_AsText(ST_OffsetCurve(ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)'),
            15, 'quad_segs=4 join=bevel'));
    -- output --
    LINESTRING(164 1,18 1,7.39339828220179 5.39339828220179,
        5.39339828220179 7.39339828220179,1 18,1 195)
| 15,-15 collected, join=mitre mitre_limit=2.1
    SELECT ST_AsText(ST_Collect(
        ST_OffsetCurve(geom, 15, 'quad_segs=4 join=mitre mitre_limit=2.2'),
        ST_OffsetCurve(geom, -15, 'quad_segs=4 join=mitre mitre_limit=2.2')
        ) )
        FROM ST_GeomFromText(
    'LINESTRING(164 16,144 16,124 16,104 16,84 16,64 16,
        44 16,24 16,20 16,18 16,17 17,
        16 18,16 20,16 40,16 60,16 80,16 100,
        16 120,16 140,16 160,16 180,16 195)') As geom;
    -- output --
    MULTILINESTRING((164 1,11.7867965644036 1,1 11.7867965644036,1 195),
        (31 195,31 31,164 31))

### See Also

ST_Buffer

ST_PointOnSurface

Returns a point guaranteed to lie in a polygon or on a geometry.

                geometry ST_PointOnSurface

                geometry
                g1

### Description

Returns a `POINT` guaranteed to intersect a surface.

&sfs_compliant; s3.2.14.2 // s3.2.18.2

&sqlmm_compliant; SQL-MM 3: 8.1.5, 9.5.6. According to the specs, ST_PointOnSurface works for surface geometries (POLYGONs, MULTIPOLYGONS, CURVED POLYGONS). So PostGIS seems to be extending what the spec allows here. Most databases Oracle,DB II, ESRI SDE seem to only support this function for surfaces. SQL Server 2008 like PostGIS supports for all common geometries.

&Z_support;

### Examples

    SELECT ST_AsText(ST_PointOnSurface('POINT(0 5)'::geometry));
     st_astext
    ------------
     POINT(0 5)
    (1 row)

    SELECT ST_AsText(ST_PointOnSurface('LINESTRING(0 5, 0 10)'::geometry));
     st_astext
    ------------
     POINT(0 5)
    (1 row)

    SELECT ST_AsText(ST_PointOnSurface('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'::geometry));
       st_astext
    ----------------
     POINT(2.5 2.5)
    (1 row)

    SELECT ST_AsEWKT(ST_PointOnSurface(ST_GeomFromEWKT('LINESTRING(0 5 1, 0 0 1, 0 10 2)')));
       st_asewkt
    ----------------
     POINT(0 0 1)
    (1 row)

### See Also

ST_Centroid, ST_PointInsideCircle

ST_Polygonize

Computes a collection of polygons formed from the linework of a set of geometries.

                geometry ST_Polygonize
                geometry set geomfield

                geometry ST_Polygonize
                geometry[] geom_array

### Description

Creates a GeometryCollection containing the polygons formed by the constituent linework of a set of geometries. Input linework must be correctly noded for this function to work properly.

To ensure input is fully noded use ST_Node on the input geometry before polygonizing.

GeometryCollections are often difficult to deal with with third party tools. Use ST_Dump to convert the polygonize result into separate polygons.

Performed by the GEOS module.

Availability: 1.0.0RC1

### Examples: Polygonizing single linestrings

    SELECT ST_AsEWKT(ST_Polygonize(the_geom_4269)) As geomtextrep
    FROM (SELECT the_geom_4269 FROM ma.suffolk_edges ORDER BY tlid LIMIT 45) As foo;

    geomtextrep
    -------------------------------------
     SRID=4269;GEOMETRYCOLLECTION(POLYGON((-71.040878 42.285678,-71.040943 42.2856,-71.04096 42.285752,-71.040878 42.285678)),
     POLYGON((-71.17166 42.353675,-71.172026 42.354044,-71.17239 42.354358,-71.171794 42.354971,-71.170511 42.354855,
     -71.17112 42.354238,-71.17166 42.353675)))
    (1 row)

    --Use ST_Dump to dump out the polygonize geoms into individual polygons
    SELECT ST_AsEWKT((ST_Dump(foofoo.polycoll)).geom) As geomtextrep
    FROM (SELECT ST_Polygonize(the_geom_4269) As polycoll
        FROM (SELECT the_geom_4269 FROM ma.suffolk_edges
            ORDER BY tlid LIMIT 45) As foo) As foofoo;

    geomtextrep
    ------------------------
     SRID=4269;POLYGON((-71.040878 42.285678,-71.040943 42.2856,-71.04096 42.285752,
    -71.040878 42.285678))
     SRID=4269;POLYGON((-71.17166 42.353675,-71.172026 42.354044,-71.17239 42.354358
    ,-71.171794 42.354971,-71.170511 42.354855,-71.17112 42.354238,-71.17166 42.353675))
    (2 rows)

### See Also

ST_Node, ST_Dump

ST_ReducePrecision

Returns a valid geometry with all points rounded to the provided grid tolerance.

                geometry ST_ReducePrecision

                geometry
                g
                float8
                gridsize

### Description

Returns a valid geometry with all points rounded to the provided grid tolerance, and features below the tolerance removed.

Unlike ST_SnapToGrid the returned geometry will be valid, with no ring self-intersections or collapsed components.

Availability: 3.1.0 - requires GEOS >= 3.9.0.

### Examples

    SELECT ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 0.1));
        st_astext
    -----------------
     POINT(1.4 19.3)

    SELECT ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 1.0));
      st_astext
    -------------
     POINT(1 19)

     SELECT ST_AsText(ST_ReducePrecision('POINT(1.412 19.323)', 10));
      st_astext
    -------------
     POINT(0 20)

### See Also

ST_SnapToGrid, ST_Simplify, ST_SimplifyVW

ST_SharedPaths

Returns a collection containing paths shared by the two input linestrings/multilinestrings.

                geometry ST_SharedPaths
                geometry lineal1
                geometry lineal2

### Description

Returns a collection containing paths shared by the two input geometries. Those going in the same direction are in the first element of the collection, those going in the opposite direction are in the second element. The paths themselves are given in the direction of the first geometry.

Performed by the GEOS module.

Availability: 2.0.0

### Examples: Finding shared paths

A multilinestring and a linestring
The shared path of multilinestring and linestring overlaid with original geometries.
     SELECT ST_AsText(
      ST_SharedPaths(
        ST_GeomFromText('MULTILINESTRING((26 125,26 200,126 200,126 125,26 125),
           (51 150,101 150,76 175,51 150))'),
        ST_GeomFromText('LINESTRING(151 100,126 156.25,126 125,90 161, 76 175)')
        )
      ) As wkt

                                    wkt
    -------------------------------------------------------------
    GEOMETRYCOLLECTION(MULTILINESTRING((126 156.25,126 125),
     (101 150,90 161),(90 161,76 175)),MULTILINESTRING EMPTY)
    -- same example but linestring orientation flipped
    SELECT ST_AsText(
      ST_SharedPaths(
       ST_GeomFromText('LINESTRING(76 175,90 161,126 125,126 156.25,151 100)'),
       ST_GeomFromText('MULTILINESTRING((26 125,26 200,126 200,126 125,26 125),
           (51 150,101 150,76 175,51 150))')
        )
      ) As wkt

                                    wkt
    -------------------------------------------------------------
    GEOMETRYCOLLECTION(MULTILINESTRING EMPTY,
    MULTILINESTRING((76 175,90 161),(90 161,101 150),(126 125,126 156.25)))

### See Also

ST_Dump, ST_GeometryN, ST_NumGeometries

ST_Simplify

Returns a simplified version of a geometry, using the Douglas-Peucker algorithm.

                geometry ST_Simplify
                geometry geomA
                float tolerance
                boolean preserveCollapsed

### Description

Returns a "simplified" version of the given geometry using the Douglas-Peucker algorithm. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.

The "preserve collapsed" flag will retain objects that would otherwise be too small given the tolerance. For example, a 1m long line simplified with a 10m tolerance. If the preserve flag is given, the line will not disappear. This flag is useful for rendering engines, to avoid having large numbers of very small objects disappear from a map leaving surprising gaps.

Note that returned geometry might lose its simplicity (see ST_IsSimple)

Note topology may not be preserved and may result in invalid geometries. Use (see ST_SimplifyPreserveTopology) to preserve topology.

Availability: 1.2.2

### Examples

A circle simplified too much becomes a triangle, medium an octagon,

    SELECT ST_Npoints(the_geom) AS np_before,
           ST_NPoints(ST_Simplify(the_geom,0.1)) AS np01_notbadcircle,
           ST_NPoints(ST_Simplify(the_geom,0.5)) AS np05_notquitecircle,
           ST_NPoints(ST_Simplify(the_geom,1)) AS np1_octagon,
           ST_NPoints(ST_Simplify(the_geom,10)) AS np10_triangle,
           (ST_Simplify(the_geom,100) is null) AS  np100_geometrygoesaway
      FROM
        (SELECT ST_Buffer('POINT(1 3)', 10,12) As the_geom) AS foo;

     np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_triangle | np100_geometrygoesaway
    -----------+-------------------+---------------------+-------------+---------------+------------------------
            49 |                33 |                  17 |           9 |             4 | t

### See Also

ST_IsSimple, ST_SimplifyPreserveTopology, Topology TP_ST_Simplify

ST_SimplifyPreserveTopology

Returns a simplified and valid version of a geometry, using the Douglas-Peucker algorithm.

                geometry ST_SimplifyPreserveTopology
                geometry geomA
                float tolerance

### Description

Returns a "simplified" version of the given geometry using the Douglas-Peucker algorithm. Will avoid creating derived geometries (polygons in particular) that are invalid. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.

Performed by the GEOS module.

Availability: 1.3.3

### Examples

Same example as Simplify, but we see Preserve Topology prevents oversimplification. The circle can at most become a square.

    SELECT ST_Npoints(the_geom) As np_before, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,0.1)) As np01_notbadcircle, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,0.5)) As np05_notquitecircle,
    ST_NPoints(ST_SimplifyPreserveTopology(the_geom,1)) As np1_octagon, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,10)) As np10_square,
    ST_NPoints(ST_SimplifyPreserveTopology(the_geom,100)) As  np100_stillsquare
    FROM (SELECT ST_Buffer('POINT(1 3)', 10,12) As the_geom) As foo;

    --result--
     np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_square | np100_stillsquare
    -----------+-------------------+---------------------+-------------+---------------+-------------------
            49 |                33 |                  17 |           9 |             5 |                 5

### See Also

ST_Simplify

ST_SimplifyVW

Returns a simplified version of a geometry, using the Visvalingam-Whyatt algorithm

                geometry ST_SimplifyVW
                geometry geomA
                float tolerance

### Description

Returns a "simplified" version of the given geometry using the Visvalingam-Whyatt algorithm. Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.

Note that returned geometry might lose its simplicity (see ST_IsSimple)

Note topology may not be preserved and may result in invalid geometries. Use (see ST_SimplifyPreserveTopology) to preserve topology.

This function handles 3D and the third dimension will affect the result.

Availability: 2.2.0

### Examples

A LineString is simplified with a minimum area threshold of 30.

    select ST_AsText(ST_SimplifyVW(geom,30)) simplified
    FROM (SELECT  'LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)'::geometry geom) As foo;
    -result
     simplified
    ------------------------------
    LINESTRING(5 2,7 25,10 10)

### See Also

ST_SetEffectiveArea, ST_Simplify, ST_SimplifyPreserveTopology, Topology TP_ST_Simplify

ST_ChaikinSmoothing

Returns a smoothed version of a geometry, using the Chaikin algorithm

                geometry ST_ChaikinSmoothing
                geometry geom
                integer nIterations = 1
                boolean preserveEndPoints = false

### Description

Returns a "smoothed" version of the given geometry using the Chaikin algorithm. See Chaikins-Algorithm for an explanation of the process. For each iteration the number of vertex points will double. The function puts new vertex points at 1/4 of the line before and after each point and removes the original point. To reduce the number of points use one of the simplification functions on the result. The new points gets interpolated values for all included dimensions, also z and m.

Second argument, number of iterations is limited to max 5 iterations

Note third argument is only valid for polygons, and will be ignored for linestrings

This function handles 3D and the third dimension will affect the result.

Note that returned geometry will get more points than the original. To reduce the number of points again use one of the simplification functions on the result. (see ST_Simplify and ST_SimplifyVW)

Availability: 2.5.0

### Examples

A triangle is smoothed

    select ST_AsText(ST_ChaikinSmoothing(geom)) smoothed
    FROM (SELECT  'POLYGON((0 0, 8 8, 0 16, 0 0))'::geometry geom) As foo;
    ┌───────────────────────────────────────────┐
    │                 smoothed                  │
    ├───────────────────────────────────────────┤
    │ POLYGON((2 2,6 6,6 10,2 14,0 12,0 4,2 2)) │
    └───────────────────────────────────────────┘

### See Also

ST_Simplify, ST_SimplifyVW

ST_SetEffectiveArea

Sets the effective area for each vertex, using the Visvalingam-Whyatt algorithm.

                geometry ST_SetEffectiveArea
                geometry geomA
                float threshold = 0
                integer set_area = 1

### Description

Sets the effective area for each vertex, using the Visvalingam-Whyatt algorithm. The effective area is stored as the M-value of the vertex. If the optional "theshold" parameter is used, a simplified geometry will be returned, containing only vertices with an effective area greater than or equal to the threshold value.

This function can be used for server-side simplification when a threshold is specified. Another option is to use a threshold value of zero. In this case, the full geometry will be returned with effective areas as M-values, which can be used by the client to simplify very quickly.

Will actually do something only with (multi)lines and (multi)polygons but you can safely call it with any kind of geometry. Since simplification occurs on a object-by-object basis you can also feed a GeometryCollection to this function.

Note that returned geometry might lose its simplicity (see ST_IsSimple)

Note topology may not be preserved and may result in invalid geometries. Use (see ST_SimplifyPreserveTopology) to preserve topology.

The output geometry will lose all previous information in the M-values

This function handles 3D and the third dimension will affect the effective area

Availability: 2.2.0

### Examples

Calculating the effective area of a LineString. Because we use a threshold value of zero, all vertices in the input geometry are returned.

    select ST_AsText(ST_SetEffectiveArea(geom)) all_pts, ST_AsText(ST_SetEffectiveArea(geom,30) ) thrshld_30
    FROM (SELECT  'LINESTRING(5 2, 3 8, 6 20, 7 25, 10 10)'::geometry geom) As foo;
    -result
     all_pts | thrshld_30
    -----------+-------------------+
    LINESTRING M (5 2 3.40282346638529e+38,3 8 29,6 20 1.5,7 25 49.5,10 10 3.40282346638529e+38) | LINESTRING M (5 2 3.40282346638529e+38,7 25 49.5,10 10 3.40282346638529e+38)

### See Also

ST_SimplifyVW

ST_VoronoiLines

Returns the boundaries of the Voronoi diagram of the vertices of a geometry.

                geometry ST_VoronoiLines

                    g1
                    geometry

                    tolerance
                    float8

                    extend_to
                    geometry

### Description

ST_VoronoiLines computes a two-dimensional Voronoi diagram from the vertices of the supplied geometry and returns the boundaries between cells in that diagram as a MultiLineString. Returns null if input geometry is null. Returns an empty geometry collection if the input geometry contains only one vertex. Returns an empty geometry collection if the extend_to envelope has zero area.

Optional parameters:

- 'tolerance' : The distance within which vertices will be considered equivalent. Robustness of the algorithm can be improved by supplying a nonzero tolerance distance. (default = 0.0)

- 'extend_to' : If a geometry is supplied as the "extend_to" parameter, the diagram will be extended to cover the envelope of the "extend_to" geometry, unless that envelope is smaller than the default envelope (default = NULL, default envelope is boundingbox of input geometry extended by about 50% in each direction).

Performed by the GEOS module.

Availability: 2.3.0

### Examples

Voronoi lines with tolerance of 30 units
    SELECT ST_VoronoiLines(geom, 30) As geom
    FROM (SELECT 'MULTIPOINT (50 30, 60 30, 100 100,10 150, 110 120)'::geometry As geom ) As g
     -- ST_AsText output
    MULTILINESTRING((135.555555555556 270,36.8181818181818 92.2727272727273),(36.8181818181818 92.2727272727273,-110 43.3333333333333),(230 -45.7142857142858,36.8181818181818 92.2727272727273))

### See Also

ST_DelaunayTriangles, ST_VoronoiPolygons, ST_Collect

ST_VoronoiPolygons

Returns the cells of the Voronoi diagram of the vertices of a geometry.

                geometry ST_VoronoiPolygons

                    g1
                    geometry

                    tolerance
                    float8

                    extend_to
                    geometry

### Description

ST_VoronoiPolygons computes a two-dimensional Voronoi diagram from the vertices of the supplied geometry. The result is a GeometryCollection of Polygons that covers an envelope larger than the extent of the input vertices. Returns null if input geometry is null. Returns an empty geometry collection if the input geometry contains only one vertex. Returns an empty geometry collection if the extend_to envelope has zero area.

Optional parameters:

- 'tolerance' : The distance within which vertices will be considered equivalent. Robustness of the algorithm can be improved by supplying a nonzero tolerance distance. (default = 0.0)

- 'extend_to' : If a geometry is supplied as the "extend_to" parameter, the diagram will be extended to cover the envelope of the "extend_to" geometry, unless that envelope is smaller than the default envelope (default = NULL, default envelope is boundingbox of input geometry extended by about 50% in each direction).

Performed by the GEOS module.

Availability: 2.3.0

### Examples

Points overlaid on top of Voronoi diagram
    SELECT
        ST_VoronoiPolygons(geom) As geom
    FROM (SELECT 'MULTIPOINT (50 30, 60 30, 100 100,10 150, 110 120)'::geometry As geom ) As g;
     -- ST_AsText output
    GEOMETRYCOLLECTION(POLYGON((-110 43.3333333333333,-110 270,100.5 270,59.3478260869565 132.826086956522,36.8181818181818 92.2727272727273,-110 43.3333333333333)),
    POLYGON((55 -90,-110 -90,-110 43.3333333333333,36.8181818181818 92.2727272727273,55 79.2857142857143,55 -90)),
    POLYGON((230 47.5,230 -20.7142857142857,55 79.2857142857143,36.8181818181818 92.2727272727273,59.3478260869565 132.826086956522,230 47.5)),POLYGON((230 -20.7142857142857,230 -90,55 -90,55 79.2857142857143,230 -20.7142857142857)),
    POLYGON((100.5 270,230 270,230 47.5,59.3478260869565 132.826086956522,100.5 270)))
Voronoi with tolerance of 30 units
    SELECT ST_VoronoiPolygons(geom, 30) As geom
    FROM (SELECT 'MULTIPOINT (50 30, 60 30, 100 100,10 150, 110 120)'::geometry As geom ) As g;
     -- ST_AsText output
    GEOMETRYCOLLECTION(POLYGON((-110 43.3333333333333,-110 270,100.5 270,59.3478260869565 132.826086956522,36.8181818181818 92.2727272727273,-110 43.3333333333333)),
    POLYGON((230 47.5,230 -45.7142857142858,36.8181818181818 92.2727272727273,59.3478260869565 132.826086956522,230 47.5)),POLYGON((230 -45.7142857142858,230 -90,-110 -90,-110 43.3333333333333,36.8181818181818 92.2727272727273,230 -45.7142857142858)),
    POLYGON((100.5 270,230 270,230 47.5,59.3478260869565 132.826086956522,100.5 270)))
Voronoi with tolerance of 30 units as MultiLineString
    SELECT ST_VoronoiLines(geom, 30) As geom
    FROM (SELECT 'MULTIPOINT (50 30, 60 30, 100 100,10 150, 110 120)'::geometry As geom ) As g
     -- ST_AsText output
    MULTILINESTRING((135.555555555556 270,36.8181818181818 92.2727272727273),(36.8181818181818 92.2727272727273,-110 43.3333333333333),(230 -45.7142857142858,36.8181818181818 92.2727272727273))

### See Also

ST_DelaunayTriangles, ST_VoronoiLines, ST_Collect