几何操作符
-
+
描述:平移。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' + point '(2.0,0)' AS RESULT; result
(3,1),(2,0) (1 row) ```
-
-
描述:平移。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' - point '(2.0,0)' AS RESULT; result
(-1,1),(-2,0) (1 row) ```
-
*
描述:伸展/旋转。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' * point '(2.0,0)' AS RESULT; result
(2,2),(0,0) (1 row) ```
-
/
描述:收缩/旋转。
示例:
``` postgres=# SELECT box '((0,0),(2,2))' / point '(2.0,0)' AS RESULT; result
(1,1),(0,0) (1 row) ```
-
#
描述:两个图形交面。
示例:
``` postgres=# SELECT box '((1,-1),(-1,1))' # box '((1,1),(-2,-2))' AS RESULT; result
(1,1),(-1,-1) (1 row) ```
-
#
描述:图形的路径数目或多边形顶点数。
示例:
``` postgres=# SELECT # path'((1,0),(0,1),(-1,0))' AS RESULT; result
3(1 row) ```
-
@-@
描述:图形的长度或者周长。
示例:
``` postgres=# SELECT @-@ path '((0,0),(1,0))' AS RESULT; result
2(1 row) ```
-
@@
描述:图形的中心。
示例:
``` postgres=# SELECT @@ circle '((0,0),10)' AS RESULT; result
(0,0) (1 row) ```
-
<->
描述:两个图形之间的距离。
示例:
``` postgres=# SELECT circle '((0,0),1)' <-> circle '((5,0),1)' AS RESULT; result
3(1 row) ```
-
&&
描述:两个图形是否重叠(有一个共同点就为真)。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' && box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
<<
描述:图形是否全部在另一个图形的左边(没有相同的横坐标)。
示例:
``` postgres=# SELECT circle '((0,0),1)' << circle '((5,0),1)' AS RESULT; result
t (1 row) ```
-
>>
描述:图形是否全部在另一个图形的右边(没有相同的横坐标)。
示例:
``` postgres=# SELECT circle '((5,0),1)' >> circle '((0,0),1)' AS RESULT; result
t (1 row) ```
-
&<
描述:图形的最右边是否不超过在另一个图形的最右边。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' &< box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
&>
描述:图形的最左边是否不超过在另一个图形的最左边。
示例:
``` postgres=# SELECT box '((0,0),(3,3))' &> box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
<<|
描述:图形是否全部在另一个图形的下边(没有相同的纵坐标)。
示例:
``` postgres=# SELECT box '((0,0),(3,3))' <<| box '((3,4),(5,5))' AS RESULT; result
t (1 row) ```
-
|>>
描述:图形是否全部在另一个图形的上边(没有相同的纵坐标)。
示例:
``` postgres=# SELECT box '((3,4),(5,5))' |>> box '((0,0),(3,3))' AS RESULT; result
t (1 row) ```
-
&<|
描述:图形的最上边是否不超过另一个图形的最上边。
示例:
``` postgres=# SELECT box '((0,0),(1,1))' &<| box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
|&>
描述:图形的最下边是否不超过另一个图形的最下边。
示例:
``` postgres=# SELECT box '((0,0),(3,3))' |&> box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
<^
描述:图形是否低于另一个图形(允许两个图形有接触)。
示例:
``` postgres=# SELECT box '((0,0),(-3,-3))' <^ box '((0,0),(2,2))' AS RESULT; result
t (1 row) ```
-
>^
描述:图形是否高于另一个图形(允许两个图形有接触)。
示例:
``` postgres=# SELECT box '((0,0),(2,2))' >^ box '((0,0),(-3,-3))' AS RESULT; result
t (1 row) ```
-
?#
描述:两个图形是否相交。
示例:
``` postgres=# SELECT lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))' AS RESULT; result
t (1 row) ```
-
?-
描述:图形是否处于水平位置。
示例:
``` postgres=# SELECT ?- lseg '((-1,0),(1,0))' AS RESULT; result
t (1 row) ```
-
?-
描述:图形是否水平对齐。
示例:
``` postgres=# SELECT point '(1,0)' ?- point '(0,0)' AS RESULT; result
t (1 row) ```
-
?|
描述:图形是否处于竖直位置。
示例:
``` postgres=# SELECT ?| lseg '((-1,0),(1,0))' AS RESULT; result
f (1 row) ```
-
?|
描述:图形是否竖直对齐。
示例:
``` postgres=# SELECT point '(0,1)' ?| point '(0,0)' AS RESULT; result
t (1 row) ```
-
?-|
描述:两条线是否垂直。
示例:
``` postgres=# SELECT lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' AS RESULT; result
t (1 row) ```
-
?||
描述:两条线是否平行。
示例:
``` postgres=# SELECT lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' AS RESULT; result
t (1 row) ```
-
@>
描述:图形是否包含另一个图形。
示例:
``` postgres=# SELECT circle '((0,0),2)' @> point '(1,1)' AS RESULT; result
t (1 row) ```
-
<@
描述:图形是否被包含于另一个图形。
示例:
``` postgres=# SELECT point '(1,1)' <@ circle '((0,0),2)' AS RESULT; result
t (1 row) ```
-
\~=
描述:两个图形是否相同?
示例:
``` postgres=# SELECT polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' AS RESULT; result
t (1 row) ```
几何函数
-
area(object)
描述:计算图形的面积。
返回类型:double precision
示例:
``` postgres=# SELECT area(box '((0,0),(1,1))') AS RESULT; result
1(1 row) ```
-
center(object)
描述:计算图形的中心。
返回类型:point
示例:
``` postgres=# SELECT center(box '((0,0),(1,2))') AS RESULT; result
(0.5,1) (1 row) ```
-
diameter(circle)
描述:计算圆的直径。
返回类型:double precision
示例:
``` postgres=# SELECT diameter(circle '((0,0),2.0)') AS RESULT; result
4(1 row) ```
-
height(box)
描述:矩形的竖直高度。
返回类型:double precision
示例:
``` postgres=# SELECT height(box '((0,0),(1,1))') AS RESULT; result
1(1 row) ```
-
isclosed(path)
描述:图形是否为闭合路径。
返回类型:Boolean
示例:
``` postgres=# SELECT isclosed(path '((0,0),(1,1),(2,0))') AS RESULT; result
t (1 row) ```
-
isopen(path)
描述:图形是否为开放路径。
返回类型:Boolean
示例:
``` postgres=# SELECT isopen(path '[(0,0),(1,1),(2,0)]') AS RESULT; result
t (1 row) ```
-
length(object)
描述:计算图形的长度。
返回类型:double precision
示例:
``` postgres=# SELECT length(path '((-1,0),(1,0))') AS RESULT; result
4(1 row) ```
-
npoints(path)
描述:计算路径的顶点数。
返回类型:int
示例:
``` postgres=# SELECT npoints(path '[(0,0),(1,1),(2,0)]') AS RESULT; result
3(1 row) ```
-
npoints(polygon)
描述:计算多边形的顶点数。
返回类型:int
示例:
``` postgres=# SELECT npoints(polygon '((1,1),(0,0))') AS RESULT; result
2(1 row) ```
-
pclose(path)
描述:把路径转换为闭合路径。
返回类型:path
示例:
``` postgres=# SELECT pclose(path '[(0,0),(1,1),(2,0)]') AS RESULT; result
((0,0),(1,1),(2,0)) (1 row) ```
-
popen(path)
描述:把路径转换为开放路径。
返回类型:path
示例:
``` postgres=# SELECT popen(path '((0,0),(1,1),(2,0))') AS RESULT; result
[(0,0),(1,1),(2,0)] (1 row) ```
-
radius(circle)
描述:计算圆的半径。
返回类型:double precision
示例:
``` postgres=# SELECT radius(circle '((0,0),2.0)') AS RESULT; result
2(1 row) ```
-
width(box)
描述:计算矩形的水平尺寸。
返回类型:double precision
示例:
``` postgres=# SELECT width(box '((0,0),(1,1))') AS RESULT; result
1(1 row) ```
几何类型转换函数
-
box(circle)
描述:将圆转换成矩形
返回类型:box
示例:
``` postgres=# SELECT box(circle '((0,0),2.0)') AS RESULT; result
(1.41421356237309,1.41421356237309),(-1.41421356237309,-1.41421356237309) (1 row) ```
-
box(point, point)
描述:将点转换成矩形
返回类型:box
示例:
``` postgres=# SELECT box(point '(0,0)', point '(1,1)') AS RESULT; result
(1,1),(0,0) (1 row) ```
-
box(polygon)
描述:将多边形转换成矩形
返回类型:box
示例:
``` postgres=# SELECT box(polygon '((0,0),(1,1),(2,0))') AS RESULT; result
(2,1),(0,0) (1 row) ```
-
circle(box)
描述:矩形转换成圆
返回类型:circle
示例:
``` postgres=# SELECT circle(box '((0,0),(1,1))') AS RESULT; result
<(0.5,0.5),0.707106781186548> (1 row) ```
-
circle(point, double precision)
描述:将圆心和半径转换成圆
返回类型:circle
示例:
``` postgres=# SELECT circle(point '(0,0)', 2.0) AS RESULT; result
<(0,0),2> (1 row) ```
-
circle(polygon)
描述:将多边形转换成圆
返回类型:circle
示例:
``` postgres=# SELECT circle(polygon '((0,0),(1,1),(2,0))') AS RESULT; result
<(1,0.333333333333333),0.924950591148529> (1 row) ```
-
lseg(box)
描述:矩形对角线转化成线段
返回类型:lseg
示例:
``` postgres=# SELECT lseg(box '((-1,0),(1,0))') AS RESULT; result
[(1,0),(-1,0)] (1 row) ```
-
lseg(point, point)
描述:点转换成线段
返回类型:lseg
示例:
``` postgres=# SELECT lseg(point '(-1,0)', point '(1,0)') AS RESULT; result
[(-1,0),(1,0)] (1 row) ```
-
path(polygon)
描述:多边形转换成路径
返回类型:path
示例:
``` postgres=# SELECT path(polygon '((0,0),(1,1),(2,0))') AS RESULT; result
((0,0),(1,1),(2,0)) (1 row) ```
-
point(double precision, double precision)
描述:结点
返回类型:point
示例:
``` postgres=# SELECT point(23.4, -44.5) AS RESULT; result
(23.4,-44.5) (1 row) ```
-
point(box)
描述:矩形的中心
返回类型:point
示例:
``` postgres=# SELECT point(box '((-1,0),(1,0))') AS RESULT; result
(0,0) (1 row) ```
-
point(circle)
描述:圆心
返回类型:point
示例:
``` postgres=# SELECT point(circle '((0,0),2.0)') AS RESULT; result
(0,0) (1 row) ```
-
point(lseg)
描述:线段的中心
返回类型:point
示例:
``` postgres=# SELECT point(lseg '((-1,0),(1,0))') AS RESULT; result
(0,0) (1 row) ```
-
point(polygon)
描述:多边形的中心
返回类型:point
示例:
``` postgres=# SELECT point(polygon '((0,0),(1,1),(2,0))') AS RESULT; result
(1,0.333333333333333) (1 row) ```
-
polygon(box)
描述:矩形转换成4点多边形
返回类型:polygon
示例:
``` postgres=# SELECT polygon(box '((0,0),(1,1))') AS RESULT; result
((0,0),(0,1),(1,1),(1,0)) (1 row) ```
-
polygon(circle)
描述:圆转换成12点多边形
返回类型:polygon
示例:
``` postgres=# SELECT polygon(circle '((0,0),2.0)') AS RESULT; result
((-2,0),(-1.73205080756888,1),(-1,1.73205080756888),(-1.22464679914735e-16,2),(1,1.73205080756888),(1.73205080756888,1),(2,2.44929359829471e-16),(1.73205080756888,-0.999999999999999),(1,-1.73205080756888),(3.67394039744206e-16,-2),(-0.999999999999999,-1.73205080756888),(-1.73205080756888,-1)) (1 row) ```
-
polygon(npts, circle)
描述:圆转换成npts点多边形
返回类型:polygon
示例:
``` postgres=# SELECT polygon(12, circle '((0,0),2.0)') AS RESULT; result
((-2,0),(-1.73205080756888,1),(-1,1.73205080756888),(-1.22464679914735e-16,2),(1,1.73205080756888),(1.73205080756888,1),(2,2.44929359829471e-16),(1.73205080756888,-0.999999999999999),(1,-1.73205080756888),(3.67394039744206e-16,-2),(-0.999999999999999,-1.73205080756888),(-1.73205080756888,-1)) (1 row) ```
-
polygon(path)
描述:路径转换成多边形
返回类型:polygon
示例:
``` postgres=# SELECT polygon(path '((0,0),(1,1),(2,0))') AS RESULT; result
((0,0),(1,1),(2,0)) (1 row) ```




