码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-07-10 12:41:23      阅读:566      评论:0      收藏:0      [点我收藏+]

标签:

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

名字 存储空间 描述 表现形式
point 16字节 平面上的点 (x,y)
line 32字节 直线 {A,B,C}
lseg 32字节 线段 ((x1,y1),(x2,y2))
box 32字节 矩形 ((x1,y1),(x2,y2))
path 16+16n字节 闭合路径 ((x1,y1),...)
path 16+16n字节 开放路径 [(x1,y1),...]
polygon 40+16n字节 多边形 ((x1,y1),...)
circle 24字节 <(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) int path中的顶点数 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转换为闭合path select pclose(path ‘[(0,0),(1,1),(2,0)]‘);  ((0,0),(1,1),(2,0))
popen(path) path 将闭合path转换为开放path select 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(pointpoint) 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(boxbox) 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(pointdouble 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(pointpoint) 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(pointpoint) lseg 点转线段 select lseg(point ‘(-1,0)‘, point ‘(1,0)‘); [(-1,0),(1,0)]
path(polygon) path 多边形转path select path(polygon ‘((0,0),(1,1),(2,0))‘); ((0,0),(1,1),(2,0))
point(double precisiondouble precision) point select 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(nptscircle) 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----几何类型和函数

标签:

原文地址:http://www.cnblogs.com/alianbog/p/5657325.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!