PostGIS
Synopsis
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 specifed 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' : '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.
|
|
|
|
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.
This method implements the OGC Simple Features Implementation Specification for SQL 1.1. s2.1.1.3
This method implements the SQL/MM specification. SQL-MM IEC 13249-3: 5.1.30
Examples
quad_segs=8 (default)
|
quad_segs=2 (lame)
|
endcap=round join=round (default)
|
endcap=square
|
join=bevel
|
join=mitre mitre_limit=5.0 (default mitre limit)
|
side=left
|
side=right
|
right-hand-winding, polygon boundary side=left
|
right-hand-winding, polygon boundary side=right
|
--A buffered point approximates a circle
-- A buffered point forcing approximation of (see diagram)
-- 2 points per quarter circle is poly with 8 sides (see diagram)
SELECT ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50)) As promisingcircle_pcount,
ST_NPoints(ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50, 2)) As lamecircle_pcount;
promisingcircle_pcount | lamecircle_pcount
------------------------+-------------------
33 | 9
--A lighter but lamer circle
-- only 2 points per quarter circle is an octagon
--Below is a 100 meter octagon
-- Note coordinates are in NAD 83 long lat which we transform
to Mass state plane meter and then buffer to get measurements in meters;
SELECT ST_AsText(ST_Buffer(
ST_Transform(
ST_SetSRID(ST_Point(-71.063526, 42.35785),4269), 26986)
,100,2)) As octagon;
----------------------
POLYGON((236057.59057465 900908.759918696,236028.301252769 900838.049240578,235
957.59057465 900808.759918696,235886.879896532 900838.049240578,235857.59057465
900908.759918696,235886.879896532 900979.470596815,235957.59057465 901008.759918
696,236028.301252769 900979.470596815,236057.59057465 900908.759918696))