Geometric data types represent two-dimensional spatial objects. The following table lists the available geometric types in PostgreSQL.
| Name | Storage size | Description | Representation |
|---|---|---|---|
point | 16 bytes | Point on a plane | (x,y) |
line | 32 bytes | Infinite line | {A,B,C} |
lseg | 32 bytes | Finite line segment | ((x1,y1),(x2,y2)) |
box | 32 bytes | Rectangular box | ((x1,y1),(x2,y2)) |
path | 16+16n bytes | Closed path (similar to polygon) | ((x1,y1),...) |
path | 16+16n bytes | Open path | [(x1,y1),...] |
polygon | 40+16n bytes | Polygon (similar to closed path) | ((x1,y1),...) |
circle | 24 bytes | Circle | <(x,y),r> (center point and radius) |
A rich set of functions and operators is available for geometric operations such as scaling, translation, rotation, and determining intersections.
Points
Points are the fundamental two-dimensional building block for geometric types. Specify a point value using either syntax:
( x , y )
x , yx and y are the respective coordinates, as floating-point numbers. Points are output using the first syntax.
Lines
Lines are represented by the linear equation A x + B y + C = 0, where A and B are not both zero. Input and output for line values uses this form:
{ A, B, C }The following input forms are also accepted:
[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 )
x1 , y1 , x2 , y2where (x1,y1) and (x2,y2) are two different points on the line.
Line segments
Line segments are represented by pairs of points that are the endpoints of the segment. Specify an lseg value using any of the following syntaxes:
[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 )
x1 , y1 , x2 , y2where (x1,y1) and (x2,y2) are the endpoints of the line segment. Line segments are output using the first syntax.
Boxes
Boxes are represented by pairs of points that are opposite corners of the box. Specify a box value using any of the following syntaxes:
( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 )
x1 , y1 , x2 , y2where (x1,y1) and (x2,y2) are any two opposite corners of the box. Boxes are output using the second syntax.
Any two opposite corners can be supplied on input, but the values are reordered as needed to store the upper right and lower left corners, in that order.
Paths
Paths are represented by lists of connected points. A path can be _open_ (the first and last points are not connected) or _closed_ (the first and last points are connected).
Specify a path value using any of the following syntaxes:
[ ( x1 , y1 ) , ... , ( xn , yn ) ]
( ( x1 , y1 ) , ... , ( xn , yn ) )
( x1 , y1 ) , ... , ( xn , yn )
( x1 , y1 , ... , xn , yn )
x1 , y1 , ... , xn , ynwhere the points are the endpoints of the line segments comprising the path. Square brackets ([]) indicate an open path, while parentheses (()) indicate a closed path. When the outermost parentheses are omitted, as in the third through fifth syntaxes, a closed path is assumed. Paths are output using the first or second syntax, as appropriate.
Polygons
Polygons are represented by lists of points (the vertices of the polygon). Polygons are very similar to closed paths, but are stored differently and have their own set of support routines.
Specify a polygon value using any of the following syntaxes:
( ( x1 , y1 ) , ... , ( xn , yn ) )
( x1 , y1 ) , ... , ( xn , yn )
( x1 , y1 , ... , xn , yn )
x1 , y1 , ... , xn , ynwhere the points are the endpoints of the line segments comprising the boundary of the polygon. Polygons are output using the first syntax.
Circles
Circles are represented by a center point and radius. Specify a circle value using any of the following syntaxes:
< ( x , y ) , r >
( ( x , y ) , r )
( x , y ) , r
x , y , rwhere (x,y) is the center point and r is the radius. Circles are output using the first syntax.