Geometric types

更新时间:
复制 MD 格式

Geometric data types represent two-dimensional spatial objects. The following table lists the available geometric types in PostgreSQL.

NameStorage sizeDescriptionRepresentation
point16 bytesPoint on a plane(x,y)
line32 bytesInfinite line{A,B,C}
lseg32 bytesFinite line segment((x1,y1),(x2,y2))
box32 bytesRectangular box((x1,y1),(x2,y2))
path16+16n bytesClosed path (similar to polygon)((x1,y1),...)
path16+16n bytesOpen path[(x1,y1),...]
polygon40+16n bytesPolygon (similar to closed path)((x1,y1),...)
circle24 bytesCircle<(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 , y

x 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 , y2

where (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 , y2

where (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 , y2

where (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 , yn

where 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 , yn

where 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   , r

where (x,y) is the center point and r is the radius. Circles are output using the first syntax.