Geometry Processing These functions compute geometric constructions, or alter geometry size or shape. ST_Buffer Computes 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 Computes a POLYGON or MULTIPOLYGON that represents all points whose distance from a geometry/geography is less than or equal to a given distance. A negative distance shrinks the geometry rather than expanding it. A negative distance may shrink a polygon completely, in which case POLYGON EMPTY is returned. For points and lines negative distances always return empty results. For geometry, the distance is specified in the units of the Spatial Reference System of the geometry. For geography, the distance is specified in meters. The optional third parameter controls the buffer accuracy and style. The accuracy of circular arcs in the buffer is specified as the number of line segments used to approximate a quarter circle (default is 8). The buffer style can be specified by providing a list of blank-separated key=value pairs as follows: 'quad_segs=#' : number of line segments used to approximate a quarter circle (default is 8). 'endcap=round|flat|square' : endcap style (defaults to "round"). 'butt' is accepted as a synonym for 'flat'. 'join=round|mitre|bevel' : join style (defaults to "round"). 'miter' is accepted as a synonym for 'mitre'. 'mitre_limit=#.#' : mitre ratio limit (only affects mitered join style). 'miter_limit' is accepted as a synonym for 'mitre_limit'. 'side=both|left|right' : defaults to 'both'. '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 applicable to LINESTRING geometry and does not affect POINT or POLYGON geometries. By default end caps are square when 'left' or 'right' are specified. &geography_transform; It determines a planar spatial reference system that best fits the bounding box of the geography object (trying UTM, Lambert Azimuthal Equal Area (LAEA) North/South pole, and finally Mercator ). The buffer is computed in the planar space, and then transformed back to WGS84. This may not produce the desired behavior if the input object is much larger than a UTM zone or crosses the dateline Buffer can handle invalid inputs and the output is always a valid polygonal geometry. Buffering by distance 0 is sometimes used as a way of repairing invalid polygons. is more suitable for this process as it can handle multi-polygons. Buffering is sometimes used to perform a within-distance search. For this use case it is more efficient to use . This function ignores the Z dimension. It always gives a 2D result even when used on a 3D geometry. 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. Performed by the GEOS module. &sfs_compliant; s2.1.1.3 &sqlmm_compliant; SQL-MM IEC 13249-3: 5.1.30 Examples The textual results are rounded to whole coordinate units for readability. Each result remains available as text, while the manual initially favors the shared input/output figure. quad_segs=8 (default) SELECT ST_Buffer( ST_GeomFromText('POINT(100 90)'), 50, 'quad_segs=8'); POLYGON((150 90,149 80,146 71,142 62,135 55,128 48,119 44,110 41,100 40,90 41,81 44,72 48,65 55,58 62,54 71,51 80,50 90,51 100,54 109,58 118,65 125,72 132,81 136,90 139,100 140,110 139,119 136,128 132,135 125,142 118,146 109,149 100,150 90)) quad_segs=2 SELECT ST_Buffer( ST_GeomFromText('POINT(100 90)'), 50, 'quad_segs=2'); POLYGON((150 90,135 55,100 40,65 55,50 90,65 125,100 140,135 125,150 90)) endcap=round join=round (default) SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'endcap=round join=round'); POLYGON((143 157,144 158,146 159,148 160,150 160,152 160,154 159,156 158,157 157,158 156,159 154,160 152,160 150,160 50,160 48,159 46,158 44,157 43,156 42,154 41,152 40,150 40,148 40,146 41,144 42,143 43,142 44,141 46,140 48,140 50,140 126,57 43,56 42,54 41,52 40,50 40,48 40,46 41,44 42,43 43,42 44,41 46,40 48,40 50,40 52,41 54,42 56,43 57,143 157)) endcap=square SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'endcap=square join=round'); POLYGON((143 157,144 158,146 159,148 160,150 160,152 160,154 159,156 158,157 157,158 156,159 154,160 152,160 150,160 50,160 40,140 40,140 126,57 43,50 36,36 50,143 157)) endcap=flat SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'endcap=flat join=round'); POLYGON((143 157,144 158,146 159,148 160,150 160,152 160,154 159,156 158,157 157,158 156,159 154,160 152,160 150,160 50,140 50,140 126,57 43,43 57,143 157)) join=bevel SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'join=bevel'); POLYGON((143 157,160 150,160 50,160 48,159 46,158 44,157 43,156 42,154 41,152 40,150 40,148 40,146 41,144 42,143 43,142 44,141 46,140 48,140 50,140 126,57 43,56 42,54 41,52 40,50 40,48 40,46 41,44 42,43 43,42 44,41 46,40 48,40 50,40 52,41 54,42 56,43 57,143 157)) 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'); POLYGON((160 174,160 50,160 48,159 46,158 44,157 43,156 42,154 41,152 40,150 40,148 40,146 41,144 42,143 43,142 44,141 46,140 48,140 50,140 126,57 43,56 42,54 41,52 40,50 40,48 40,46 41,44 42,43 43,42 44,41 46,40 48,40 50,40 52,41 54,42 56,43 57,160 174)) join=mitre mitre_limit=1 SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'join=mitre mitre_limit=1.0'); POLYGON((148 162,160 157,160 50,160 48,159 46,158 44,157 43,156 42,154 41,152 40,150 40,148 40,146 41,144 42,143 43,142 44,141 46,140 48,140 50,140 126,57 43,56 42,54 41,52 40,50 40,48 40,46 41,44 42,43 43,42 44,41 46,40 48,40 50,40 52,41 54,42 56,43 57,148 162)) side=left SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'side=left'); POLYGON((150 50,150 150,50 50,43 57,143 157,144 158,146 159,148 160,150 160,152 160,154 159,156 158,157 157,158 156,159 154,160 152,160 150,160 50,150 50)) side=right SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'side=right'); POLYGON((50 50,150 150,150 50,140 50,140 126,57 43,50 50)) side=left join=mitre SELECT ST_Buffer( ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'side=left join=mitre'); POLYGON((150 50,150 150,50 50,43 57,160 174,160 50,150 50)) 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'); POLYGON((50 50,50 150,150 150,150 50,50 50)) 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'); POLYGON((50 50,50 70,50 150,150 150,150 50,70 50,50 50),(70 70,130 70,130 130,70 130,70 70)) 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('POINT(100 90)'::geometry, 50)) As promisingcircle_pcount, ST_NPoints(ST_Buffer('POINT(100 90)'::geometry, 50, 2)) As lamecircle_pcount; promisingcircle_pcount | lamecircle_pcount ------------------------+------------------- 33 | 9 A lighter, less smooth circle using only 2 points per quarter circle is an octagon. The following example creates a 100 meter octagon in NAD83 longitude/latitude by transforming to the Massachusetts state plane meter projection and then buffering. The figure shows the input and output in separate panels because the coordinates are in different SRIDs. WITH input AS ( SELECT ST_SetSRID(ST_Point(-71.063526, 42.35785), 4269) AS point_4269 ), projected AS ( SELECT point_4269, ST_Transform(point_4269, 26986) AS point_26986 FROM input ) SELECT point_4269 AS input_point_4269, ST_Buffer(point_26986, 100, 2) AS octagon_26986 FROM projected; SRID=4269;POINT(-71.063526 42.35785) | SRID=26986;POLYGON((236057.5905746494 900908.7599186979,236028.30125276805 900838.0492405792,235957.5905746494 900808.7599186979,235886.87989653074 900838.0492405792,235857.5905746494 900908.7599186979,235886.87989653074 900979.4705968165,235957.5905746494 901008.7599186979,236028.30125276805 900979.4705968165,236057.5905746494 900908.7599186979)) Buffering a polygon by a positive distance and then by the same negative distance is a morphological closing operation. It can be useful for smoothing noisy boundaries, such as simplifying a coastline by removing narrow inlets and bays. The result intentionally changes the shape and area of the input, and the distance must be chosen in the units of the input SRS. For data in a geographic SRS, transform to a projected SRS suited to the operation first; for cartographic visualization in Web Mercator, using that display SRS can be appropriate. Smooth a coastline using a 1 km closing operation, then simplify the result. The example uses Massachusetts State Plane meter units for the operation. WITH projected AS ( SELECT id, ST_Transform(geom, 26986) AS geom FROM coast ), closed AS ( SELECT id, ST_Buffer(ST_Buffer(geom, 1000), -1000) AS geom FROM projected ) SELECT id, ST_Transform(ST_SimplifyPreserveTopology(geom, 50), 4326) AS geom FROM closed; The same technique is described in Paul Ramsey's Removing Complexities. The final simplification step is optional; use when polygonal validity matters, and check the result against the cartographic or analytical tolerance required by the application. A small negative buffer can also be used as a heuristic to find narrow polygon spikes. The query below compares how much area and perimeter remain after erosion. A large erosion_index indicates that the perimeter dropped proportionally more than the area. This is only a preselection aid; the threshold and buffer distance must be chosen for the data units and the kind of spike being checked. WITH sample(id, geom) AS ( VALUES ('plain', 'POLYGON((0 0,10 0,10 10,0 10,0 0))'::geometry), ('spike', 'POLYGON((0 0,10 0,10 10,5.2 10,5 16,4.8 10,0 10,0 0))'::geometry) ), eroded AS ( SELECT id, geom, ST_Buffer(geom, -0.5) AS eroded_geom FROM sample ), scored AS ( SELECT id, round(( ST_Area(eroded_geom) / ST_Area(geom) / NULLIF(ST_Perimeter(eroded_geom) / ST_Perimeter(geom), 0) )::numeric, 3) AS erosion_index FROM eroded WHERE NOT ST_IsEmpty(eroded_geom) ) SELECT id, erosion_index, erosion_index > 1.1 AS possible_spike FROM scored ORDER BY id; id | erosion_index | possible_spike -------+---------------+---------------- plain | 0.900 | f spike | 1.147 | t A variable-distance buffer can be approximated by buffering each vertex of a line by a distance interpolated along the line, building the convex hull for each consecutive pair of vertex buffers, and unioning the segment hulls. As with any geometry buffer, distances are in the units of the input SRS. Taper a line buffer from 5 to 25 units along the line. WITH line AS ( SELECT 'LINESTRING(0 0, 100 0, 160 40)'::geometry AS geom ), vertices AS ( SELECT (dump).path[1] AS n, (dump).geom AS geom, line.geom AS line_geom FROM line CROSS JOIN LATERAL ST_DumpPoints(line.geom) AS dump ), radii AS ( SELECT n, geom, 5 + (25 - 5) * ST_LineLocatePoint(line_geom, geom) AS radius FROM vertices ), segments AS ( SELECT n, geom, radius, lead(geom) OVER (ORDER BY n) AS next_geom, lead(radius) OVER (ORDER BY n) AS next_radius FROM radii ) SELECT ST_Union( ST_ConvexHull( ST_Collect( ST_Buffer(geom, radius), ST_Buffer(next_geom, next_radius) ) ) ) AS tapered_buffer FROM segments WHERE next_geom IS NOT NULL; POLYGON((96.758 -16.301,-0.975 -4.904,-1.913 -4.619,-2.778 -4.157,-3.536 -3.536,-4.157 -2.778,-4.619 -1.913,-4.904 -0.975,-5 0,-4.904 0.975,-4.619 1.913,-4.157 2.778,-3.536 3.536,-2.778 4.157,-1.913 4.619,-0.975 4.904,93.101 15.875,142.322 57.678,146.111 60.787,150.433 63.097,155.123 64.52,160 65,164.877 64.52,169.567 63.097,173.889 60.787,177.678 57.678,180.787 53.889,183.097 49.567,184.52 44.877,185 40,184.52 35.123,183.097 30.433,180.787 26.111,177.678 22.322,173.889 19.213,169.567 16.903,106.36 -15.355,103.242 -16.301,100 -16.62,96.758 -16.301)) See Also , , , , , , , , , 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 a LineString, MultiLineString, Polygon, MultiPolygon or a GeometryCollection. The result is a Polygon or MultiPolygon, depending on input. If the input linework does not form polygons, NULL is returned. Unlike , this function accepts rings formed by multiple lines, and can form any number of polygons. This function converts inner rings into holes. To turn inner rings into polygons as well, use . Input linework must be correctly noded for this function to work properly. can be used to node lines. If the input linework crosses, this function will produce invalid polygons. can be used to ensure the output is valid. Availability: 1.1.0 Examples Building an area from five input lines. WITH data(geom) AS (VALUES ('LINESTRING (180 40,30 20,20 90)'::geometry), ('LINESTRING (180 40,160 160)'::geometry), ('LINESTRING (160 160,80 190,80 120,20 90)'::geometry), ('LINESTRING (80 60,120 130,150 80)'::geometry), ('LINESTRING (80 60,150 80)'::geometry) ) SELECT ST_BuildArea(ST_Collect(geom )) AS wkt FROM data; POLYGON((180 40,30 20,20 90,80 120,80 190,160 160,180 40),(150 80,120 130,80 60,150 80)) Create a donut from two circular polygons. WITH input AS ( SELECT 'POINT(100 90)'::geometry AS geom ), rings AS ( SELECT ST_Buffer(geom, 25, 'quad_segs=1') AS inring, ST_Buffer(geom, 50, 'quad_segs=1') AS outring FROM input ) SELECT inring AS inner_ring, outring AS outer_ring, ST_BuildArea(ST_Collect(inring, outring)) AS area FROM rings; -[ RECORD 1 ]----- inner_ring | POLYGON((125 90,100 65,75 90,100 115,125 90)) outer_ring | POLYGON((150 90,100 40,50 90,100 140,150 90)) area | POLYGON((150 90,100 40,50 90,100 140,150 90),(125 90,100 115,75 90,100 65,125 90)) Input linework that crosses at non-endpoint intersections must be noded before building areas: WITH lines(geom) AS (VALUES ('LINESTRING(36 35,45 307)'::geometry), ('LINESTRING(30 290,390 280)'::geometry), ('LINESTRING(320 60,300 310)'::geometry), ('LINESTRING(20 60,320 60)'::geometry), ('LINESTRING(120 140,168 225)'::geometry), ('LINESTRING(140 220,220 150,120 170)'::geometry) ), noded AS ( SELECT ST_Node(ST_UnaryUnion(ST_Collect(geom))) AS geom FROM lines ) SELECT ST_BuildArea(geom) AS area FROM noded; POLYGON((320 60,36.8 60,44.4 289.6,302.2 282.4,320 60),(156.9 205.3,135.2 167,220 150,156.9 205.3)) See Also , , , , , , (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]POINTs, the centroid is the arithmetic mean of the input coordinates. For [MULTI]LINESTRINGs, the centroid is computed using the weighted length of each line segment. For [MULTI]POLYGONs, 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 with 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). Note that for polygonal geometries the centroid does not necessarily lie in the interior of the polygon. For example, see the diagram below of the centroid of a C-shaped polygon. To construct a point guaranteed to lie in the interior of a polygon use . New in 2.3.0 : supports 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 Centroid of a MultiPoint. SELECT ST_Centroid( 'MULTIPOINT (8 24,10 92,12 154,17 68,28 10,29 52,29 84,55 50,56 24,131 14,160 180,189 180)'); POINT(60.333 77.667) Centroid of a LineString. SELECT ST_Centroid( 'LINESTRING (190 160,10 190,40 90,20 70,10 10,30 40,30 10,110 40,70 10,110 10,140 40,140 10,160 30,180 10)'); POINT(76.191 79.876) Centroid of a Polygon. SELECT ST_Centroid( 'POLYGON ((190 190,10 190,10 10,190 10,190 20,160 30,60 30,60 130,190 140,190 190))'); POINT(80.251 113.405) Centroid of the highest-dimension components of a GeometryCollection. SELECT ST_Centroid( 'GEOMETRYCOLLECTION (POLYGON ((190 170,180 100,80 140,80 160,130 160,110 180,110 190,180 180,190 170)), LINESTRING (80 120,120 20,140 70,150 30,180 50,190 10), MULTIPOINT (19 150,22 49,30 13,32 101,45 35,67 88,75 16))'); POINT(143.361 148.263) SELECT 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 ; st_astext ------------- POINT(0.5 1) (1 row) SELECT 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; st_astext ------------- POINT(0.5 1) (1 row) Centroids of the parts of a MultiPolygon. SELECT ST_Collect(ST_Centroid(geom) ORDER BY path) FROM ST_Dump('MULTIPOLYGON ( ((0 0,0 1,1 1,1 0,0 0)), ((2 2,2 3,3 3,3 2,2 2)) )'::geometry); MULTIPOINT((0.5 0.5),(2.5 2.5)) See Also , , , 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 Smoothes a linear or polygonal geometry using Chaikin's algorithm. The degree of smoothing is controlled by the nIterations parameter. On each iteration, each interior vertex is replaced by two vertices located at 1/4 of the length of the line segments before and after the vertex. A reasonable degree of smoothing is provided by 3 iterations; the maximum is limited to 5. If preserveEndPoints is true, the endpoints of Polygon rings are not smoothed. The endpoints of LineStrings are always preserved. The number of vertices doubles with each iteration, so the result geometry may have many more points than the input. To reduce the number of points use a simplification function on the result (see , and ). The result has interpolated values for the Z and M dimensions when present. &Z_support; Availability: 2.5.0 Examples Smoothing a Polygon using 1, 2 and 3 iterations. SELECT n AS iterations, ST_ChaikinSmoothing( 'POLYGON ((20 20,60 90,10 150,100 190,190 160,130 120,190 50,140 70,120 10,90 60,20 20))', n ) AS smoothed FROM generate_series(1, 3) AS n; 1 | POLYGON((30 37.5,50 72.5,47.5 105,22.5 135,32.5 160,77.5 180,122.5 182.5,167.5 167.5,175 150,145 130,145 102.5,175 67.5,177.5 55,152.5 65,135 55,125 25,112.5 22.5,97.5 47.5,72.5 50,37.5 30,30 37.5)) 2 | POLYGON((35 46.25,45 63.75,49.375 80.625,48.125 96.875,41.25 112.5,28.75 127.5,25 141.25,30 153.75,43.75 165,66.25 175,88.75 180.625,111.25 181.875,133.75 178.75,156.25 171.25,169.375 163.125,173.125 154.375,167.5 145,152.5 135,145 123.125,145 109.375,152.5 93.75,167.5 76.25,175.625 64.375,176.875 58.125,171.25 57.5,158.75 62.5,148.125 62.5,139.375 57.5,132.5 47.5,127.5 32.5,121.875 24.375,115.625 23.125,108.75 28.75,101.25 41.25,91.25 48.125,78.75 49.375,63.75 45,46.25 35,35.625 31.875,31.875 35.625,35 46.25)) 3 | POLYGON((37.5 50.625,42.5 59.375,46.09375 67.96875,48.28125 76.40625,49.0625 84.6875,48.4375 92.8125,46.40625 100.78125,42.96875 108.59375,38.125 116.25,31.875 123.75,27.8125 130.9375,25.9375 137.8125,26.25 144.375,28.75 150.625,33.4375 156.5625,40.3125 162.1875,49.375 167.5,60.625 172.5,71.875 176.40625,83.125 179.21875,94.375 180.9375,105.625 181.5625,116.875 181.09375,128.125 179.53125,139.375 176.875,150.625 173.125,159.53125 169.21875,166.09375 165.15625,170.3125 160.9375,172.1875 156.5625,171.71875 152.03125,168.90625 147.34375,163.75 142.5,156.25 137.5,150.625 132.03125,146.875 126.09375,145 119.6875,145 112.8125,146.875 105.46875,150.625 97.65625,156.25 89.375,163.75 80.625,169.53125 73.28125,173.59375 67.34375,175.9375 62.8125,176.5625 59.6875,175.46875 57.96875,172.65625 57.65625,168.125 58.75,161.875 61.25,156.09375 62.5,150.78125 62.5,145.9375 61.25,141.5625 58.75,137.65625 55,134.21875 50,131.25 43.75,128.75 36.25,126.09375 30.46875,123.28125 26.40625,120.3125 24.0625,117.1875 23.4375,113.90625 24.53125,110.46875 27.34375,106.875 31.875,103.125 38.125,98.75 42.96875,93.75 46.40625,88.125 48.4375,81.875 49.0625,75 48.28125,67.5 46.09375,59.375 42.5,50.625 37.5,43.59375 34.21875,38.28125 32.65625,34.6875 32.8125,32.8125 34.6875,32.65625 38.28125,34.21875 43.59375,37.5 50.625)) Smoothing a LineString using 1, 2 and 3 iterations. SELECT n AS iterations, ST_ChaikinSmoothing( 'LINESTRING (10 140,80 130,100 190,190 150,140 20,120 120,50 30,30 100)', n ) AS smoothed FROM generate_series(1, 3) AS n; 1 | LINESTRING(10 140,62.5 132.5,85 145,95 175,122.5 180,167.5 160,177.5 117.5,152.5 52.5,135 45,125 95,102.5 97.5,67.5 52.5,45 47.5,30 100) 2 | LINESTRING(10 140,49.375 134.375,68.125 135.625,79.375 141.875,87.5 152.5,92.5 167.5,101.875 176.25,115.625 178.75,133.75 175,156.25 165,170 149.375,175 128.125,171.25 101.25,158.75 68.75,148.125 50.625,139.375 46.875,132.5 57.5,127.5 82.5,119.375 95.625,108.125 96.875,93.75 86.25,76.25 63.75,61.875 51.25,50.625 48.75,41.25 60.625,30 100) 3 | LINESTRING(10 140,39.53125 135.78125,54.0625 134.6875,63.4375 135.3125,70.9375 137.1875,76.5625 140.3125,81.40625 144.53125,85.46875 149.84375,88.75 156.25,91.25 163.75,94.84375 169.6875,99.53125 174.0625,105.3125 176.875,112.1875 178.125,120.15625 177.8125,129.21875 175.9375,139.375 172.5,150.625 167.5,159.6875 161.09375,166.5625 153.28125,171.25 144.0625,173.75 133.4375,174.0625 121.40625,172.1875 107.96875,168.125 93.125,161.875 76.875,156.09375 64.21875,150.78125 55.15625,145.9375 49.6875,141.5625 47.8125,137.65625 49.53125,134.21875 54.84375,131.25 63.75,128.75 76.25,125.46875 85.78125,121.40625 92.34375,116.5625 95.9375,110.9375 96.5625,104.53125 94.21875,97.34375 88.90625,89.375 80.625,80.625 69.375,72.65625 60.625,65.46875 54.375,59.0625 50.625,53.4375 49.375,48.28125 51.71875,43.59375 57.65625,38.4375 70.46875,30 100) Smoothing a triangle shows the weakest visual change, so it is kept last. SELECT ST_ChaikinSmoothing(geom) smoothed FROM (SELECT 'POLYGON((0 0,8 8,0 16,0 0))'::geometry geom) AS foo; POLYGON((2 2,6 6,6 10,2 14,0 12,0 4,2 2)) See Also , , ST_CatmullRomSmoothing Returns a smoothed version of a geometry, using the Catmull-Rom spline algorithm geometry ST_CatmullRomSmoothing geometry geom integer nSegments = 5 Description Smoothes a linear or polygonal geometry using the Catmull-Rom spline algorithm. Unlike , this is an interpolating spline: the output curve passes through every original vertex. Between each pair of consecutive original vertices, nSegments - 1 new intermediate points are inserted. The nSegments parameter controls the density of the output. With nSegments = 5 (the default), each original span is divided into 5 sub-segments (inserting 4 new points per span). The minimum value is 2. At least 4 input vertices are required to apply smoothing; geometries with fewer vertices are returned unchanged. Points and multipoints are always returned unchanged. The output vertex count grows as 1 + (N-1) * nSegments for open lines, and 1 + N * nSegments for closed rings, where N is the number of input vertices. For large geometries, use a simplification function on the result to reduce the number of points (see , and ). The result has interpolated values for the Z and M dimensions when present. &Z_support; Availability: 3.7.0 Examples Smoothing a LineString using nSegments = 5 and 10. WITH input(geom) AS (VALUES ('LINESTRING (10 140,80 130,100 190,190 150,140 20,120 120,50 30,30 100)'::geometry) ) SELECT ST_CatmullRomSmoothing(geom, 5) AS segments_5, ST_CatmullRomSmoothing(geom, 10) AS segments_10 FROM input; LINESTRING(10 140,24.8 136.88,40.4 132.64,55.6 128.96,69.2 127.52,80 130,86.08 139.12,88.24 153.76,89.36 169.84,92.32 183.28,100 190,115.76 189.84,137.68 185.52,160.72 177.28,179.84 165.36,190 150,188.48 126.08,178.64 93.44,164.56 59.76,150.32 32.72,140 20,134.88 28.32,132.24 52.56,130.16 82.64,126.72 108.48,120 120,108.4 111.6,93.2 90,76.8 63.6,61.6 40.8,50 30,42.8 33.76,38.4 46.48,35.6 64.32,33.2 83.44,30 100) | LINESTRING(10 140,17.225 138.685,24.8 136.88,32.575 134.795,40.4 132.64,48.125 130.625,55.6 128.96,62.675 127.855,69.2 127.52,75.025 128.165,80 130,83.71 133.615,86.08 139.12,87.47 146.005,88.24 153.76,88.75 161.875,89.36 169.84,90.43 177.145,92.32 183.28,95.39 187.735,100 190,106.795 190.455,115.76 189.84,126.265 188.185,137.68 185.52,149.375 181.875,160.72 177.28,171.085 171.765,179.84 165.36,186.355 158.095,190 150,190.535 139.61,188.48 126.08,184.345 110.37,178.64 93.44,171.875 76.25,164.56 59.76,157.205 44.93,150.32 32.72,144.415 24.09,140 20,137.01 21.54,134.88 28.32,133.37 39.08,132.24 52.56,131.25 67.5,130.16 82.64,128.73 96.72,126.72 108.48,123.89 116.66,120 120,114.8 117.975,108.4 111.6,101.1 101.925,93.2 90,85 76.875,76.8 63.6,68.9 51.225,61.6 40.8,55.2 33.375,50 30,45.975 30.52,42.8 33.76,40.325 39.24,38.4 46.48,36.875 55,35.6 64.32,34.425 73.96,33.2 83.44,31.775 92.28,30 100) Smoothing a 4-point collinear line with default nSegments=5 shows the minimal change case. SELECT ST_CatmullRomSmoothing('LINESTRING(0 0,5 0,10 0,15 0)'); LINESTRING(0 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0,10 0,11 0,12 0,13 0,14 0,15 0) Smoothing a Polygon using nSegments = 5 and 10. This larger example is kept last. WITH input(geom) AS (VALUES ('POLYGON ((20 20,60 90,10 150,100 190,190 160,130 120,190 50,140 70,120 10,90 60,20 20))'::geometry) ) SELECT ST_CatmullRomSmoothing(geom, 5) AS segments_5, ST_CatmullRomSmoothing(geom, 10) AS segments_10 FROM input; POLYGON((20 20,22.4 27.12,32.4 40.56,45.2 57.44,56 74.88,60 90,53.52 102.96,39.76 115.68,24.24 127.92,12.48 139.44,10 150,19.04 160.4,35.92 170.8,57.28 180,79.76 186.8,100 190,120.4 188.64,143.2 183.52,164.8 176.08,181.6 167.76,190 160,185.68 153.12,171.04 146.16,152.56 138.64,136.72 130.08,130 120,136.08 106.48,150.64 89.84,168.16 72.96,183.12 58.72,190 50,186.56 49.52,176.48 55.36,163.12 63.44,149.84 69.68,140 70,134.24 61.36,130.32 46.48,127.28 29.92,124.16 16.24,120 10,115.28 14.4,110.64 26.4,105.36 41.2,98.72 54,90 60,76.8 56,59.6 45.2,42 32.4,27.6 22.4,20 20)) | POLYGON((20 20,19.95 22.59,22.4 27.12,26.75 33.23,32.4 40.56,38.75 48.75,45.2 57.44,51.15 66.27,56 74.88,59.15 82.91,60 90,58.015 96.495,53.52 102.96,47.205 109.365,39.76 115.68,31.875 121.875,24.24 127.92,17.545 133.785,12.48 139.44,9.735 144.855,10 150,13.33 155.125,19.04 160.4,26.71 165.675,35.92 170.8,46.25 175.625,57.28 180,68.59 183.775,79.76 186.8,90.37 188.925,100 190,109.675 189.88,120.4 188.64,131.725 186.46,143.2 183.52,154.375 180,164.8 176.08,174.025 171.94,181.6 167.76,187.075 163.72,190 160,189.535 156.54,185.68 153.12,179.245 149.68,171.04 146.16,161.875 142.5,152.56 138.64,143.905 134.52,136.72 130.08,131.815 125.26,130 120,131.635 113.81,136.08 106.48,142.645 98.37,150.64 89.84,159.375 81.25,168.16 72.96,176.305 65.33,183.12 58.72,187.915 53.49,190 50,189.32 48.715,186.56 49.52,182.14 51.905,176.48 55.36,170 59.375,163.12 63.44,156.26 67.045,149.84 69.68,144.28 70.835,140 70,136.83 66.745,134.24 61.36,132.11 54.415,130.32 46.48,128.75 38.125,127.28 29.92,125.79 22.435,124.16 16.24,122.27 11.905,120 10,117.585 10.95,115.28 14.4,112.995 19.75,110.64 26.4,108.125 33.75,105.36 41.2,102.255 48.15,98.72 54,94.665 58.15,90 60,84.125 59.15,76.8 56,68.475 51.15,59.6 45.2,50.625 38.75,42 32.4,34.175 26.75,27.6 22.4,22.725 19.95,20 20)) See Also , , , ST_ConcaveHull Computes a possibly concave geometry that contains all input geometry vertices geometry ST_ConcaveHull geometry param_geom float param_pctconvex boolean param_allow_holes = false Description A concave hull is a (usually) concave geometry which contains the input, and whose vertices are a subset of the input vertices. In the general case the concave hull is a Polygon. The concave hull of two or more collinear points is a two-point LineString. The concave hull of one or more identical points is a Point. The polygon will not contain holes unless the optional param_allow_holes argument is specified as true. One can think of a concave hull as "shrink-wrapping" a set of points. This is different to the convex hull, which is more like wrapping a rubber band around the points. A concave hull generally has a smaller area and represents a more natural boundary for the input points. The param_pctconvex controls the concaveness of the computed hull. A value of 1 produces the convex hull. Values between 1 and 0 produce hulls of increasing concaveness. A value of 0 produces a hull with maximum concaveness (but still a single polygon). Choosing a suitable value depends on the nature of the input data, but often values between 0.3 and 0.1 produce reasonable results. Technically, the param_pctconvex determines a length as a fraction of the difference between the longest and shortest edges in the Delaunay Triangulation of the input points. Edges longer than this length are "eroded" from the triangulation. The triangles remaining form the concave hull. For point and linear inputs, the hull will enclose all the points of the inputs. For polygonal inputs, the hull will enclose all the points of the input and also all the areas covered by the input. If you want a point-wise hull of a polygonal input, convert it to points first using . This is not an aggregate function. To compute the concave hull of a set of geometries use (e.g. ST_ConcaveHull(ST_Collect(geom ), 0.80). Availability: 2.0.0 Enhanced: 3.3.0, GEOS native implementation enabled for GEOS 3.11+ Examples Concave hull of a MultiPoint. SELECT ST_ConcaveHull('MULTIPOINT ((10 72),(53 76),(56 66),(63 58),(71 51),(81 48),(91 46),(101 45),(111 46),(121 47),(131 50),(140 55),(145 64),(144 74),(135 80),(125 83),(115 85),(105 87),(95 89),(85 91),(75 93),(65 95),(55 98),(45 102),(37 107),(29 114),(22 122),(19 132),(18 142),(21 151),(27 160),(35 167),(44 172),(54 175),(64 178),(74 180),(84 181),(94 181),(104 181),(114 181),(124 181),(134 179),(144 177),(153 173),(162 168),(171 162),(177 154),(182 145),(184 135),(139 132),(136 142),(128 149),(119 153),(109 155),(99 155),(89 155),(79 153),(69 150),(61 144),(63 134),(72 128),(82 125),(92 123),(102 121),(112 119),(122 118),(132 116),(142 113),(151 110),(161 106),(170 102),(178 96),(185 88),(189 78),(190 68),(189 58),(185 49),(179 41),(171 34),(162 29),(153 25),(143 23),(133 21),(123 19),(113 19),(102 19),(92 19),(82 19),(72 21),(62 22),(52 25),(43 29),(33 34),(25 41),(19 49),(14 58),(21 73),(31 74),(42 74),(173 134),(161 134),(150 133),(97 104),(52 117),(157 156),(94 171),(112 106),(169 73),(58 165),(149 40),(70 33),(147 157),(48 153),(140 96),(47 129),(173 55),(144 86),(159 67),(150 146),(38 136),(111 170),(124 94),(26 59),(60 41),(71 162),(41 64),(88 110),(122 34),(151 97),(157 56),(39 146),(88 33),(159 45),(47 56),(138 40),(129 165),(33 48),(106 31),(169 147),(37 122),(71 109),(163 89),(37 156),(82 170),(180 72),(29 142),(46 41),(59 155),(124 106),(157 80),(175 82),(56 50),(62 116),(113 95),(144 167))', 0.1 ); st_astext ----------- POLYGON ((18 142, 21 151, 27 160, 35 167, 44 172, 54 175, 64 178, 74 180, 84 181, 94 181, 104 181, 114 181, 124 181, 134 179, 144 177, 153 173, 162 168, 171 162, 177 154, 182 145, 184 135, 173 134, 161 134, 150 133, 139 132, 136 142, 128 149, 119 153, 109 155, 99 155, 89 155, 79 153, 69 150, 61 144, 63 134, 72 128, 82 125, 92 123, 102 121, 112 119, 122 118, 132 116, 142 113, 151 110, 161 106, 170 102, 178 96, 185 88, 189 78, 190 68, 189 58, 185 49, 179 41, 171 34, 162 29, 153 25, 143 23, 133 21, 123 19, 113 19, 102 19, 92 19, 82 19, 72 21, 62 22, 52 25, 43 29, 33 34, 25 41, 19 49, 14 58, 10 72, 21 73, 31 74, 42 74, 53 76, 56 66, 63 58, 71 51, 81 48, 91 46, 101 45, 111 46, 121 47, 131 50, 140 55, 145 64, 144 74, 135 80, 125 83, 115 85, 105 87, 95 89, 85 91, 75 93, 65 95, 55 98, 45 102, 37 107, 29 114, 22 122, 19 132, 18 142)) (1 row) Concave hull of a MultiPoint, allowing holes. SELECT ST_ConcaveHull('MULTIPOINT ((132 64),(114 64),(99 64),(81 64),(63 64),(57 49),(52 36),(46 20),(37 20),(26 20),(32 36),(39 55),(43 69),(50 84),(57 100),(63 118),(68 133),(74 149),(81 164),(88 180),(101 180),(112 180),(119 164),(126 149),(132 131),(139 113),(143 100),(150 84),(157 69),(163 51),(168 36),(174 20),(163 20),(150 20),(143 36),(139 49),(132 64),(99 151),(92 138),(88 124),(81 109),(74 93),(70 82),(83 82),(99 82),(112 82),(126 82),(121 96),(114 109),(110 122),(103 138),(99 151),(34 27),(43 31),(48 44),(46 58),(52 73),(63 73),(61 84),(72 71),(90 69),(101 76),(123 71),(141 62),(166 27),(150 33),(159 36),(146 44),(154 53),(152 62),(146 73),(134 76),(143 82),(141 91),(130 98),(126 104),(132 113),(128 127),(117 122),(112 133),(119 144),(108 147),(119 153),(110 171),(103 164),(92 171),(86 160),(88 142),(79 140),(72 124),(83 131),(79 118),(68 113),(63 102),(68 93),(35 45))', 0.15, true ); st_astext ----------- POLYGON ((43 69, 50 84, 57 100, 63 118, 68 133, 74 149, 81 164, 88 180, 101 180, 112 180, 119 164, 126 149, 132 131, 139 113, 143 100, 150 84, 157 69, 163 51, 168 36, 174 20, 163 20, 150 20, 143 36, 139 49, 132 64, 114 64, 99 64, 81 64, 63 64, 57 49, 52 36, 46 20, 37 20, 26 20, 32 36, 35 45, 39 55, 43 69), (88 124, 81 109, 74 93, 83 82, 99 82, 112 82, 121 96, 114 109, 110 122, 103 138, 92 138, 88 124)) (1 row) Comparing a concave hull of a Polygon to the concave hull of the constituent points. The hull respects the boundary of the polygon, whereas the points-based hull does not. WITH data(geom) AS (VALUES ('POLYGON ((10 90,39 85,61 79,50 90,80 80,95 55,25 60,90 45,70 16,63 38,60 10,50 30,43 27,30 10,20 20,10 90))'::geometry) ) SELECT ST_ConcaveHull(geom, 0.1) AS polygon_hull, ST_ConcaveHull(ST_Points(geom), 0.1) AS points_hull FROM data; POLYGON((60 10,50 30,43 27,30 10,20 20,10 90,39 85,50 90,80 80,95 55,90 45,70 16,60 10)) | POLYGON((25 60,10 90,39 85,50 90,80 80,95 55,90 45,70 16,60 10,30 10,20 20,43 27,50 30,63 38,61 79,25 60)) Using with ST_Collect to compute the concave hull of a geometry set. This example estimates an infected area from point observations. SELECT disease_type, ST_ConcaveHull(ST_Collect(obs_pnt), 0.3 ) AS geom FROM disease_obs GROUP BY disease_type; See Also , , , 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. One can think of the convex hull as the geometry obtained by wrapping an rubber 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. 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. This is not an aggregate function. To compute the convex hull of a set of geometries, use to aggregate them into a geometry collection (e.g. ST_ConvexHull(ST_Collect(geom)). Performed by the GEOS module &sfs_compliant; s2.1.1.3 &sqlmm_compliant; SQL-MM IEC 13249-3: 5.1.16 &Z_support; Examples Compute the convex hull of a MultiLineString and a MultiPoint. SELECT 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)) (1 row) Using with ST_Collect to compute the convex hulls of geometry sets. This example returns an estimated infected area from point observations. SELECT d.disease_type, ST_ConvexHull(ST_Collect(d.geom)) As geom FROM disease_obs As d GROUP BY d.disease_type; See Also , , ST_DelaunayTriangles Returns the Delaunay triangulation of the vertices of a geometry. geometry ST_DelaunayTriangles geometry g1 float tolerance = 0.0 int4 flags = 0 Description Computes the Delaunay triangulation of the vertices of the input geometry. The optional tolerance can be used to snap nearby input vertices together, which improves robustness in some situations. The result geometry is bounded by the convex hull of the input vertices. The result geometry representation is determined by the flags code: 0 - a GEOMETRYCOLLECTION of triangular POLYGONs (default) 1 - a MULTILINESTRING of the edges of the triangulation 2 - A TIN of the triangulation Performed by the GEOS module. Availability: 2.1.0 &Z_support; &T_support; Examples Triangulation of the vertices of a polygon and a buffered point. WITH data AS ( SELECT polygon, ST_Buffer(center, 20) AS point_buffer FROM (SELECT 'POLYGON((175 150,20 40,50 60,125 100,175 150))'::geometry AS polygon, 'POINT(110 170)'::geometry AS center ) AS input ) SELECT ST_DelaunayTriangles(ST_Union(polygon, point_buffer)) AS triangles FROM data; GEOMETRYCOLLECTION(POLYGON((96 184,93 181,96 156,96 184)), POLYGON((96 184,96 156,102 188,96 184)), POLYGON((96 184,102 188,99 187,96 184)), POLYGON((102 188,96 156,99 153,102 188)), POLYGON((102 188,99 153,102 152,102 188)), POLYGON((102 188,102 152,106 190,102 188)), POLYGON((106 190,102 152,106 150,106 190)), POLYGON((106 190,106 150,110 190,106 190)), POLYGON((110 190,106 150,110 150,110 190)), POLYGON((110 190,110 150,118 188,110 190)), POLYGON((110 190,118 188,114 190,110 190)), POLYGON((118 188,110 150,121 153,118 188)), POLYGON((118 188,121 153,121 187,118 188)), POLYGON((121 187,121 153,124 156,121 187)), POLYGON((121 187,124 156,124 184,121 187)), POLYGON((121 187,124 184,175 150,121 187)), POLYGON((175 150,124 184,127 181,175 150)), POLYGON((175 150,127 181,128 178,175 150)), POLYGON((175 150,128 178,130 174,175 150)), POLYGON((175 150,130 174,130 170,175 150)), POLYGON((175 150,130 170,130 166,175 150)), POLYGON((175 150,130 166,128 162,175 150)), POLYGON((175 150,128 162,127 159,175 150)), POLYGON((175 150,127 159,124 156,175 150)), POLYGON((175 150,124 156,125 100,175 150)), POLYGON((125 100,124 156,121 153,125 100)), POLYGON((125 100,121 153,118 152,125 100)), POLYGON((125 100,118 152,114 150,125 100)), POLYGON((125 100,114 150,110 150,125 100)), POLYGON((125 100,110 150,106 150,125 100)), POLYGON((125 100,106 150,102 152,125 100)), POLYGON((125 100,102 152,99 153,125 100)), POLYGON((125 100,99 153,50 60,125 100)), POLYGON((125 100,50 60,20 40,125 100)), POLYGON((20 40,50 60,90 166,20 40)), POLYGON((20 40,90 166,90 170,20 40)), POLYGON((20 40,90 170,90 174,20 40)), POLYGON((20 40,90 174,92 178,20 40)), POLYGON((92 178,90 174,90 170,92 178)), POLYGON((92 178,90 170,92 162,92 178)), POLYGON((92 178,92 162,93 159,92 178)), POLYGON((92 178,93 159,93 181,92 178)), POLYGON((93 181,93 159,96 156,93 181)), POLYGON((96 156,93 159,50 60,96 156)), POLYGON((96 156,50 60,99 153,96 156)), POLYGON((50 60,93 159,92 162,50 60)), POLYGON((50 60,92 162,90 166,50 60)), POLYGON((90 166,92 162,90 170,90 166)), POLYGON((110 150,114 150,121 153,110 150)), POLYGON((121 153,114 150,118 152,121 153)), POLYGON((124 156,127 159,130 166,124 156)), POLYGON((124 156,130 166,128 178,124 156)), POLYGON((124 156,128 178,124 184,124 156)), POLYGON((124 184,128 178,127 181,124 184)), POLYGON((128 178,130 166,130 170,128 178)), POLYGON((128 178,130 170,130 174,128 178)), POLYGON((130 166,127 159,128 162,130 166))) Triangulation edges returned as a MULTILINESTRING. WITH data AS ( SELECT polygon, ST_Buffer(center, 20) AS point_buffer FROM (SELECT 'POLYGON((175 150,20 40,50 60,125 100,175 150))'::geometry AS polygon, 'POINT(110 170)'::geometry AS center ) AS input ) SELECT ST_DelaunayTriangles(ST_Union(polygon, point_buffer), 0.001, 1) AS triangulation_edges FROM data; MULTILINESTRING((121 187,175 150),(118 188,121 187),(114 190,118 188),(110 190,114 190),(106 190,110 190),(102 188,106 190),(99 187,102 188),(96 184,99 187),(93 181,96 184),(92 178,93 181),(20 40,92 178),(20 40,125 100),(125 100,175 150),(124 156,125 100),(124 156,175 150),(124 156,127 159),(127 159,175 150),(127 159,128 162),(128 162,175 150),(128 162,130 166),(130 166,175 150),(130 166,130 170),(130 170,175 150),(130 174,130 170),(130 174,175 150),(128 178,130 174),(128 178,175 150),(127 181,128 178),(127 181,175 150),(124 184,127 181),(124 184,175 150),(121 187,124 184),(124 156,124 184),(121 187,124 156),(121 153,124 156),(121 153,121 187),(118 188,121 153),(110 150,121 153),(110 150,118 188),(110 150,110 190),(110 190,118 188),(106 150,110 150),(106 150,110 190),(106 190,106 150),(102 152,106 150),(102 152,106 190),(102 152,102 188),(99 153,102 152),(99 153,102 188),(96 156,99 153),(96 156,102 188),(96 156,96 184),(96 184,102 188),(93 181,96 156),(93 159,96 156),(93 159,93 181),(92 178,93 159),(92 162,93 159),(92 162,92 178),(90 170,92 162),(90 170,92 178),(90 170,90 174),(90 174,92 178),(20 40,90 174),(20 40,90 170),(90 170,90 166),(20 40,90 166),(50 60,90 166),(20 40,50 60),(50 60,125 100),(50 60,99 153),(99 153,125 100),(50 60,96 156),(50 60,93 159),(50 60,92 162),(90 166,92 162),(102 152,125 100),(106 150,125 100),(110 150,125 100),(110 150,114 150),(114 150,125 100),(114 150,118 152),(118 152,125 100),(118 152,121 153),(121 153,125 100),(114 150,121 153),(124 184,128 178),(124 156,128 178),(128 178,130 166),(124 156,130 166),(127 159,130 166),(128 178,130 170)) Triangulation of 42 points forming an L shape. WITH data AS ( SELECT '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)'::geometry AS l_shape_points ) SELECT ST_DelaunayTriangles(l_shape_points) AS triangles FROM data; GEOMETRYCOLLECTION(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)), POLYGON((154 6,150 14,134 6,154 6)), POLYGON((134 6,150 14,134 14,134 6)), POLYGON((134 6,134 14,114 14,134 6)), POLYGON((134 6,114 14,114 6,134 6)), POLYGON((114 6,114 14,94 14,114 6)), POLYGON((114 6,94 14,94 6,114 6)), POLYGON((94 6,94 14,74 14,94 6)), POLYGON((94 6,74 14,74 6,94 6)), POLYGON((74 6,74 14,54 14,74 6)), POLYGON((74 6,54 14,54 6,74 6)), POLYGON((54 6,54 14,34 14,54 6)), POLYGON((54 6,34 14,34 6,54 6)), POLYGON((34 6,34 14,14 14,34 6)), POLYGON((34 6,14 14,14 6,34 6)), POLYGON((14 6,14 14,10 6,14 6)), POLYGON((10 6,14 14,6 10,10 6)), POLYGON((10 6,6 10,7 7,10 6)), POLYGON((10 6,7 7,8 6,10 6)), POLYGON((7 7,6 10,6 8,7 7)), POLYGON((6 10,14 14,6 30,6 10)), POLYGON((6 30,14 14,14 34,6 30)), POLYGON((6 30,14 34,6 50,6 30)), POLYGON((6 50,14 34,14 54,6 50)), POLYGON((6 50,14 54,6 70,6 50)), POLYGON((6 70,14 54,14 74,6 70)), POLYGON((6 70,14 74,6 90,6 70)), POLYGON((6 90,14 74,14 94,6 90)), POLYGON((6 90,14 94,6 110,6 90)), POLYGON((6 110,14 94,14 114,6 110)), POLYGON((6 110,14 114,6 130,6 110)), POLYGON((6 130,14 114,14 134,6 130)), POLYGON((6 130,14 134,6 150,6 130)), POLYGON((6 150,14 134,14 154,6 150)), POLYGON((6 150,14 154,6 170,6 150)), POLYGON((6 170,14 154,14 174,6 170)), POLYGON((6 170,14 174,6 190,6 170)), POLYGON((14 154,14 134,150 14,14 154)), POLYGON((150 14,14 134,134 14,150 14)), POLYGON((134 14,14 134,114 14,134 14)), POLYGON((114 14,14 134,14 114,114 14)), POLYGON((114 14,14 114,94 14,114 14)), POLYGON((94 14,14 114,14 94,94 14)), POLYGON((94 14,14 94,74 14,94 14)), POLYGON((74 14,14 94,14 74,74 14)), POLYGON((74 14,14 74,54 14,74 14)), POLYGON((54 14,14 74,14 54,54 14)), POLYGON((54 14,14 54,34 14,54 14)), POLYGON((34 14,14 54,14 34,34 14)), POLYGON((34 14,14 34,14 14,34 14))) Example using vertices with Z values. SELECT ST_DelaunayTriangles( 'MULTIPOINT Z(14 14 10,150 14 100,34 6 25,20 10 150)'::geometry); 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_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_FilterByM(geom, 30) simplified FROM (SELECT ST_SetEffectiveArea('LINESTRING(5 2,3 8,6 20,7 25,10 10)'::geometry) geom) As foo; LINESTRING(5 2,7 25,10 10) See Also , ST_GeneratePoints Generates a multipoint of random points contained in a Polygon or MultiPolygon. geometry ST_GeneratePoints geometry g integer npoints integer seed = 0 Description ST_GeneratePoints generates a multipoint consisting of 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 Generate 12 points inside a buffered LineString using the deterministic seed 1996. WITH source AS ( SELECT ST_Buffer(ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10, 'endcap=round join=round') AS geom ) SELECT geom AS area, ST_GeneratePoints(geom, 12, 1996) AS points FROM source; POLYGON((142.929 157.071,144.444 158.315,146.173 159.239,148.049 159.808,150 160,151.951 159.808,153.827 159.239,155.556 158.315,157.071 157.071,158.315 155.556,159.239 153.827,159.808 151.951,160 150,160 50,159.808 48.049,159.239 46.173,158.315 44.444,157.071 42.929,155.556 41.685,153.827 40.761,151.951 40.192,150 40,148.049 40.192,146.173 40.761,144.444 41.685,142.929 42.929,141.685 44.444,140.761 46.173,140.192 48.049,140 50,140 125.858,57.071 42.929,55.556 41.685,53.827 40.761,51.951 40.192,50 40,48.049 40.192,46.173 40.761,44.444 41.685,42.929 42.929,41.685 44.444,40.761 46.173,40.192 48.049,40 50,40.192 51.951,40.761 53.827,41.685 55.556,42.929 57.071,142.929 157.071)) | MULTIPOINT((97.546 111.15),(155.206 69.56),(101.94 114.818),(90.308 91.125),(151.257 106.401),(143.12 120.461),(152.952 146.697),(119.774 123.985),(148.672 40.92),(54.376 45.337),(150.667 88.153),(129.634 120.578)) Given a table of polygons s, return 12 individual points per polygon. Results will be different each time you run. SELECT s.id, dp.path[1] AS pt_id, dp.geom FROM s, ST_DumpPoints(ST_GeneratePoints(s.geom, 12)) AS dp; Generate dot-density points from a polygon table, using the absolute value of an attribute as the number of points and keeping the sign of the attribute for styling. SELECT z.id, CASE WHEN z.count_delta < 0 THEN -1 ELSE 1 END AS sign, dp.path[1] AS pt_id, dp.geom FROM zones AS z CROSS JOIN LATERAL ST_DumpPoints( ST_GeneratePoints(z.geom, abs(z.count_delta)::integer, z.id + 1) ) AS dp WHERE z.count_delta <> 0; See Also 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 Compare the geometric median and centroid of a MultiPoint. WITH test AS ( SELECT 'MULTIPOINT((10 10),(10 40),(40 10),(190 190))'::geometry geom) SELECT ST_Centroid(geom) centroid, ST_GeometricMedian(geom) median FROM test; centroid | median --------------------+---------------------------------------- POINT(62.5 62.5) | POINT(25.01778421249728 25.01778421249728) (1 row) See Also ST_LineMerge Return the lines formed by sewing together a MultiLineString. geometry ST_LineMerge geometry amultilinestring geometry ST_LineMerge geometry amultilinestring boolean directed Description Returns a LineString or MultiLineString formed by joining together the line elements of a MultiLineString. Lines are joined at their endpoints at 2-way intersections. Lines are not joined across intersections of 3-way or greater degree. If directed is TRUE, then ST_LineMerge will not change point order within LineStrings, so lines with opposite directions will not be merged Only use with MultiLineString/LineStrings. Other geometry types return an empty GeometryCollection Performed by the GEOS module. Enhanced: 3.3.0 accept a directed parameter. Requires GEOS >= 3.11.0 to use the directed parameter. Availability: 1.1.0 This function strips the M dimension. Examples Cardinality 2 Nodes with cardinality 2 are merged away. SELECT ST_LineMerge('MULTILINESTRING((10 160,60 120),(120 140,60 120),(120 140,180 120))' ); LINESTRING(10 160,60 120,120 140,180 120) Cardinality 3 or More Lines are not merged across intersections with degree > 2. SELECT ST_LineMerge('MULTILINESTRING((10 160,60 120),(120 140,60 120),(120 140,180 120),(100 180,120 140))' ); MULTILINESTRING((10 160,60 120,120 140),(100 180,120 140),(120 140,180 120)) Non-Touching Lines If merging is not possible due to non-touching lines, the original MultiLineString is returned. SELECT ST_LineMerge('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45.2 -33.2,-46 -32))' ); MULTILINESTRING((-45.2 -33.2,-46 -32),(-29 -27,-30 -29.7,-36 -31,-45 -33)) Directed Parameter Lines with opposite directions are not merged if directed is TRUE. SELECT ST_LineMerge('MULTILINESTRING((60 30,10 70),(120 50,60 30),(120 50,180 30))', TRUE); MULTILINESTRING((120 50,60 30,10 70),(120 50,180 30)) Z-dimension Handling SELECT ST_LineMerge('MULTILINESTRING((-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 6),(-29 -27 12,-30 -29.7 5),(-45 -33 1,-46 -32 11))' ); LINESTRING Z (-30 -29.7 5,-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 1,-46 -32 11) See Also , ST_MaximumInscribedCircle Computes the largest circle contained within a geometry. (geometry, geometry, double precision) ST_MaximumInscribedCircle geometry geom Description 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. Examples 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) See Also , ST_LargestEmptyCircle Computes the largest circle not overlapping a geometry. (geometry, geometry, double precision) ST_LargestEmptyCircle geometry geom double precision tolerance=0.0 geometry boundary=POINT EMPTY Description Finds the largest circle which does not overlap a set of point and line obstacles. (Polygonal geometries may be included as obstacles, but only their boundary lines are used.) The center of the circle is constrained to lie inside a polygonal boundary, which by default is the convex hull of the input geometry. The circle center is the point in the interior of the boundary which has the farthest distance from the obstacles. The circle itself is provided by the center point and a nearest point lying on an obstacle determining the circle radius. If a boundary is supplied it must be a valid polygonal geometry with positive area. The circle center is determined to a given accuracy specified by a distance tolerance, using an iterative algorithm. If the accuracy distance is not specified a reasonable default is used. 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 To find the largest empty circle in the interior of a polygon, see . Availability: 3.4.0. Requires GEOS >= 3.9.0. Examples Largest empty circle within a set of lines. WITH obstacles(geom) AS (VALUES ('MULTILINESTRING ( (10 100,60 180,130 150,190 160), (20 50,70 70,90 20,110 40), (160 30,100 100,180 100))'::geometry)), circle AS ( SELECT result.* FROM obstacles CROSS JOIN LATERAL ST_LargestEmptyCircle(obstacles.geom) AS result ) SELECT round(radius::numeric, 6) AS radius, ST_SnapToGrid(center, 1) AS center, ST_SnapToGrid(nearest, 1) AS nearest, ST_SnapToGrid(ST_MakeLine(center, nearest), 1) AS radius_line, ST_SnapToGrid(ST_Buffer(center, radius), 1) AS circle FROM circle; -[ RECORD 1 ]----- radius | 39.260545 center | POINT(62 108) nearest | POINT(70 70) radius_line | LINESTRING(62 108,70 70) circle | POLYGON((101 108,100 101,98 93,94 87,89 81,83 76,77 72,69 70,62 69,54 70,47 72,40 76,34 81,29 87,25 93,23 101,22 108,23 116,25 123,29 130,34 136,40 141,47 145,54 147,62 148,69 147,77 145,83 141,89 136,94 130,98 123,100 116,101 108)) Largest empty circle within a set of points, constrained to lie in a polygon. The constraint polygon boundary is included both as an obstacle and as the constraint for the circle center. WITH inputs(points, boundary) AS (VALUES ( 'MULTIPOINT ((70 50),(60 130),(130 150),(80 90))'::geometry, 'POLYGON ((90 190,10 100,60 10,190 40,120 100,190 180,90 190))'::geometry )), circle AS ( SELECT result.* FROM inputs CROSS JOIN LATERAL ST_LargestEmptyCircle( ST_Collect(points, boundary), 0, boundary ) AS result ) SELECT round(radius::numeric, 6) AS radius, ST_SnapToGrid(center, 1) AS center, ST_SnapToGrid(nearest, 1) AS nearest, ST_SnapToGrid(ST_MakeLine(center, nearest), 1) AS radius_line, ST_SnapToGrid(ST_Buffer(center, radius), 1) AS circle FROM circle; -[ RECORD 1 ]----- radius | 19.903876 center | POINT(97 100) nearest | POINT(80 90) radius_line | LINESTRING(97 100,80 90) circle | POLYGON((117 100,117 96,116 92,114 89,111 86,108 83,105 82,101 80,97 80,93 80,90 82,86 83,83 86,81 89,79 92,78 96,77 100,78 104,79 108,81 111,83 114,86 116,90 118,93 119,97 120,101 119,105 118,108 116,111 114,114 111,116 108,117 104,117 100)) See Also 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 bounding 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. For applications where an approximation is not suitable may be used. Use with to get the minimum bounding circle of a set of geometries. To compute two points lying on the minimum circle (the "maximum diameter") use . The ratio of the area of a polygon divided by the area of its Minimum Bounding Circle is referred to as the Reock compactness score. Performed by the GEOS module. Availability: 1.4.0 Examples SELECT d.disease_type, ST_MinimumBoundingCircle(ST_Collect(d.geom)) As geom FROM disease_obs As d GROUP BY d.disease_type; Minimum bounding circle of a point and linestring, using 8 segments to approximate a quarter circle. SELECT ST_MinimumBoundingCircle(ST_Collect('LINESTRING(55 75,125 150)', ST_Point(20, 80)), 8 ) As wktmbc; POLYGON((72.5 178.4024474346694,84.86920388664029 177.18418718546332,96.76306620464646 173.57622349601382,107.72451249529237 167.71720838753708,117.33230052487836 159.83230052487838,125.21720838753708 150.22451249529237,131.07622349601382 139.26306620464646,134.68418718546332 127.3692038866403,135.9024474346694 115,134.68418718546332 102.63079611335971,131.07622349601382 90.73693379535354,125.21720838753708 79.77548750470766,117.33230052487838 70.16769947512164,107.72451249529237 62.282791612462916,96.76306620464648 56.42377650398619,84.86920388664032 52.815812814536685,72.50000000000001 51.59755256533059,60.13079611335969 52.815812814536685,48.236933795353536 56.42377650398618,37.27548750470765 62.28279161246291,27.667699475121637 70.16769947512162,19.782791612462923 79.77548750470763,13.923776503986204 90.7369337953535,10.315812814536692 102.63079611335968,9.097552565330588 114.99999999999999,10.315812814536685 127.3692038866403,13.923776503986197 139.2630662046465,19.78279161246291 150.22451249529234,27.667699475121623 159.83230052487835,37.275487504707634 167.71720838753708,48.236933795353494 173.5762234960138,60.13079611335967 177.18418718546332,72.5 178.4024474346694)) See Also , , , ST_MinimumBoundingRadius Returns the center point and radius of the smallest circle that contains a geometry. (geometry, double precision) ST_MinimumBoundingRadius geometry geom Description Computes the center point and radius of the smallest circle that contains a geometry. Returns a record with fields: center - center point of the circle radius - radius of the circle Use with to get the minimum bounding circle of a set of geometries. To compute two points lying on the minimum circle (the "maximum diameter") use . Availability - 2.3.0 Examples SELECT center, radius FROM ST_MinimumBoundingRadius('POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))'); st_astext | radius ------------------------------------------+------------------ POINT(26284.84180271327 65267.114509082545) | 247.43604559140655 See Also , , ST_OrientedEnvelope Returns a minimum-area rectangle containing a geometry. geometry ST_OrientedEnvelope geometry geom Description Returns the minimum-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. Requires GEOS >= 3.6.0. Examples SELECT ST_OrientedEnvelope('MULTIPOINT ((0 0),(-1 -1),(3 2))'); POLYGON((3 2,-1 -1,-1.12 -0.84,2.88 2.16,3 2)) Oriented envelope of a Point and LineString. SELECT ST_OrientedEnvelope(ST_Collect('LINESTRING(55 75,125 150)', ST_Point(20, 80)) ) As wktenv; POLYGON((20 80,125 150,138.0769230769241 130.38461538461573,33.07692307692291 60.384615384615195,20 80)) See Also 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. Units of distance are measured in units of the spatial reference system. Note that output may be a MULTILINESTRING or EMPTY for some jigsaw-shaped input geometries. 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'. Performed by the GEOS module. Behavior changed in GEOS 3.11 so offset curves now have the same direction as the input line, for both positive and negative offsets. Availability: 2.0 Enhanced: 2.5 - added support for GEOMETRYCOLLECTION and MULTILINESTRING This function ignores the Z dimension. It always gives a 2D result even when used on a 3D geometry. Examples Compute an open buffer around roads. SELECT ST_Union( ST_OffsetCurve(f.geom, f.width/2, 'quad_segs=4 join=round'), ST_OffsetCurve(f.geom, -f.width/2, 'quad_segs=4 join=round') ) as track FROM someroadstable; Offset 15 units with quad_segs=4 join=round. SELECT 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'); LINESTRING(164 1,18 1,15.073645169758077 1.288220793951544, 12.259748514523654 2.141807012330698,9.66644650470597 3.527955815461818, 7.393398282201788 5.393398282201788,5.393398282201788 7.393398282201788, 3.527955815461818 9.66644650470597,2.141807012330696 12.259748514523654, 1.288220793951544 15.073645169758075,1 18,1 195) Offset -15 units with quad_segs=4 join=round. SELECT 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; LINESTRING(164 31,31 31,31 195) Apply two negative offsets to obtain a smoother curve; the distances combine to -45 units. SELECT 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; LINESTRING(164 61,61 61,61 195) Collect the positive offset and the double-offset to produce parallel curves. SELECT 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; MULTILINESTRING((164 1,18 1,15.073645169758077 1.288220793951544, 12.259748514523654 2.141807012330698,9.66644650470597 3.527955815461818, 7.393398282201788 5.393398282201788,5.393398282201788 7.393398282201788, 3.527955815461818 9.66644650470597,2.141807012330696 12.259748514523654, 1.288220793951544 15.073645169758075,1 18,1 195),(164 61,61 61,61 195)) Offset 15 units with a bevel join. SELECT 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'); LINESTRING(164 1,18 1,7.393398282201788 5.393398282201788, 5.393398282201788 7.393398282201788,1 18,1 195) Collect offsets on both sides using a mitre join and a mitre limit of 2.2. SELECT 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; MULTILINESTRING((164 1,11.786796564403577 1,1 11.786796564403577,1 195), (164 31,31 31,31 195)) See Also ST_PointOnSurface Computes a point guaranteed to lie in a polygon, or on a geometry. geometry ST_PointOnSurface geometry g1 Description Returns a POINT which is guaranteed to lie in the interior of a surface (POLYGON, MULTIPOLYGON, and CURVEPOLYGON). In PostGIS this function also works on line and point geometries. &sfs_compliant; s3.2.14.2 // s3.2.18.2 &sqlmm_compliant; SQL-MM 3: 8.1.5, 9.5.6. The specifications define ST_PointOnSurface for surface geometries only. PostGIS extends the function to support all common geometry types. Other databases (Oracle, DB2, ArcSDE) seem to support this function only for surfaces. SQL Server 2008 supports all common geometry types. &Z_support; Examples Point on surface of a MultiPoint. SELECT ST_PointOnSurface( 'MULTIPOINT (8 24,10 92,12 154,17 68,28 10,29 52,29 84,55 50,56 24,131 14,160 180,189 180)'); POINT(55 50) Point on surface of a LineString. SELECT ST_PointOnSurface( 'LINESTRING (190 160,10 190,40 90,20 70,10 10,30 40,30 10,110 40,70 10,110 10,140 40,140 10,160 30,180 10)'); POINT(40 90) Point on surface of a Polygon. SELECT ST_PointOnSurface( 'POLYGON ((190 190,10 190,10 10,190 10,190 20,160 30,60 30,60 130,190 140,190 190))'); POINT(35 80) Point on surface of the highest-dimension components of a GeometryCollection. SELECT ST_PointOnSurface( 'GEOMETRYCOLLECTION (POLYGON ((190 170,180 100,80 140,80 160,130 160,110 180,110 190,180 180,190 170)), LINESTRING (80 120,120 20,140 70,150 30,180 50,190 10), MULTIPOINT (19 150,22 49,30 13,32 101,45 35,67 88,75 16))'); POINT(133.571 150) SELECT ST_PointOnSurface('LINESTRING(0 5 1,0 0 1,0 10 2)'); st_asewkt -------------- POINT(0 0 1) (1 row) Example: The result of ST_PointOnSurface is guaranteed to lie within polygons, whereas the point computed by may be outside. SELECT ST_PointOnSurface(geom) AS pt_on_surf, ST_Centroid(geom) AS centroid FROM (SELECT 'POLYGON ((130 120,120 190,30 140,50 20,190 20, 170 100,90 60,90 130,130 120))'::geometry AS geom) AS t; pt_on_surf | centroid -----------------+--------------------------------------------- POINT(62.5 110) | POINT(100.18264840182648 85.11415525114155) See Also , 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 linework of a set of geometries. If the input linework does not form any polygons, an empty GeometryCollection is returned. This function creates polygons covering all delimited areas. If the result is intended to form a valid polygonal geometry, use to prevent holes being filled. The input linework must be correctly noded for this function to work properly. To ensure input is noded use on the input geometry before polygonizing. GeometryCollections can be difficult to handle with external tools. Use to convert the polygonized result into separate polygons. Performed by the GEOS module. Availability: 1.0.0RC1 Examples Polygonize a set of input lines. WITH data(geom) AS ( VALUES ('LINESTRING (180 40,30 20,20 90)'::geometry), ('LINESTRING (180 40,160 160)'::geometry), ('LINESTRING (80 60,120 130,150 80)'::geometry), ('LINESTRING (80 60,150 80)'::geometry), ('LINESTRING (20 90,70 70,80 130)'::geometry), ('LINESTRING (80 130,160 160)'::geometry), ('LINESTRING (20 90,20 160,70 190)'::geometry), ('LINESTRING (70 190,80 130)'::geometry), ('LINESTRING (70 190,160 160)'::geometry) ) SELECT ST_Polygonize(geom) FROM data; GEOMETRYCOLLECTION(POLYGON((180 40,30 20,20 90,70 70,80 130,160 160,180 40),(150 80,120 130,80 60,150 80)), POLYGON((80 60,120 130,150 80,80 60)), POLYGON((80 130,70 70,20 90,20 160,70 190,80 130)), POLYGON((160 160,80 130,70 190,160 160))) Polygonizing two polygon coverages and transferring attributes to the resultants: WITH poly_a(id, geom) AS (VALUES ('a1', 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))'::geometry), ('a2', 'POLYGON ((4 0, 8 0, 8 4, 4 4, 4 0))'::geometry) ), poly_b(id, geom) AS (VALUES ('b1', 'POLYGON ((0 0, 8 0, 8 2, 0 2, 0 0))'::geometry), ('b2', 'POLYGON ((0 2, 8 2, 8 4, 0 4, 0 2))'::geometry) ), lines AS ( SELECT ST_Boundary(geom) AS geom FROM poly_a UNION ALL SELECT ST_Boundary(geom) FROM poly_b ), noded AS ( SELECT ST_UnaryUnion(ST_Collect(geom)) AS geom FROM lines ), cells AS ( SELECT (ST_Dump(ST_Polygonize(geom))).geom AS geom FROM noded ) SELECT a.id AS id_a, b.id AS id_b, c.geom AS geom FROM cells AS c LEFT JOIN poly_a AS a ON ST_Within(ST_PointOnSurface(c.geom), a.geom) LEFT JOIN poly_b AS b ON ST_Within(ST_PointOnSurface(c.geom), b.geom) WHERE a.id IS NOT NULL OR b.id IS NOT NULL ORDER BY id_a, id_b; id_a | id_b | geom ------+------+-------------------------------- a1 | b1 | POLYGON((4 0,0 0,0 2,4 2,4 0)) a1 | b2 | POLYGON((4 4,4 2,0 2,0 4,4 4)) a2 | b1 | POLYGON((4 0,4 2,8 2,8 0,4 0)) a2 | b2 | POLYGON((4 2,4 4,8 4,8 2,4 2)) Polygonizing a table of linestrings: SELECT ST_Polygonize(geom_4269) As geomtextrep FROM (SELECT geom_4269 FROM ma.suffolk_edges) 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_Dump(t.polycoll)).geom AS geomtextrep FROM (SELECT ST_Polygonize(geom_4269) AS polycoll FROM (SELECT geom_4269 FROM ma.suffolk_edges) As foo) AS t; 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_ReducePrecision Returns a valid geometry with points rounded to a 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 the returned geometry will be valid, with no ring self-intersections or collapsed components. Precision reduction can be used to: match coordinate precision to the data accuracy reduce the number of coordinates needed to represent a geometry ensure valid geometry output to formats which use lower precision (e.g. text formats such as WKT, GeoJSON or KML when the number of output decimal places is limited). export valid geometry to systems which use lower or limited precision (e.g. SDE, Oracle tolerance value) Availability: 3.1.0. Requires GEOS >= 3.9.0. Examples SELECT ST_ReducePrecision('POINT(1.412 19.323)', 0.1); POINT(1.4 19.3) SELECT ST_ReducePrecision('POINT(1.412 19.323)', 1.0); POINT(1 19) SELECT ST_ReducePrecision('POINT(1.412 19.323)', 10); POINT(0 20) Precision reduction can reduce number of vertices SELECT ST_ReducePrecision('LINESTRING (10 10,19.6 30.1,20 30,20.3 30,40 40)', 1); LINESTRING (10 10, 20 30, 40 40) Precision reduction splits polygons if needed to ensure validity WITH data(geom) AS ( VALUES ('POLYGON ((10 10,60 60.1,70 30,40 40,50 10,10 10))'::geometry) ) SELECT geom AS input, ST_ReducePrecision(geom, 10) AS reduced FROM data; -[ RECORD 1 ]------------------------------------------------ input | POLYGON((10 10,60 60.1,70 30,40 40,50 10,10 10)) reduced | MULTIPOLYGON(((10 10,40 40,50 10,10 10)),((40 40,60 60,70 30,40 40))) See Also , , 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 Adjacent shared path segments may be returned as separate or merged LineStrings depending on the GEOS version. Find the shared paths of a MultiLineString and a LineString. SELECT 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,101 150,76 175)') ) GEOMETRYCOLLECTION(MULTILINESTRING((126 156.25,126 125), (101 150,76 175)),MULTILINESTRING EMPTY) Flip the LineString orientation to return the same paths in the opposite-direction member. SELECT ST_SharedPaths(ST_GeomFromText('LINESTRING(76 175,101 150,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))') ) GEOMETRYCOLLECTION(MULTILINESTRING EMPTY, MULTILINESTRING((76 175,101 150),(126 125,126 156.25))) See Also , , ST_Simplify Returns a simplified representation of a geometry, using the Douglas-Peucker algorithm. geometry ST_Simplify geometry geom float tolerance geometry ST_Simplify geometry geom float tolerance boolean preserveCollapsed Description Computes a simplified representation of a geometry using the Douglas-Peucker algorithm. The simplification tolerance is a distance value, in the units of the input SRS. Simplification removes vertices which are within the tolerance distance of the simplified linework. The result may not be valid even if the input is. The function can be called with any kind of geometry (including GeometryCollections), but only line and polygon elements are simplified. Endpoints of linear geometry are preserved. The preserveCollapsed flag retains small geometries that would otherwise be removed at the given tolerance. For example, if a 1m long line is simplified with a 10m tolerance, when preserveCollapsed is true the line will not disappear. This flag is useful for rendering purposes, to prevent very small features disappearing from a map. The returned geometry may lose its simplicity (see ), topology may not be preserved, and polygonal results may be invalid (see ). Use to preserve topology and ensure validity. This function does not preserve boundaries shared between polygons. Use if this is required. Availability: 1.2.2 Examples A circle simplified with a medium tolerance becomes an octagon, and with a large tolerance disappears. SELECT ST_NPoints(geom) AS np_before, ST_NPoints(ST_Simplify(geom, 0.1)) AS np01_notbadcircle, ST_NPoints(ST_Simplify(geom, 0.5)) AS np05_notquitecircle, ST_NPoints(ST_Simplify(geom, 1)) AS np1_octagon, ST_NPoints(ST_Simplify(geom, 10)) AS np10_gone, (ST_Simplify(geom, 100) is null) AS np100_geometrygoesaway FROM (SELECT ST_Buffer('POINT(1 3)', 10, 12) As geom) AS t; -[ RECORD 1 ]------------ np_before | 49 np01_notbadcircle | 33 np05_notquitecircle | 17 np1_octagon | 9 np10_gone | null np100_geometrygoesaway | t Simplifying a set of lines. Lines may intersect after simplification. SELECT ST_Simplify('MULTILINESTRING ((20 180,20 150,50 150,50 100,110 150,150 140,170 120),(20 10,80 30,90 120),(90 120,130 130),(130 130,130 70,160 40,180 60,180 90,140 80),(50 40,70 40,80 70,70 60,60 60,50 50,50 40))'::geometry, 40); MULTILINESTRING((20 180,50 100,170 120),(20 10,90 120),(90 120,130 130),(130 130,160 40,180 90,140 80),(50 40,80 70,50 40)) Simplifying a MultiPolygon. Polygonal results may be invalid. SELECT ST_Simplify('MULTIPOLYGON (((90 110,80 180,50 160,10 170,10 140,20 110,90 110)),((40 80,100 100,120 160,170 180,190 70,140 10,110 40,60 40,40 80),(180 70,170 110,142.5 128.5,128.5 77.5,90 60,180 70)))'::geometry, 40); MULTIPOLYGON(((90 110,80 180,10 170,20 110,90 110)),((40 80,170 180,140 10,40 80),(180 70,142.5 128.5,90 60,180 70))) See Also , , , , Topology ST_SimplifyPreserveTopology Returns a simplified and valid representation of a geometry, using the Douglas-Peucker algorithm. geometry ST_SimplifyPreserveTopology geometry geom float tolerance Description Computes a simplified representation of a geometry using a variant of the Douglas-Peucker algorithm which limits simplification to ensure the result has the same topology as the input. The simplification tolerance is a distance value, in the units of the input SRS. Simplification removes vertices which are within the tolerance distance of the simplified linework, as long as topology is preserved. The result will be valid and simple if the input is. The function can be called with any kind of geometry (including GeometryCollections), but only line and polygon elements are simplified. For polygonal inputs, the result will have the same number of rings (shells and holes), and the rings will not cross. Ring endpoints may be simplified. For linear inputs, the result will have the same number of lines, and lines will not intersect if they did not do so in the original geometry. Endpoints of linear geometry are preserved. This function does not preserve boundaries shared between polygons. Use if this is required. Performed by the GEOS module. Availability: 1.3.3 Examples For the same example as , ST_SimplifyPreserveTopology prevents the geometry from disappearing. SELECT ST_NPoints(geom) AS np_before, ST_NPoints(ST_SimplifyPreserveTopology(geom, 0.1)) AS np01_notbadcircle, ST_NPoints(ST_SimplifyPreserveTopology(geom, 0.5)) AS np05_notquitecircle, ST_NPoints(ST_SimplifyPreserveTopology(geom, 1)) AS np1_octagon, ST_NPoints(ST_SimplifyPreserveTopology(geom, 10)) AS np10_minimal, ST_NPoints(ST_SimplifyPreserveTopology(geom, 100)) AS np100_minimal FROM (SELECT ST_Buffer('POINT(1 3)', 10, 12) AS geom) AS t; np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_minimal | np100_minimal -----------+-------------------+---------------------+-------------+--------------+--------------- 49 | 33 | 17 | 9 | 4 | 4 Simplifying a set of lines, preserving topology of non-intersecting lines. SELECT ST_SimplifyPreserveTopology('MULTILINESTRING ((20 180,20 150,50 150,50 100,110 150,150 140,170 120),(20 10,80 30,90 120),(90 120,130 130),(130 130,130 70,160 40,180 60,180 90,140 80),(50 40,70 40,80 70,70 60,60 60,50 50,50 40))'::geometry, 40); MULTILINESTRING((20 180,50 100,110 150,170 120),(20 10,80 30,90 120),(90 120,130 130),(130 130,130 70,160 40,180 90,140 80),(50 40,70 40,80 70,60 60,50 40)) Simplifying a MultiPolygon, preserving topology of shells and holes. SELECT ST_SimplifyPreserveTopology('MULTIPOLYGON (((90 110,80 180,50 160,10 170,10 140,20 110,90 110)),((40 80,100 100,120 160,170 180,190 70,140 10,110 40,60 40,40 80),(180 70,170 110,142.5 128.5,128.5 77.5,90 60,180 70)))'::geometry, 40); MULTIPOLYGON(((90 110,80 180,10 170,20 110,90 110)),((40 80,100 100,170 180,190 70,140 10,40 80),(180 70,142.5 128.5,90 60,180 70))) See Also , , 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 Description 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. Examples 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))) See Also , , , ST_SimplifyVW Returns a simplified representation of a geometry, using the Visvalingam-Whyatt algorithm geometry ST_SimplifyVW geometry geom float tolerance Description Returns a simplified representation of a geometry using the Visvalingam-Whyatt algorithm. The simplification tolerance is an area value, in squared units of the input SRS. Simplification removes vertices which form "corners" with area less than the tolerance. The result may not be valid even if the input is. The function can be called with any kind of geometry (including GeometryCollections), but only line and polygon elements are simplified. Endpoints of linear geometry are preserved. The returned geometry may lose its simplicity (see ), topology may not be preserved, and polygonal results may be invalid (see ). Use to preserve topology and ensure validity. also preserves topology and validity. This is a general-purpose simplification function. It may remove narrow polygon spikes when their effective area is below the tolerance, but it is not a dedicated spike-removal or polygon-repair operation. Use to check the result and to repair invalid polygonal output if needed. This function does not preserve boundaries shared between polygons. Use if this is required. This function handles 3D and the third dimension will affect the result. Availability: 2.2.0 Examples This polygon has a narrow spike whose effective area is small enough to be removed by a tolerance of 20 square units. SELECT geom AS original, ST_SimplifyVW(geom, 20) AS simplified FROM (SELECT 'POLYGON((0 0,10 0,10 10,5.2 10,5 16,4.8 10,0 10,0 0))'::geometry AS geom) AS t; POLYGON((0 0,10 0,10 10,5.2 10,5 16,4.8 10,0 10,0 0)) | POLYGON((0 0,10 0,10 10,0 10,0 0)) A LineString is simplified with a minimum-area tolerance of 30. For a linear simplification using , a comparable tolerance would be a length in input-SRS units, so the value here is roughly that linear tolerance squared. SELECT ST_SimplifyVW(geom, 30) simplified FROM (SELECT 'LINESTRING(5 2,3 8,6 20,7 25,10 10)'::geometry AS geom) AS t; LINESTRING(5 2,7 25,10 10) Simplifying a line. SELECT ST_SimplifyVW('LINESTRING (10 10,50 40,30 70,50 60,70 80,50 110,100 100,90 140,100 180,150 170,170 140,190 90,180 40,110 40,150 20)'::geometry, 1600); LINESTRING(10 10,100 100,100 180,150 170,190 90,150 20) Simplifying a polygon. SELECT ST_SimplifyVW('POLYGON ((20 20,50 60,20 120,40 170,80 180,120 140,180 180,160 130,180 100,180 30,130 70,150 10,20 20))'::geometry, 1600); POLYGON((20 20,20 120,80 180,160 130,180 30,20 20)) See Also , , , , Topology ST_SetEffectiveArea Sets the effective area for each vertex, using the Visvalingam-Whyatt algorithm. geometry ST_SetEffectiveArea geometry geom 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 "threshold" 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 ) Note topology may not be preserved and may result in invalid geometries. Use (see ) 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_SetEffectiveArea(geom) AS all_pts, ST_SetEffectiveArea(geom, 30) AS threshold_30 FROM (SELECT 'LINESTRING(5 2,3 8,6 20,7 25,10 10)'::geometry geom) As foo; -[ RECORD 1 ]------------------ all_pts | LINESTRING M (5 2 3.4e+38,3 8 29,6 20 1.5,7 25 49.5,10 10 3.4e+38) threshold_30 | LINESTRING M (5 2 3.4e+38,7 25 49.5,10 10 3.4e+38) See Also ST_TriangulatePolygon Computes the constrained Delaunay triangulation of polygons geometry ST_TriangulatePolygon geometry geom Description Computes the constrained Delaunay triangulation of polygons. Holes and Multipolygons are supported. The "constrained Delaunay triangulation" of a polygon is a set of triangles formed from the vertices of the polygon, and covering it exactly, with the maximum total interior angle over all possible triangulations. It provides the "best quality" triangulation of the polygon. Availability: 3.3.0. Requires GEOS >= 3.11.0. Examples Triangulation of a square. SELECT ST_TriangulatePolygon('POLYGON((0 0,0 1,1 1,1 0,0 0))'); GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 1,0 0)), POLYGON((1 1,1 0,0 0,1 1))) Triangulation of the letter P. SELECT ST_TriangulatePolygon('POLYGON ((26 17,31 19,34 21,37 24,38 29,39 43,39 161,38 172,36 176,34 179,30 181,25 183,10 185,10 190,100 190,121 189,139 187,154 182,167 177,177 169,184 161,189 152,190 141,188 128,186 123,184 117,180 113,176 108,170 104,164 101,151 96,136 92,119 89,100 89,86 89,73 89,73 39,74 32,75 27,77 23,79 20,83 18,89 17,106 15,106 10,10 10,10 15,26 17),(152 147,151 152,149 157,146 162,142 166,137 169,132 172,126 175,118 177,109 179,99 180,89 180,80 179,76 178,74 176,73 171,73 100,85 99,91 99,102 99,112 100,121 102,128 104,134 107,139 110,143 114,147 118,149 123,151 128,153 141,152 147))' ); GEOMETRYCOLLECTION (POLYGON ((10 10, 10 15, 26 17, 10 10)), POLYGON ((25 183, 10 185, 10 190, 25 183)), POLYGON ((126 175, 121 189, 139 187, 126 175)), POLYGON ((137 169, 139 187, 154 182, 137 169)), POLYGON ((149 157, 167 177, 177 169, 149 157)), POLYGON ((153 141, 189 152, 190 141, 153 141)), POLYGON ((153 141, 188 128, 186 123, 153 141)), POLYGON ((186 123, 184 117, 180 113, 186 123)), POLYGON ((149 123, 176 108, 170 104, 149 123)), POLYGON ((147 118, 164 101, 151 96, 147 118)), POLYGON ((121 102, 136 92, 119 89, 121 102)), POLYGON ((85 99, 73 89, 73 100, 85 99)), POLYGON ((89 17, 106 15, 106 10, 89 17)), POLYGON ((83 18, 10 10, 26 17, 83 18)), POLYGON ((100 190, 25 183, 10 190, 100 190)), POLYGON ((121 189, 109 179, 100 190, 121 189)), POLYGON ((189 152, 152 147, 184 161, 189 152)), POLYGON ((153 141, 190 141, 188 128, 153 141)), POLYGON ((147 118, 170 104, 164 101, 147 118)), POLYGON ((139 110, 151 96, 136 92, 139 110)), POLYGON ((73 89, 85 99, 86 89, 73 89)), POLYGON ((83 18, 89 17, 106 10, 83 18)), POLYGON ((83 18, 26 17, 31 19, 83 18)), POLYGON ((100 190, 30 181, 25 183, 100 190)), POLYGON ((189 152, 153 141, 152 147, 189 152)), POLYGON ((176 108, 151 128, 180 113, 176 108)), POLYGON ((91 99, 86 89, 85 99, 91 99)), POLYGON ((10 10, 83 18, 106 10, 10 10)), POLYGON ((76 178, 100 190, 80 179, 76 178)), POLYGON ((86 89, 91 99, 100 89, 86 89)), POLYGON ((79 20, 83 18, 31 19, 79 20)), POLYGON ((102 99, 100 89, 91 99, 102 99)), POLYGON ((34 21, 79 20, 31 19, 34 21)), POLYGON ((112 100, 100 89, 102 99, 112 100)), POLYGON ((37 24, 79 20, 34 21, 37 24)), POLYGON ((100 89, 112 100, 119 89, 100 89)), POLYGON ((79 20, 37 24, 77 23, 79 20)), POLYGON ((119 89, 112 100, 121 102, 119 89)), POLYGON ((77 23, 37 24, 75 27, 77 23)), POLYGON ((136 92, 121 102, 128 104, 136 92)), POLYGON ((38 29, 75 27, 37 24, 38 29)), POLYGON ((134 107, 136 92, 128 104, 134 107)), POLYGON ((75 27, 38 29, 74 32, 75 27)), POLYGON ((139 110, 136 92, 134 107, 139 110)), POLYGON ((74 32, 38 29, 73 39, 74 32)), POLYGON ((151 96, 139 110, 143 114, 151 96)), POLYGON ((39 43, 73 39, 38 29, 39 43)), POLYGON ((151 96, 143 114, 147 118, 151 96)), POLYGON ((73 39, 39 43, 73 89, 73 39)), POLYGON ((170 104, 147 118, 149 123, 170 104)), POLYGON ((73 89, 39 43, 73 100, 73 89)), POLYGON ((176 108, 149 123, 151 128, 176 108)), POLYGON ((39 161, 73 100, 39 43, 39 161)), POLYGON ((180 113, 151 128, 186 123, 180 113)), POLYGON ((73 100, 39 161, 73 171, 73 100)), POLYGON ((186 123, 151 128, 153 141, 186 123)), POLYGON ((38 172, 73 171, 39 161, 38 172)), POLYGON ((151 152, 184 161, 152 147, 151 152)), POLYGON ((73 171, 38 172, 74 176, 73 171)), POLYGON ((184 161, 151 152, 177 169, 184 161)), POLYGON ((36 176, 74 176, 38 172, 36 176)), POLYGON ((149 157, 177 169, 151 152, 149 157)), POLYGON ((34 179, 74 176, 36 176, 34 179)), POLYGON ((146 162, 167 177, 149 157, 146 162)), POLYGON ((74 176, 34 179, 76 178, 74 176)), POLYGON ((167 177, 146 162, 154 182, 167 177)), POLYGON ((30 181, 76 178, 34 179, 30 181)), POLYGON ((154 182, 146 162, 142 166, 154 182)), POLYGON ((100 190, 76 178, 30 181, 100 190)), POLYGON ((154 182, 142 166, 137 169, 154 182)), POLYGON ((80 179, 100 190, 89 180, 80 179)), POLYGON ((139 187, 137 169, 132 172, 139 187)), POLYGON ((100 190, 99 180, 89 180, 100 190)), POLYGON ((139 187, 132 172, 126 175, 139 187)), POLYGON ((100 190, 109 179, 99 180, 100 190)), POLYGON ((121 189, 126 175, 118 177, 121 189)), POLYGON ((121 189, 118 177, 109 179, 121 189))) Triangulation of the polygon used in the example. SELECT ST_TriangulatePolygon('POLYGON (( 10 190,10 70,80 70,80 130,50 160,120 160,120 190,10 190 ))'::geometry ); GEOMETRYCOLLECTION(POLYGON((50 160,120 190,120 160,50 160)), POLYGON((10 70,80 130,80 70,10 70)), POLYGON((50 160,10 70,10 190,50 160)), POLYGON((120 190,50 160,10 190,120 190)), POLYGON((80 130,10 70,50 160,80 130))) See Also , , ST_VoronoiLines Returns the boundaries of the Voronoi diagram of the vertices of a geometry. geometry ST_VoronoiLines geometry geom float8 tolerance = 0.0 geometry extend_to = NULL Description Computes a two-dimensional Voronoi diagram from the vertices of the supplied geometry and returns the boundaries between cells in the 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 present, the diagram is extended to cover the envelope of the supplied geometry, unless smaller than the default envelope (default = NULL, default envelope is the bounding box of the input expanded by about 50%). Performed by the GEOS module. Availability: 2.3.0 Examples Voronoi diagram lines with a tolerance of 30 units. SELECT ST_VoronoiLines('MULTIPOINT (50 30,60 30,100 100,10 150,110 120)'::geometry, 30) AS geom; 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_VoronoiPolygons Returns the cells of the Voronoi diagram of the vertices of a geometry. geometry ST_VoronoiPolygons geometry geom float8 tolerance = 0.0 geometry extend_to = NULL Description 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 present, the diagram is extended to cover the envelope of the supplied geometry, unless smaller than the default envelope (default = NULL, default envelope is the bounding box of the input expanded by about 50%). Performed by the GEOS module. Availability: 2.3.0 Examples Points overlaid on top of the Voronoi diagram. SELECT ST_VoronoiPolygons('MULTIPOINT (50 30,60 30,100 100,10 150,110 120)'::geometry ) AS geom; GEOMETRYCOLLECTION(POLYGON((-110 270,100.5 270,59.34782608695652 132.82608695652175,36.81818181818182 92.27272727272727,-110 43.33333333333332,-110 270)), POLYGON((-110 -90,-110 43.33333333333332,36.81818181818182 92.27272727272727,55 79.28571428571429,55 -90,-110 -90)), POLYGON((230 -20.71428571428572,55 79.28571428571429,36.81818181818182 92.27272727272727,59.34782608695652 132.82608695652175,230 47.50000000000001,230 -20.71428571428572)), POLYGON((230 -90,55 -90,55 79.28571428571429,230 -20.71428571428572,230 -90)), POLYGON((230 270,230 47.50000000000001,59.34782608695652 132.82608695652175,100.5 270,230 270))) Voronoi diagram with a tolerance of 30 units. SELECT ST_VoronoiPolygons('MULTIPOINT (50 30,60 30,100 100,10 150,110 120)'::geometry, 30) AS geom; GEOMETRYCOLLECTION(POLYGON((-110 270,135.55555555555557 270,36.81818181818182 92.27272727272727,-110 43.33333333333332,-110 270)), POLYGON((230 270,230 -45.71428571428574,36.81818181818182 92.27272727272727,135.55555555555557 270,230 270)), POLYGON((230 -90,-110 -90,-110 43.33333333333332,36.81818181818182 92.27272727272727,230 -45.71428571428574,230 -90))) See Also ,