On this page
9.11. 几何函数和运算符
几何类型point
,box
,lseg
,line
,path
,polygon
和circle
具有大量本机支持功能和运算符,如Table 9.33,Table 9.34和Table 9.35所示。
Caution
请注意,“相同”运算符~=
代表point
,box
,polygon
和circle
类型的通常的相等概念。其中一些类型也具有=
运算符,但是=
仅比较相等的* area *。其他标量比较运算符(<=
等)同样比较这些类型的面积。
表 9.33. 几何运算符
Operator | Description | Example |
---|---|---|
+ |
Translation | box '((0,0),(1,1))' + point '(2.0,0)' |
- |
Translation | box '((0,0),(1,1))' - point '(2.0,0)' |
* |
Scaling/rotation | box '((0,0),(1,1))' * point '(2.0,0)' |
/ |
Scaling/rotation | box '((0,0),(2,2))' / point '(2.0,0)' |
# |
点或交点箱 | box '((1,-1),(-1,1))' # box '((1,1),(-2,-2))' |
# |
路径或多边形中的点数 | # path '((1,0),(0,1),(-1,0))' |
@-@ |
长度或周长 | @-@ path '((0,0),(1,0))' |
@@ |
Center | @@ circle '((0,0),10)' |
## |
最接近第二个操作数上第一个操作数的点 | point '(0,0)' ## lseg '((2,0),(0,2))' |
<-> |
Distance between | circle '((0,0),1)' <-> circle '((5,0),1)' |
&& |
重叠? (有一点共同点使这成为事实.) | box '((0,0),(1,1))' && box '((0,0),(2,2))' |
<< |
是严格离开的吗? | circle '((0,0),1)' << circle '((5,0),1)' |
>> |
严格来说是对的吗? | circle '((5,0),1)' >> circle '((0,0),1)' |
&< |
不延伸到右边吗? | box '((0,0),(1,1))' &< box '((0,0),(2,2))' |
&> |
不延伸到左边吗? | box '((0,0),(3,3))' &> box '((0,0),(2,2))' |
<<| |
严格低于? | box '((0,0),(3,3))' <<| box '((3,4),(5,5))' |
|>> |
严格以上吗? | box '((3,4),(5,5))' |>> box '((0,0),(3,3))' |
&<| |
不延伸以上? | 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 '((0,5),1)' |
>^ |
是否在上方(允许触摸)? | circle '((0,5),1)' >^ circle '((0,0),1)' |
?# |
Intersects? | lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))' |
?- |
Is horizontal? | ?- lseg '((-1,0),(1,0))' |
?- |
水平对齐? | point '(1,0)' ?- point '(0,0)' |
?| |
Is vertical? | ?| lseg '((-1,0),(1,0))' |
?| |
垂直对齐? | point '(0,1)' ?| point '(0,0)' |
?-| |
Is perpendicular? | lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' |
?|| |
Are parallel? | lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' |
@> |
Contains? | circle '((0,0),2)' @> point '(1,1)' |
<@ |
包含在里面还是上面? | point '(1,1)' <@ circle '((0,0),2)' |
~= |
Same as? | polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' |
Note
在 PostgreSQL 8.2 之前,包含运算符@>
和<@
分别称为~
和@
。这些名称仍然可用,但已过时,最终将被删除。
表 9.34. 几何函数
Function | Return Type | Description | Example |
---|---|---|---|
area(object) |
double precision |
area | area(box '((0,0),(1,1))') |
center(object) |
point |
center | 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 | length(path '((-1,0),(1,0))') |
npoints(path) |
int |
点数 | npoints(path '[(0,0),(1,1),(2,0)]') |
npoints(polygon) |
int |
点数 | npoints(polygon '((1,1),(0,0))') |
pclose(path) |
path |
将路径转换为封闭 | pclose(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))') |
表 9.35. 几何类型转换函数
可以访问point
的两个组件号,就好像该点是具有索引 0 和 1 的数组一样。例如,如果t.p
是point
列,则SELECT p[0] FROM t
检索 X 坐标,而UPDATE t SET p[1] = ...
更改 Y 坐标。以相同的方式,类型box
或lseg
的值可以视为两个point
值的数组。
area
函数适用于box
,circle
和path
类型。如果path
中的点不相交,则area
函数仅适用于path
数据类型。例如,path
'((0,0),(0,1),(2,1),(2,2),(1,2),(1,0),(0,0))'::PATH
将不起作用;但是,以下视觉上相同的path
'((0,0),(0,1),(1,1),(1,2),(2,2),(2,1),(1,1),(1,0),(0,0))'::PATH
将起作用。如果相交与不相交的path
的概念令人困惑,请在一张方格纸上并排绘制以上path
的内容。