postgresql----几何类型和函数

postgresql支持的几何类型如下表:

名字存储空间描述表现形式
point16字节平面上的点(x,y)
line32字节直线{A,B,C}
lseg32字节线段((x1,y1),(x2,y2))
box32字节矩形((x1,y1),(x2,y2))
path16+16n字节闭合路径((x1,y1),…)
path16+16n字节开放路径[(x1,y1),…]
polygon40+16n字节多边形((x1,y1),…)
circle24字节<(x,y),r> 

示例:

test=# select point'(1,1)';
 point 
-------
 (1,1)
(1 row)

test=# select line'{1,1,1}';
  line   
---------
 {1,1,1}
(1 row)

test=# select lseg'(1,1),(2,2)';
     lseg      
---------------
 [(1,1),(2,2)]
(1 row)

test=# select box'(1,1),(2,2)';
     box     
-------------
 (2,2),(1,1)
(1 row)

test=# select path'(1,1),(2,2),(2,1)';
        path         
---------------------
 ((1,1),(2,2),(2,1))
(1 row)

test=# select path'[(1,1),(2,2),(2,1)]';
        path         
---------------------
 [(1,1),(2,2),(2,1)]
(1 row)

test=# select polygon'((1,1),(2,2),(2,1))';
       polygon       
---------------------
 ((1,1),(2,2),(2,1))
(1 row)

test=# select circle'<(0,0),1>';
  circle   
-----------
 <(0,0),1>
(1 row)

 

操作符

操作符描述示例结果
+平移select box ‘((0,0),(1,1))’ + point ‘(2.0,0)’;(3,1),(2,0)
平移select box ‘((0,0),(1,1))’ – point ‘(2.0,0)’;(-1,1),(-2,0)
*伸缩/旋转select box ‘((0,0),(1,1))’ * point ‘(2.0,0)’;(2,2),(0,0)
/伸缩/旋转select box ‘((0,0),(2,2))’ / point ‘(2.0,0)’;(1,1),(0,0)
#交点或者交面select box'((1,-1),(-1,1))’ # box'((1,1),(-1,-1))’;(1,1),(-1,-1)
#path或polygon的顶点数select #path'((1,1),(2,2),(2,1))’;3
@-@长度或周长select @-@ path'((1,1),(2,2),(2,1))’;3.41421356237309
@@中心select @@ circle'<(0,0),1>’;(0,0)
##第一个操作数和第二个操作数的最近点select point ‘(0,0)’ ## lseg ‘((2,0),(0,2))’;(1,1)
<->间距select circle ‘<(0,0),1>’ <-> circle ‘<(5,0),1>’;3
&&是否有重叠select box ‘((0,0),(1,1))’ && box ‘((0,0),(2,2))’;t
<<是否严格在左select circle ‘((0,0),1)’ << circle ‘((5,0),1)’;t
>>是否严格在右select circle ‘((0,0),1)’ >> circle ‘((5,0),1)’;f
&<是否没有延伸到右边select box ‘((0,0),(1,1))’ &< box ‘((0,0),(2,2))’;t
&>是否没有延伸到左边select box ‘((0,0),(3,3))’ &> box ‘((0,0),(2,2))’;t
<<|是否严格在下select box ‘((0,0),(3,3))’ <<| box ‘((3,4),(5,5))’;t
|>>是否严格在上select box ‘((3,4),(5,5))’ |>> box ‘((0,0),(3,3))’;t
&<|是否没有延伸到上面select box ‘((0,0),(1,1))’ &<| box ‘((0,0),(2,2))’;t
|&>是否没有延伸到下面select box ‘((0,0),(3,3))’ |&> box ‘((0,0),(2,2))’;t
<^是否低于(允许接触)select box ‘((0,0),(3,3))’ <^ box ‘((3,3),(4,4))’;t
>^是否高于(允许接触)select box ‘((0,0),(3,3))’ >^ box ‘((3,3),(4,4))’;f
?#是否相交select lseg ‘((-1,0),(1,0))’ ?# box ‘((-2,-2),(2,2))’;t
?-是否水平对齐select ?- lseg ‘((-1,1),(1,1))’;t
?-两边图形是否水平对齐select point ‘(1,0)’ ?- point ‘(0,0)’;t
?|是否竖直对齐select ?| lseg ‘((-1,0),(1,0))’;f
?|两边图形是否竖直对齐select point ‘(0,1)’ ?| point ‘(0,0)’;t
?-|是否垂直select lseg ‘((0,0),(0,1))’ ?-| lseg ‘((0,0),(1,0))’;t
?||是否平行select lseg ‘((-1,0),(1,0))’ ?|| lseg ‘((-1,2),(1,2))’;t
@>是否包含select circle ‘((0,0),2)’ @> point ‘(1,1)’;t
<@是否包含于或在图形上select point ‘(1,1)’ <@ circle ‘((0,0),2)’;t
~=是否相同select polygon ‘((0,0),(1,1))’ ~= polygon ‘((1,1),(0,0))’;t

 

函数

函数返回值类型描述示例结果
area(object)double precision面积select area(circle'((0,0),1)’);3.14159265358979
center(object)point中心select center(box'(0,0),(1,1)’);(0.5,0.5)
diameter(circle)double precision圆周长select diameter(circle ‘((0,0),2.0)’);4
height(box)double precision矩形竖直高度select height(box ‘((0,0),(1,1))’);1
isclosed(path)boolean是否为闭合路径select isclosed(path ‘((0,0),(1,1),(2,0))’);t
isopen(path)boolean是否为开放路径select isopen(path ‘[(0,0),(1,1),(2,0)]’);t
length(object)double precision长度select length(path ‘((-1,0),(1,0))’);4
npoints(path)intpath中的顶点数select npoints(path ‘[(0,0),(1,1),(2,0)]’);3
npoints(polygon)int多边形的顶点数select npoints(polygon ‘((1,1),(0,0))’);2
pclose(path)path将开放path转换为闭合pathselect pclose(path ‘[(0,0),(1,1),(2,0)]’); ((0,0),(1,1),(2,0))
popen(path)path将闭合path转换为开放pathselect popen(path ‘((0,0),(1,1),(2,0))’);[(0,0),(1,1),(2,0)]
radius(circle)double precision圆半径select radius(circle ‘((0,0),2.0)’);2
width(box)double precision矩形的水平长度select width(box ‘((0,0),(1,1))’);1

类型转换函数

函数返回类型描述示例结果
box(circle)box圆形转矩形select box(circle ‘((0,0),2.0)’);(1.41421356237309,1.41421356237309),(-1.41421356237309,-1.41421356237309)
box(point)box点转空矩形select box(point ‘(0,0)’);(0,0),(0,0)
box(point, point)box点转矩形select box(point ‘(0,0)’, point ‘(1,1)’);(1,1),(0,0)
box(polygon)box多边形转矩形select box(polygon ‘((0,0),(1,1),(2,0))’);(2,1),(0,0)
bound_box(box, box)box将两个矩形转换成一个边界矩形select bound_box(box ‘((0,0),(1,1))’, box ‘((3,3),(4,4))’);(4,4),(0,0)
circle(box)circle矩形转圆形select circle(box ‘((0,0),(1,1))’);<(0.5,0.5),0.707106781186548>
circle(point, double precision)circle圆心与半径转圆形select circle(point ‘(0,0)’, 2.0);<(0,0),2>
circle(polygon)circle多边形转圆形select circle(polygon ‘((0,0),(1,1),(2,0))’);<(1,0.333333333333333),0.924950591148529>
line(point, point)line点转直线select line(point ‘(-1,0)’, point ‘(1,0)’);{0,-1,0}
lseg(box)lseg矩形转线段select lseg(box ‘((-1,0),(1,0))’);[(1,0),(-1,0)]
lseg(point, point)lseg点转线段select lseg(point ‘(-1,0)’, point ‘(1,0)’);[(-1,0),(1,0)]
path(polygon)path多边形转pathselect path(polygon ‘((0,0),(1,1),(2,0))’);((0,0),(1,1),(2,0))
point(double precision, double precision)pointselect point(23.4, -44.5);(23.4,-44.5)
point(box)point矩形转点select point(box ‘((-1,0),(1,0))’);(0,0)
point(circle)point圆心select point(circle ‘((0,0),2.0)’);(0,0)
point(lseg)point线段中心select point(lseg ‘((-1,0),(1,0))’);(0,0)
point(polygon)point多边形的中心select point(polygon ‘((0,0),(1,1),(2,0))’);(1,0.333333333333333)
polygon(box)polygon矩形转4点多边形select polygon(box ‘((0,0),(1,1))’);((0,0),(0,1),(1,1),(1,0))
polygon(circle)polygon圆形转12点多边形select polygon(circle ‘((0,0),2.0)’);

((-2,0),(-1.73205080756888,1),(-1,1.73205080756888),(-1.22460635382238e-16,2),(1,1.73205080756888),(1.73205080756888,1),(2,2.4492127
0764475e-16),(1.73205080756888,-0.999999999999999),(1,-1.73205080756888),(3.67381906146713e-16,-2),(-0.999999999999999,-1.73205080756
888),(-1.73205080756888,-1))

polygon(npts, circle)polygon圆形转npts点多边形select polygon(12, circle ‘((0,0),2.0)’);

((-2,0),(-1.73205080756888,1),(-1,1.73205080756888),(-1.22460635382238e-16,2),(1,1.73205080756888),(1.73205080756888,1),(2,2.4492127
0764475e-16),(1.73205080756888,-0.999999999999999),(1,-1.73205080756888),(3.67381906146713e-16,-2),(-0.999999999999999,-1.73205080756
888),(-1.73205080756888,-1))

polygon(path)polygon将path转多边形select polygon(path ‘((0,0),(1,1),(2,0))’);((0,0),(1,1),(2,0))

 

原文链接:

https://www.postgresql.org/docs/9.6/static/functions-geometry.html

 

如果有兴趣学习地图相关的,大家可以去看一下postgis。

 

    原文作者:PostgreSQL
    原文地址: https://www.cnblogs.com/alianbog/p/5657325.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞