postgresql----几何类型和函数
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(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 | 多边形转path | select path(polygon '((0,0),(1,1),(2,0))'); | ((0,0),(1,1),(2,0)) |
point(double precision, double 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 |
| 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 |
| 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----几何类型和函数的更多相关文章
- PostgreSQL+PostGIS的使用 函数清单
一. PostgreSQL与PostGIS的关系 PostgreSQL 是世界上技术最先进的开源数据库,其前身是1977年一个源于Berkeley名为Ingres的非关系型数据库,其项目领导人为Mic ...
- PostgreSQL的时间/日期函数使用
PostgreSQL的常用时间函数使用整理如下: 一.获取系统时间函数 1.1 获取当前完整时间 select now(); david=# select now(); now ----------- ...
- [转] PostgreSQL的时间/日期函数使用
PS:http://blog.csdn.net/love_rongrong/article/details/6712883 字符串模糊比较 日期类型的模糊查询是不能直接进行的,要先转换成字符串然后再查 ...
- PostgreSQL学习手册(五) 函数和操作符
PostgreSQL学习手册(五) 函数和操作符 一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是Post ...
- [转帖]PostgreSQL的时间/日期函数使用
PostgreSQL的时间/日期函数使用 https://www.cnblogs.com/mchina/archive/2013/04/15/3010418.html 这个博客的 文章目录比上一个好十 ...
- 基类中定义的虚函数在派生类中重新定义时,其函数原型,包括返回类型、函数名、参数个数、参数类型及参数的先后顺序,都必须与基类中的原型完全相同 but------> 可以返回派生类对象的引用或指针
您查询的关键词是:c++primer习题15.25 以下是该网页在北京时间 2016年07月15日 02:57:08 的快照: 如果打开速度慢,可以尝试快速版:如果想更新或删除快照,可以投诉快照. ...
- YUI的类型判断函数
1.首先定义一个关于类型的对象,及相关变量 类型判断对象 ar L = Y.Lang || (Y.Lang = {}), STRING_PROTO = String.prototype, TOSTRI ...
- 函数的类型:函数也是类型 (*)->*
函数的类型:函数也是类型 (*)->* 函数类型作为类型可以定义变量,使得函数变量具有可替代性,这个是高阶函数的编程基础. 使用函数的类型可以定义函数的变量,并用函数给这个变量赋值: 每一个函数 ...
- C++数组类型与函数类型
之所以将C++的数组类型与函数类型拿到一块说,是因为两者在很多地方都一样. 首先,声明形式上类似: 数组类型: type [num] ...
随机推荐
- MVC母版页_Layout.cshtml
记得在asp.net时候,我们常会使用母版页MasterPage.而在MVC也有此功能,应用起来比MasterPage更加便捷. 在本次练习之前,所有MVC的练习均是创建单独的网页.Insus.NET ...
- SQL server Profiler 监视数据库活动
做网站后台开始时需要考虑后台对数据库的一些操作,比如尽量减少查询次数,尽快释放连接,只选取必须的字段等等.如果是用三层开发,复杂的项目中直接拼装SQL语句多一点,拼装的SQL语句可以直接在SQL se ...
- WebForm 【复合控件】
一 复合控件(取值,赋值用法相近) RadioButtonList --单选按钮 (一组列表) <asp:RadioButtonList ID="RadioButtonL ...
- Netty中消除开始的日志消息修改日志级别
我是使用logback作为日志打印,之前使用slf4j,日志打印不出,就干脆换掉了. 1.首先引入依赖 <dependency> <groupId>ch.qos.logback ...
- SqlSession对象之ParameterHandler
上一篇讲了StatementHandler,其中有ParameterHandler(参数处理器)是在StatementHandler被创建时被创建的.下面对ParameterHandler进行说明.其 ...
- 自定义MVC框架之工具类-文件上传类
截止目前已经改造了3个类: ubuntu:通过封装验证码类库一步步安装php的gd扩展 自定义MVC框架之工具类-分页类的封装 该文件上传类功能如下: 1,允许定制上传的文件类型,文件mime信息,文 ...
- linux上,mysql使用聚合函数group by 时报错:SELECT list is not in GROUP BY clause and contains nonaggre的问题
之前在windows上测试是可以正常使用的,但是上传到Linux上后,就报错: Expression # of SELECT list is not in GROUP BY clause and co ...
- 【读书笔记】iOS-网络-负载
负载指的是在服务的请求响应事务中交换的数据.常见的负载格式包括XML,JSON与HTML. 进入与发出的负载数据存在很多形式与大小.比如,有些开发者会使用原生的字符串或是以分隔符分开的数据与Web S ...
- 3.1 - Apps or metadata that mentions the name of any other mobile platform will be rejected
3.1 - Apps or metadata that mentions the name of any other mobile platform will be rejected3.1 Detai ...
- Windows Win7建立wifi热点,手机共享WIFI上网
Win7建立wifi热点,手机共享wifi上网 by:授客 QQ:1033553122 1.以管理员身份运行命令提示符:快捷键win+R→输入cmd→回车 2.启用并设定虚拟WiFi网卡:运行命令:n ...