Postgresql 中文操作指南

8.8. Geometric Types #

几何数据类型表示二维空间对象。 Table 8.20 显示了 PostgreSQL 中可用的几何类型。

Geometric data types represent two-dimensional spatial objects. Table 8.20 shows the geometric types available in PostgreSQL.

Table 8.20. Geometric Types

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)

提供了丰富的函数和运算符集,用于执行各种几何运算,例如缩放、平移、旋转和确定交点。它们在 Section 9.11 中进行了说明。

A rich set of functions and operators is available to perform various geometric operations such as scaling, translation, rotation, and determining intersections. They are explained in Section 9.11.

8.8.1. Points #

点是用于几何类型的基本二维模块。通过以下语法之一指定类型 point 的值:

Points are the fundamental two-dimensional building block for geometric types. Values of type point are specified using either of the following syntaxes:

( x , y )
  x , y

其中 xy 分别是坐标,是浮点数。

where x and y are the respective coordinates, as floating-point numbers.

使用第一个语法输出点。

Points are output using the first syntax.

8.8.2. Lines #

线段用线性方程 A_x + _B_y + _C=0 来表示,其中,AB 都不为零。line 类型的值按以下格式作为输入和输出:

Lines are represented by the linear equation A_x + _B_y + _C = 0, where A and B are not both zero. Values of type line are input and output in the following form:

{ A, B, C }

另外,以下任何格式都可以作为输入:

Alternatively, any of the following forms can be used for input:

[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( 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.

8.8.3. Line Segments #

线段用作为线段端点的成对点表示。lseg 类型的值使用以下任何语法指定:

Line segments are represented by pairs of points that are the endpoints of the segment. Values of type lseg are specified using any of the following syntaxes:

[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
  ( x1 , y1 ) , ( x2 , y2 )
    x1 , y1   ,   x2 , y2

其中,(_x1,y1)_ 和 (_x2,y2)_ 是线段的端点。

where (_x1,y1)_ and (_x2,y2)_ are the end points of the line segment.

使用第一个语法输出线段。

Line segments are output using the first syntax.

8.8.4. Boxes #

盒子用作为盒子对角线的成对点表示。box 类型的值使用以下任何语法指定:

Boxes are represented by pairs of points that are opposite corners of the box. Values of type box are specified 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 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 will be reordered as needed to store the upper right and lower left corners, in that order.

8.8.5. Paths #

路径由连接点列表表示。路径可以是 open,其中列表中的第一个和最后一个点被认为是未连接的,也可以是 closed,其中列表中的第一个和最后一个点被认为是连接的。

Paths are represented by lists of connected points. Paths can be open, where the first and last points in the list are considered not connected, or closed, where the first and last points are considered connected.

path 类型的值使用以下任何语法指定:

Values of type path are specified 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 end points 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.

8.8.6. Polygons #

多边形由点列表 (多边形的顶点) 表示。多边形与闭合路径非常相似;本质区别在于多边形被认为包含在其内部的面积,而路径则不包含。

Polygons are represented by lists of points (the vertexes of the polygon). Polygons are very similar to closed paths; the essential difference is that a polygon is considered to include the area within it, while a path is not.

polygon 类型的值使用以下任何语法指定:

Values of type polygon are specified 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 end points of the line segments comprising the boundary of the polygon.

使用第一个语法输出多边形。

Polygons are output using the first syntax.

8.8.7. Circles #

圆由中心点和半径表示。类型 circle 的值使用以下任何语法指定:

Circles are represented by a center point and radius. Values of type circle are specified using any of the following syntaxes:

< ( x , y ) , r >
( ( x , y ) , r )
  ( x , y ) , r
    x , y   , r

其中 (_xy)_ 是中心点,而 r 是圆的半径。

where (_x,y)_ is the center point and r is the radius of the circle.

圆形输出使用第一个语法。

Circles are output using the first syntax.