The ST_Buffer() function
The ST_Buffer() function encircles a geometry object at a specified distance and returns a geometry object that is the buffer that surrounds the source object.
Syntax
ST_Buffer(g1 ST_Geometry, distance double_precision)
ST_Buffer(g1 ST_Geometry, distance double_precision, linear_uom varchar(128))
ST_Buffer(g1 ST_Geometry, distance double_precision)
Return type
ST_Geometry
Usage
A single polygon results when a primary geometry is buffered or when the buffer polygons of a collection are close enough to overlap. When enough separation exists between the elements of a buffered collection, individual buffer ST_Polygons result in an ST_MultiPolygon.
The ST_Buffer() function accepts both positive and negative distances, but only geometries with a dimension of 2 (ST_Polygon and ST_MultiPolygon) can apply a negative buffer. The absolute value of the buffer distance is used when the dimension of the source geometry is less than 2. Generally, positive buffer distances generate polygon rings away from the center of the source geometry and, for the exterior ring of a ST_Polygon or ST_MultiPolygon, toward the center when the distance is negative. For interior rings of an ST_Polygon or ST_MultiPolygon, the buffer ring is toward the center when the buffer distance is positive and away when it is negative.
The buffering process merges buffer polygons that overlap. Negative distances greater than one-half the maximum interior width of a polygon result in an empty geometry.
The linear_uom parameter converts the result to the specified unit of measure. To calculate the buffer if the geometries are in a geographic coordinate system where the coordinates are in an angular unit of measure, you must specify a linear unit of measure with the linear_uom parameter. Angular units of measure are converted to linear units of measure by great-circle calculations. If the geometry is in a projected coordinate system that has a unit of measure that is different from the unit of measure that is specified by the linear_uom parameter, then the returned value is converted to the unit of measure that is specified by the linear_uom parameter. The linear_uom parameter must be the name of a linear unit of measure from the unit_name column of the st_units_of_measure table.
Example: Find 5-mile radii of hazardous sites
CREATE TABLE sensitive_areas (id integer,
name varchar(128),
size float,
type varchar(10),
zone ST_Polygon);
CREATE TABLE hazardous_sites (site_id integer,
name varchar(40),
location ST_Point);
t
(TRUE) for all sensitive_areas rows
whose zone polygons overlap the buffered 5-mile radius of the hazardous_sites location
point. SELECT sa.name, hs.name
FROM sensitive_areas sa, hazardous_sites hs
WHERE ST_Overlaps(sa.zone, ST_Buffer(hs.location,26400));
name Johnson County Hospital
name Landmark Industrial
name Summerhill Elementary School
name Landmark Industrial
Example: Find a 3-meter buffer around a multipoint
The following statement returns a polygon that surrounds a multipoint by a buffer of 3 meters:
EXECUTE FUNCTION st_buffer(
'32608 multipoint(576100 15230, 576100 15232, 576102 15232,
576102 15230, 576100 15230)'::st_multipoint,
3, 'meter');
(expression) 32608 POLYGON ((576097 15230, 576097.006423 15229.8037906, 576097
.025665 15229.6084214, 576097.057644 15229.414729, 576097.102223
15229.2235429, 576097.15921 15229.0356816, 576097.228361 15228.85
19497, 576097.309382 15228.6731339, 576097.401924 15228.5, 576097
.505591 15228.3332893, 576097.61994 15228.1737157, 576097.744481
15228.0219626, 576097.87868 15227.8786797, 576098.021963 15227.74
44806, 576098.173716 15227.61994, 576098.333289 15227.5055912, 57
6098.5 15227.4019238, 576098.673134 15227.3093818, 576098.85195 1
5227.2283614, 576099.035682 15227.1592096, 576099.223543 15227.10
22225, 576099.414729 15227.0576442, 576099.608421 15227.0256654,
576099.803791 15227.0064232, 576100 15227, 576100.196209 15227.00
64232, 576100.391579 15227.0256654, 576100.585271 15227.0576442,
576100.776457 15227.1022225, 576100.964318 15227.1592096, 576101
15227.1726392, 576101.035682 15227.1592096, 576101.223543 15227.1
022225, 576101.414729 15227.0576442, 576101.608421 15227.0256654,
576101.803791 15227.0064232, 576102 15227, 576102.196209 15227.0
064232, 576102.391579 15227.0256654, 576102.585271 15227.0576442,
576102.776457 15227.1022225, 576102.964318 15227.1592096, 576103
.14805 15227.2283614, 576103.326866 15227.3093818, 576103.5 15227
.4019238, 576103.666711 15227.5055912, 576103.826284 15227.61994,
576103.978037 15227.7444806, 576104.12132 15227.8786797, 576104.
255519 15228.0219626, 576104.38006 15228.1737157, 576104.494409 1
5228.3332893, 576104.598076 15228.5, 576104.690618 15228.6731339,
576104.771639 15228.8519497, 576104.84079 15229.0356816, 576104.
897777 15229.2235429, 576104.942356 15229.414729, 576104.974335 1
5229.6084214, 576104.993577 15229.8037906, 576105 15230, 576104.9
93577 15230.1962094, 576104.974335 15230.3915786, 576104.942356 1
5230.585271, 576104.897777 15230.7764571, 576104.84079 15230.9643
184, 576104.827361 15231, 576104.84079 15231.0356816, 576104.8977
77 15231.2235429, 576104.942356 15231.414729, 576104.974335 15231
.6084214, 576104.993577 15231.8037906, 576105 15232, 576104.99357
7 15232.1962094, 576104.974335 15232.3915786, 576104.942356 15232
.585271, 576104.897777 15232.7764571, 576104.84079 15232.9643184,
576104.771639 15233.1480503, 576104.690618 15233.3268661, 576104
.598076 15233.5, 576104.494409 15233.6667107, 576104.38006 15233.
8262843, 576104.255519 15233.9780374, 576104.12132 15234.1213203,
576103.978037 15234.2555194, 576103.826284 15234.38006, 576103.6
66711 15234.4944088, 576103.5 15234.5980762, 576103.326866 15234.
6906182, 576103.14805 15234.7716386, 576102.964318 15234.8407904,
576102.776457 15234.8977775, 576102.585271 15234.9423558, 576102
.391579 15234.9743346, 576102.196209 15234.9935768, 576102 15235,
576101.803791 15234.9935768, 576101.608421 15234.9743346, 576101
.414729 15234.9423558, 576101.223543 15234.8977775, 576101.035682
15234.8407904, 576101 15234.8273608, 576100.964318 15234.8407904
, 576100.776457 15234.8977775, 576100.585271 15234.9423558, 57610
0.391579 15234.9743346, 576100.196209 15234.9935768, 576100 15235
, 576099.803791 15234.9935768, 576099.608421 15234.9743346, 57609
9.414729 15234.9423558, 576099.223543 15234.8977775, 576099.03568
2 15234.8407904, 576098.85195 15234.7716386, 576098.673134 15234.
6906182, 576098.5 15234.5980762, 576098.333289 15234.4944088, 576
098.173716 15234.38006, 576098.021963 15234.2555194, 576097.87868
15234.1213203, 576097.744481 15233.9780374, 576097.61994 15233.8
262843, 576097.505591 15233.6667107, 576097.401924 15233.5, 57609
7.309382 15233.3268661, 576097.228361 15233.1480503, 576097.15921
15232.9643184, 576097.102223 15232.7764571, 576097.057644 15232.
585271, 576097.025665 15232.3915786, 576097.006423 15232.1962094,
576097 15232, 576097.006423 15231.8037906, 576097.025665 15231.6
084214, 576097.057644 15231.414729, 576097.102223 15231.2235429,
576097.15921 15231.0356816, 576097.172639 15231, 576097.15921 152
30.9643184, 576097.102223 15230.7764571, 576097.057644 15230.5852
71, 576097.025665 15230.3915786, 576097.006423 15230.1962094, 576
097 15230))
1 row(s) retrieved.
Example: Find a buffer around a point that has angular coordinates
The following statement returns a 20-mile buffer around the latitude and longitude of New York (40.67000 N, 73.94000 W). The distance is linear, but the result is a polygon in the WGS 84 geographic coordinate system:
EXECUTE FUNCTION ST_Buffer('4326 point(-73.94000 40.67000)'::st_point,
20, 'mile_us');
(expression) 4326 POLYGON ((-73.94 40.9598410446, -73.9650052554 40.9592177873
, -73.9899020331 40.9573507189, -74.0145823443 40.9542479379, -74
.0389391756 40.9499229014, -74.0628669705 40.9443943641, -74.0862
62103 40.9376862943, -74.1090233418 40.9298277658, -74.1310523018
40.9208528277, -74.1522538813 40.9108003512, -74.1725366824 40.8
997138558, -74.191813413 40.8876413147, -74.2100012676 40.8746349
404, -74.2270222864 40.8607509525, -74.2428036898 40.8460493278,
-74.2572781883 40.8305935344, -74.270384265 40.8144502508, -74.28
20664306 40.7976890725, -74.2922754499 40.7803822052, -74.3009685
386 40.762604149, -74.3081095301 40.7444313721, -74.3136690117 40
.725941978, -74.3176244305 40.7072153662, -74.3199601683 40.68833
18884, -74.3206675854 40.6693725018, -74.3197450343 40.6504184208
, -74.3171978431 40.6315507692, -74.3130382692 40.6128502335, -74
.3072854238 40.5943967192, -74.2999651681 40.5762690118, -74.2911
099818 40.558544444, -74.2807588051 40.5412985687, -74.2689568546
40.5246048426, -74.2557554153 40.5085343173, -74.2412116083 40.4
931553434, -74.2253881367 40.4785332853, -74.2083530102 40.464730
2495, -74.1901792499 40.4518048277, -74.170944575 40.4398118544,
-74.1507310716 40.4288021807, -74.1296248465 40.4188224653, -74.1
077156662 40.4099149825, -74.085096583 40.4021174495, -74.0618635
499 40.3954628715, -74.0381150244 40.389979407, -74.0139515651 40
.3856902529, -73.9894754197 40.3826135501, -73.9647901079 40.3807
623093, -73.94 40.3801443581, -73.9152098921 40.3807623093, -73.8
905245803 40.3826135501, -73.8660484349 40.3856902529, -73.841884
9756 40.389979407, -73.8181364501 40.3954628715, -73.794903417 40
.4021174495, -73.7722843338 40.4099149825, -73.7503751535 40.4188
224653, -73.7292689284 40.4288021807, -73.709055425 40.4398118544
, -73.6898207501 40.4518048277, -73.6716469898 40.4647302495, -73
.6546118633 40.4785332853, -73.6387883917 40.4931553434, -73.6242
445847 40.5085343173, -73.6110431454 40.5246048426, -73.599241194
9 40.5412985687, -73.5888900182 40.558544444, -73.5800348319 40.5
762690118, -73.5727145762 40.5943967192, -73.5669617308 40.612850
2335, -73.5628021569 40.6315507692, -73.5602549657 40.6504184208,
-73.5593324146 40.6693725018, -73.5600398317 40.6883318884, -73.
5623755695 40.7072153662, -73.5663309883 40.725941978, -73.571890
4699 40.7444313721, -73.5790314614 40.762604149, -73.5877245501 4
0.7803822052, -73.5979335694 40.7976890725, -73.609615735 40.8144
502508, -73.6227218117 40.8305935344, -73.6371963102 40.846049327
8, -73.6529777136 40.8607509525, -73.6699987324 40.8746349404, -7
3.688186587 40.8876413147, -73.7074633176 40.8997138558, -73.7277
461187 40.9108003512, -73.7489476982 40.9208528277, -73.770976658
2 40.9298277658, -73.793737897 40.9376862943, -73.8171330295 40.9
443943641, -73.8410608244 40.9499229014, -73.8654176557 40.954247
9379, -73.8900979669 40.9573507189, -73.9149947446 40.9592177873,
-73.94 40.9598410446))
1 row(s) retrieved.