Functions that create new geometries with different space configurations

Using existing geometries as a starting point, the following functions create new geometries that represent circular areas or other configurations of space.

For example, given a point that represents the center of a proposed airport, ST_Buffer can create a surface that represents, in circular form, the proposed extent of the airport.

ST_Buffer

The ST_Buffer function can generate a new geometry that extends outward from an existing geometry by a specified radius.

The new geometry is a surface when the existing geometry is buffered or whenever the elements of a collection are so close that the buffers around the single elements of the collection overlap. However, when the buffers are separate, individual buffer surfaces result, in which case ST_Buffer returns a multisurface.

The following figure illustrates the buffer around single and overlapped elements.
Figure 1. ST_Buffer
Begin figure description. Geometry buffered shapes. End figure description.

The ST_Buffer function accepts both positive and negative distance; however, only geometries with a dimension of two (surfaces and multisurfaces) apply a negative buffer. The absolute value of the buffer distance is used whenever the dimension of the source geometry is less than 2 (all geometries that are not surfaces or multisurfaces).

In general, for exterior rings, positive buffer distances generate surface rings that are away from the center of the source geometry; negative buffer distances generate surface or multisurface rings toward the center. For interior rings of a surface or multisurface, a positive buffer distance generates a buffer ring toward the center, and a negative buffer distance generates a buffer ring away from the center.

The buffering process merges surfaces that overlap. Negative distances greater than one half the maximum interior width of a polygon result in an empty geometry.

ST_ConvexHull

The ST_ConvexHull function returns the convex hull of any geometry that has at least three vertices forming a convex.

Vertices are the pairs of X and Y coordinates within geometries. A convex hull is the smallest convex polygon that can be formed by all vertices within a given set of vertices.

The following illustration shows four examples of convex hull. In the first example, an irregular shape resembling the letter c has been drawn. The c is closed by the convex hull. In the fourth example, there are four points with lines in a zig-zag pattern. The convex line goes between points four and two on one side and three and one on the other side.
Figure 2. ST_ConvexHull
Begin figure description. Convex hull function. End figure description.

ST_Difference

ST_Difference takes two geometries of the same dimension as input and returns that portion of the first geometry that is not intersected by the second geometry.

This operation is the spatial equivalent of the logical operator AND NOT. The portion of geometry returned by ST_Difference is itself a geometry—a collection that has the same dimension as the geometries taken as input. If these two geometries are equal—that is, if they occupy the same space— the returned geometry is empty.

To the left of each arrow are two geometries that are given to ST_Difference as input. To the right of each arrow is the output of ST_Difference. If part of the first geometry is intersected by the second, the output is that part of the first geometry that is not intersected. If the geometries given as input are equal, the output is an empty geometry (denoted by the term nil)

This figure illustrates input and output for ST_Difference. For example, if input is points, and point A and point B are the same, the output is null. If point A and point B are different, the output is a new point between the two. If the input is a polygon for Band a smaller but identical polygon for geometry A inside the first, the outcome is null. If the polygons are overlapping, the output is the outer edges of the combined polygons.
Figure 3. ST_Difference
Begin figure description. ST_Difference function. End figure description.

ST_Intersection

The ST_Intersection function returns a set of points, represented as a geometry, that define the intersection of two given geometries.

If the geometries given to ST_Intersection as input do not intersect, or if they do intersect and the dimension of their intersection is less than the geometries' dimensions, ST_Intersection returns an empty geometry.

This figure illustrates ten examples of output for ST_Intersection, which returns information on where given geometries intersect. To the left of each arrow are two intersecting geometries that are given to ST_Intersection as input. To the right of each arrow is the output of ST_Intersection, which is a geometry that represents the intersection created by the geometries at the left.

For example, if B is a linestring and geometry A is a point on the line, the output is the multipoint where geometry A and geometry B converge. If geometry A and geometry B are overlapping polygons, the output is a new multipolygon of only that portion that overlaps.
Figure 4. ST_Intersection
Begin figure description. Intersection function. End figure description.

ST_SymDifference

The ST_SymDifference function returns the symmetric difference (the spatial equivalent of the logical XOR operation) of two intersecting geometries that have the same dimension.

If these geometries are equal, ST_SymDifference returns an empty geometry. If they are not equal, then a portion of one or both of them lies outside the area of intersection.