华为云云数据库GaussDB几何函数和操作符_云淘科技

几何操作符

+

描述:平移。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' + point '(2.0,0)' AS RESULT;
   result    
-------------
 (3,1),(2,0)
(1 row)

-e

描述:平移。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' - point '(2.0,0)' AS RESULT;
    result     
---------------
 (-1,1),(-2,0)
(1 row)

*

描述:伸展/旋转。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' * point '(2.0,0)' AS RESULT;
   result    
-------------
 (2,2),(0,0)
(1 row)

/

描述:收缩/旋转。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(2,2))' / point '(2.0,0)' AS RESULT;
   result    
-------------
 (1,1),(0,0)
(1 row)

#

描述:两个图形交面。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((1,-1),(-1,1))' # box '((1,1),(-2,-2))' AS RESULT;
 result 
---------------
 (1,1),(-1,-1)
(1 row)

#

描述:图形的路径数目或多边形顶点数。

示例:

1
2
3
4
5
gaussdb=# SELECT # path'((1,0),(0,1),(-1,0))' AS RESULT;
 result 
--------
      3
(1 row)

@-@

描述:图形的长度或者周长。

示例:

1
2
3
4
5
gaussdb=# SELECT @-@ path '((0,0),(1,0))' AS RESULT;
 result 
--------
      2
(1 row)

@@

描述:图形的中心。

示例:

1
2
3
4
5
gaussdb=# SELECT @@ circle '((0,0),10)' AS RESULT;
 result 
--------
 (0,0)
(1 row)

描述:两个图形之间的距离。

示例:

1
2
3
4
5
gaussdb=# SELECT circle '((0,0),1)'  circle '((5,0),1)' AS RESULT;
 result 
--------
      3
(1 row)

&&

描述:两个图形是否重叠(有一个共同点就为真)。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' && box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

<<

描述:图形是否全部在另一个图形的左边(没有相同的横坐标)。

示例:

1
2
3
4
5
gaussdb=# SELECT circle '((0,0),1)' << circle '((5,0),1)' AS RESULT;
 result 
--------
 t
(1 row)

>>

描述:图形是否全部在另一个图形的右边(没有相同的横坐标)。

示例:

1
2
3
4
5
gaussdb=# SELECT circle '((5,0),1)' >> circle '((0,0),1)' AS RESULT;
 result 
--------
 t
(1 row)

&<

描述:图形的最右边是否不超过在另一个图形的最右边。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' &< box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

&>

描述:图形的最左边是否不超过在另一个图形的最左边。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(3,3))' &> box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

<<|

描述:图形是否全部在另一个图形的下边(没有相同的纵坐标)。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(3,3))' <<| box '((3,4),(5,5))' AS RESULT;
 result 
--------
 t
(1 row)

|>>

描述:图形是否全部在另一个图形的上边(没有相同的纵坐标)。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((3,4),(5,5))' |>> box '((0,0),(3,3))' AS RESULT;
 result 
--------
 t
(1 row)

&<|

描述:图形的最上边是否不超过另一个图形的最上边。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(1,1))' &<| box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

|&>

描述:图形的最下边是否不超过另一个图形的最下边。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(3,3))' |&> box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

<^

描述:图形是否低于另一个图形(允许两个图形有接触)。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(-3,-3))' <^ box '((0,0),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

>^

描述:图形是否高于另一个图形(允许两个图形有接触)。

示例:

1
2
3
4
5
gaussdb=# SELECT box '((0,0),(2,2))' >^ box '((0,0),(-3,-3))'  AS RESULT;
 result 
--------
 t
(1 row)

?#

描述:两个图形是否相交。

示例:

1
2
3
4
5
gaussdb=# SELECT lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))' AS RESULT;
 result 
--------
 t
(1 row)

?-

描述:图形是否处于水平位置。

示例:

1
2
3
4
5
gaussdb=# SELECT ?- lseg '((-1,0),(1,0))' AS RESULT;
 result 
--------
 t
(1 row)

?-

描述:图形是否水平对齐。

示例:

1
2
3
4
5
gaussdb=# SELECT point '(1,0)' ?- point '(0,0)' AS RESULT;
 result 
--------
 t
(1 row)

?|

描述:图形是否处于竖直位置。

示例:

1
2
3
4
5
gaussdb=# SELECT ?| lseg '((-1,0),(1,0))' AS RESULT;
 result 
--------
 f
(1 row)

?|

描述:图形是否竖直对齐。

示例:

1
2
3
4
5
gaussdb=# SELECT point '(0,1)' ?| point '(0,0)' AS RESULT;
 result 
--------
 t
(1 row)

?-|

描述:两条线是否垂直。

示例:

1
2
3
4
5
gaussdb=# SELECT lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' AS RESULT;
 result 
--------
 t
(1 row)

?||

描述:两条线是否平行。

示例:

1
2
3
4
5
gaussdb=# SELECT lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' AS RESULT;
 result 
--------
 t
(1 row)

@>

描述:图形是否包含另一个图形。

示例:

1
2
3
4
5
gaussdb=# SELECT circle '((0,0),2)' @> point '(1,1)' AS RESULT;
 result 
--------
 t
(1 row)

<@

描述:图形是否被包含于另一个图形。

示例:

1
2
3
4
5
gaussdb=# SELECT point '(1,1)' <@ circle '((0,0),2)' AS RESULT;
 result 
--------
 t
(1 row)

~=

描述:两个图形是否相同?

示例:

1
2
3
4
5
gaussdb=# SELECT polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' AS RESULT;
 result 
--------
 t
(1 row)

几何函数

area(object)

描述:计算图形的面积。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT area(box '((0,0),(1,1))') AS RESULT;
 result 
--------
      1
(1 row)

center(object)

描述:计算图形的中心。

返回类型:point

示例:

1
2
3
4
5
gaussdb=# SELECT center(box '((0,0),(1,2))') AS RESULT;
 result  
---------
 (0.5,1)
(1 row)

diameter(circle)

描述:计算圆的直径。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT diameter(circle '((0,0),2.0)') AS RESULT;
 result 
--------
      4
(1 row)

height(box)

描述:矩形的竖直高度。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT height(box '((0,0),(1,1))') AS RESULT;
 result 
--------
      1
(1 row)

isclosed(path)

描述:图形是否为闭合路径。

返回类型:Boolean

示例:

1
2
3
4
5
gaussdb=# SELECT isclosed(path '((0,0),(1,1),(2,0))') AS RESULT;
 result 
--------
 t
(1 row)

isopen(path)

描述:图形是否为开放路径。

返回类型:Boolean

示例:

1
2
3
4
5
gaussdb=# SELECT isopen(path '[(0,0),(1,1),(2,0)]') AS RESULT;
 result 
--------
 t
(1 row)

length(object)

描述:计算图形的长度。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT length(path '((-1,0),(1,0))') AS RESULT;
 result 
--------
      4
(1 row)

npoints(path)

描述:计算路径的顶点数。

返回类型:int

示例:

1
2
3
4
5
gaussdb=# SELECT npoints(path '[(0,0),(1,1),(2,0)]') AS RESULT;
 result 
--------
      3
(1 row)

npoints(polygon)

描述:计算多边形的顶点数。

返回类型:int

示例:

1
2
3
4
5
gaussdb=# SELECT npoints(polygon '((1,1),(0,0))') AS RESULT;
 result 
--------
      2
(1 row)

pclose(path)

描述:把路径转换为闭合路径。

返回类型:path

示例:

1
2
3
4
5
gaussdb=# SELECT pclose(path '[(0,0),(1,1),(2,0)]') AS RESULT;
       result        
---------------------
 ((0,0),(1,1),(2,0))
(1 row)

popen(path)

描述:把路径转换为开放路径。

返回类型:path

示例:

1
2
3
4
5
gaussdb=# SELECT popen(path '((0,0),(1,1),(2,0))') AS RESULT;
       result        
---------------------
 [(0,0),(1,1),(2,0)]
(1 row)

radius(circle)

描述:计算圆的半径。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT radius(circle '((0,0),2.0)') AS RESULT;
 result 
--------
      2
(1 row)

width(box)

描述:计算矩形的水平尺寸。

返回类型:double precision

示例:

1
2
3
4
5
gaussdb=# SELECT width(box '((0,0),(1,1))') AS RESULT;
 result 
--------
      1
(1 row)

几何类型转换函数

box(circle)

描述:将圆转换成矩形

返回类型:box

示例:

1
2
3
4
5
gaussdb=# SELECT box(circle '((0,0),2.0)') AS RESULT;
                                  result                                   
---------------------------------------------------------------------------
 (1.41421356237309,1.41421356237309),(-1.41421356237309,-1.41421356237309)
(1 row)

box(point, point)

描述:将点转换成矩形

返回类型:box

示例:

1
2
3
4
5
gaussdb=# SELECT box(point '(0,0)', point '(1,1)') AS RESULT;
   result    
-------------
 (1,1),(0,0)
(1 row)

box(polygon)

描述:将多边形转换成矩形

返回类型:box

示例:

1
2
3
4
5
gaussdb=# SELECT box(polygon '((0,0),(1,1),(2,0))') AS RESULT;
   result    
-------------
 (2,1),(0,0)
(1 row)

circle(box)

描述:矩形转换成圆

返回类型:circle

示例:

1
2
3
4
5
gaussdb=# SELECT circle(box '((0,0),(1,1))') AS RESULT;
            result             
-------------------------------
 
(1 row)

circle(point, double precision)

描述:将圆心和半径转换成圆

返回类型:circle

示例:

1
2
3
4
5
gaussdb=# SELECT circle(point '(0,0)', 2.0) AS RESULT;
  result   
-----------
 
(1 row)

circle(polygon)

描述:将多边形转换成圆

返回类型:circle

示例:

1
2
3
4
5
gaussdb=# SELECT circle(polygon '((0,0),(1,1),(2,0))') AS RESULT;
                  result                   
-------------------------------------------
 
(1 row)

lseg(box)

描述:矩形对角线转化成线段

返回类型:lseg

示例:

1
2
3
4
5
gaussdb=# SELECT lseg(box '((-1,0),(1,0))') AS RESULT;
     result     
----------------
 [(1,0),(-1,0)]
(1 row)

lseg(point, point)

描述:点转换成线段

返回类型:lseg

示例:

1
2
3
4
5
gaussdb=# SELECT lseg(point '(-1,0)', point '(1,0)') AS RESULT;
     result     
----------------
 [(-1,0),(1,0)]
(1 row)

slope(point, point)

描述:计算两个点构成直线的斜率。

返回类型:double

示例:

gaussdb=# SELECT slope(point '(1,1)', point '(0,0)') AS RESULT;
 result
--------
      1
(1 row)

path(polygon)

描述:多边形转换成路径

返回类型:path

示例:

1
2
3
4
5
gaussdb=# 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

示例:

1
2
3
4
5
gaussdb=# SELECT point(23.4, -44.5) AS RESULT;
    result    
--------------
 (23.4,-44.5)
(1 row)

point(box)

描述:矩形的中心

返回类型:point

示例:

1
2
3
4
5
gaussdb=# SELECT point(box '((-1,0),(1,0))') AS RESULT;
 result 
--------
 (0,0)
(1 row)

point(circle)

描述:圆心

返回类型:point

示例:

1
2
3
4
5
gaussdb=# SELECT point(circle '((0,0),2.0)') AS RESULT;
 result 
--------
 (0,0)
(1 row)

point(lseg)

描述:线段的中心

返回类型:point

示例:

1
2
3
4
5
gaussdb=# SELECT point(lseg '((-1,0),(1,0))') AS RESULT;
 result 
--------
 (0,0)
(1 row)

point(polygon)

描述:多边形的中心

返回类型:point

示例:

1
2
3
4
5
gaussdb=# SELECT point(polygon '((0,0),(1,1),(2,0))') AS RESULT;
        result         
-----------------------
 (1,0.333333333333333)
(1 row)

polygon(box)

描述:矩形转换成4点多边形

返回类型:polygon

示例:

1
2
3
4
5
gaussdb=# SELECT polygon(box '((0,0),(1,1))') AS RESULT;
          result           
---------------------------
 ((0,0),(0,1),(1,1),(1,0))
(1 row)

polygon(circle)

描述:圆转换成12点多边形

返回类型:polygon

示例:

1
2
3
4
5
6
gaussdb=# 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

示例:

1
2
3
4
5
6
gaussdb=# 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

示例:

1
2
3
4
5
gaussdb=# SELECT polygon(path '((0,0),(1,1),(2,0))') AS RESULT;
       result        
---------------------
 ((0,0),(1,1),(2,0))
(1 row)

父主题: 函数和操作符

同意关联代理商云淘科技,购买华为云产品更优惠(QQ 78315851)

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家