有许多内置函数和操作符支持 几何类型point,box,lseg, line,path,polygon 和 circle 等, 在Table 6-20, Table 6-21,和 Table 6-22。
Table 6-20. 几何函数和操作符
| 操作符 | 描述 | 用法 |
|---|---|---|
| + | 平移 | box '((0,0),(1,1))' + point '(2.0,0)' |
| - | 平移 | box '((0,0),(1,1))' - point '(2.0,0)' |
| * | 伸缩/旋转 | box '((0,0),(1,1))' * point '(2.0,0)' |
| / | 伸缩/旋转 | box '((0,0),(2,2))' / point '(2.0,0)' |
| # | 交 | '((1,-1),(-1,1))' # '((1,1),(-1,-1))' |
| # | 多边形顶点数 | # '((1,0),(0,1),(-1,0))' |
| ## | 最近点 | point '(0,0)' ## lseg '((2,0),(0,2))' |
| && | 重叠? | box '((0,0),(1,1))' && box '((0,0),(2,2))' |
| &< | 左重叠? | box '((0,0),(1,1))' &< box '((0,0),(2,2))' |
| &> | 右重叠? | box '((0,0),(3,3))' &> box '((0,0),(2,2))' |
| <-> | 两者间距离 | circle '((0,0),1)' <-> circle '((5,0),1)' |
| << | 在左边? | circle '((0,0),1)' << circle '((5,0),1)' |
| <^ | 低于? | circle '((0,0),1)' <^ circle '((0,5),1)' |
| >> | 在右边? | circle '((5,0),1)' >> circle '((0,0),1)' |
| >^ | 高于? | circle '((0,5),1)' >^ circle '((0,0),1)' |
| ?# | 相交或重叠? | lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))'; |
| ?- | 水平? | point '(1,0)' ?- point '(0,0)' |
| ?-| | 垂直? | lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' |
| @-@ | 长度或周长 | @-@ path '((0,0),(1,0))' |
| ?| | 竖直? | point '(0,1)' ?| point '(0,0)' |
| ?|| | 平行? | lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' |
| @ | 包含或在...上 | point '(1,1)' @ circle '((0,0),2)' |
| @@ | ...的中心 | @@ circle '((0,0),10)' |
| ~= | 与...相同 | polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' |
Table 6-21. 几何函数
| 函数 | 返回 | 描述 | 例子 |
|---|---|---|---|
| area(object) | double precision | 目标的面积 | area(box '((0,0),(1,1))') |
| box(box,box) | box | 方的交 | box(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))') |
| center(object) | point | 对象中心 | center(box '((0,0),(1,2))') |
| diameter(circle) | double precision | 圆直径 | diameter(circle '((0,0),2.0)') |
| height(box) | double precision | 方的竖直高度 | height(box '((0,0),(1,1))') |
| isclosed(path) | boolean | 是闭合路径吗? | isclosed(path '((0,0),(1,1),(2,0))') |
| isopen(path) | boolean | 是开环路径吗? | isopen(path '[(0,0),(1,1),(2,0)]') |
| length(object) | double precision | 对象长度 | length(path '((-1,0),(1,0))') |
| npoints(path) | integer | 点数 | npoints(path '[(0,0),(1,1),(2,0)]') |
| npoints(polygon) | integer | 点数 | npoints(polygon '((1,1),(0,0))') |
| pclose(path) | path | 把路径转换为闭合 | popen(path '[(0,0),(1,1),(2,0)]') |
| popen(path) | path | 把路径转换为开环的 | popen(path '((0,0),(1,1),(2,0))') |
| radius(circle) | double precision | 圆半径 | radius(circle '((0,0),2.0)') |
| width(box) | double precision | 水平尺寸(宽) | width(box '((0,0),(1,1))') |
Table 6-22. 几何类型转换函数
| 函数 | 返回 | 描述 | 例子 |
|---|---|---|---|
| box(circle) | box | 将圆转换成长方形 | box(cricle '((0,0),2.0)') |
| box(point,point) | box | 将点转换成长方形 | box(point '(0,0)', point '(1,1)') |
| box(polygon) | box | 将多边形转换成长方形 | box(polygon '((0,0),(1,1),(2,0))') |
| circle(box) | circle | 方转换成圆 | circle(box '((0,0),(1,1))') |
| circle(point,double precision) | circle | 点转换成圆 | circle(point '(0,0)',2.0) |
| lseg(box) | lseg | 将长方形判为lseg | lseg(box '((-1,0),(1,0))') |
| lseg(point,point) | lseg | 点转换成lseg | lseg(point '(-1,0)',point '(1,0)') |
| path(polygon) | point | 多边形转换成路径 | path(polygon '((0,0),(1,1),(2,0))') |
| point(circle) | point | 转换成点(中心) | point(circle '((0,0),2.0)') |
| point(lseg,lseg) | point | 转换成点(相交) | point(lseg '((-1,0),(1,0))', lseg '((-2,-2),(2,2))') |
| point(polygon) | point | 多边形中心 | point(polygon '((0,0),(1,1),(2,0))') |
| polygon(box) | polygon | 转换成4点的多边形 | polygon(box '((0,0),(1,1))') |
| polygon(circle) | polygon | 转换成12点的多边形 | polygon(circle '((0,0),2.0)') |
| polygon(npts,circle) | polygon | 转换成npts 点多边形 | polygon(12, circle '((0,0),2.0)') |
| polygon(path) | polygon | 路径转换成多边形 | polygon(path '((0,0),(1,1),(2,0))') |
我们可以吧一个 point 的两个组成部分当作下标分别为 0 和 1 的数组元素进行访问。比如,如果 t.p 是一个 point 字段,那么 SELECT p[0] FROM t 检索 X 座标; UPDATE t SET p[1] = ... 改变 Y 座标。同样, box 或者 lseg 可以当作两个 point 的数组看待。