更新时间:2022-07-29 GMT+08:00
几何函数和操作符
几何操作符
- +
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' + point '(2.0,0)' AS RESULT; result ------------- (3,1),(2,0) (1 row)
- -
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' - point '(2.0,0)' AS RESULT; result --------------- (-1,1),(-2,0) (1 row)
- *
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' * point '(2.0,0)' AS RESULT; result ------------- (2,2),(0,0) (1 row)
- /
示例:
1 2 3 4 5
SELECT box '((0,0),(2,2))' / point '(2.0,0)' AS RESULT; result ------------- (1,1),(0,0) (1 row)
- #
示例:
1 2 3 4 5
SELECT box'((1,-1),(-1,1))' # box'((1,1),(-1,-1))' AS RESULT; result -------- (1,1),(-1,-1) (1 row)
- #
示例:
1 2 3 4 5
SELECT # path'((1,0),(0,1),(-1,0))' AS RESULT; result -------- 3 (1 row)
- @-@
示例:
1 2 3 4 5
SELECT @-@ path '((0,0),(1,0))' AS RESULT; result -------- 2 (1 row)
- @@
示例:
1 2 3 4 5
SELECT @@ circle '((0,0),10)' AS RESULT; result -------- (0,0) (1 row)
- ##
示例:
1 2 3 4 5
SELECT point '(0,0)' ## box '((2,0),(0,2))' AS RESULT; result -------- (0,0) (1 row)
- <->
示例:
1 2 3 4 5
SELECT circle '((0,0),1)' <-> circle '((5,0),1)' AS RESULT; result -------- 3 (1 row)
- &&
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' && box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- <<
示例:
1 2 3 4 5
SELECT circle '((0,0),1)' << circle '((5,0),1)' AS RESULT; result -------- t (1 row)
- >>
示例:
1 2 3 4 5
SELECT circle '((5,0),1)' >> circle '((0,0),1)' AS RESULT; result -------- t (1 row)
- &<
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' &< box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- &>
示例:
1 2 3 4 5
SELECT box '((0,0),(3,3))' &> box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- <<|
示例:
1 2 3 4 5
SELECT box '((0,0),(3,3))' <<| box '((3,4),(5,5))' AS RESULT; result -------- t (1 row)
- |>>
示例:
1 2 3 4 5
SELECT box '((3,4),(5,5))' |>> box '((0,0),(3,3))' AS RESULT; result -------- t (1 row)
- &<|
示例:
1 2 3 4 5
SELECT box '((0,0),(1,1))' &<| box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- |&>
示例:
1 2 3 4 5
SELECT box '((0,0),(3,3))' |&> box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- <^
示例:
1 2 3 4 5
SELECT box '((0,0),(-3,-3))' <^ box '((0,0),(2,2))' AS RESULT; result -------- t (1 row)
- >^
示例:
1 2 3 4 5
SELECT box '((0,0),(2,2))' >^ box '((0,0),(-3,-3))' AS RESULT; result -------- t (1 row)
- ?#
示例:
1 2 3 4 5
SELECT lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))' AS RESULT; result -------- t (1 row)
- ?-
示例:
1 2 3 4 5
SELECT ?- lseg '((-1,0),(1,0))' AS RESULT; result -------- t (1 row)
- ?-
示例:
1 2 3 4 5
SELECT point '(1,0)' ?- point '(0,0)' AS RESULT; result -------- t (1 row)
- ?|
示例:
1 2 3 4 5
SELECT ?| lseg '((-1,0),(1,0))' AS RESULT; result -------- f (1 row)
- ?|
示例:
1 2 3 4 5
SELECT point '(0,1)' ?| point '(0,0)' AS RESULT; result -------- t (1 row)
- ?-|
示例:
1 2 3 4 5
SELECT lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' AS RESULT; result -------- t (1 row)
- ?||
示例:
1 2 3 4 5
SELECT lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' AS RESULT; result -------- t (1 row)
- @>
示例:
1 2 3 4 5
SELECT circle '((0,0),2)' @> point '(1,1)' AS RESULT; result -------- t (1 row)
- <@
示例:
1 2 3 4 5
SELECT point '(1,1)' <@ circle '((0,0),2)' AS RESULT; result -------- t (1 row)
- ~=
示例:
1 2 3 4 5
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
SELECT area(box '((0,0),(1,1))') AS RESULT; result -------- 1 (1 row)
- center(object)
返回类型:point
示例:
1 2 3 4 5
SELECT center(box '((0,0),(1,2))') AS RESULT; result --------- (0.5,1) (1 row)
- diameter(circle)
返回类型:double precision
示例:
1 2 3 4 5
SELECT diameter(circle '((0,0),2.0)') AS RESULT; result -------- 4 (1 row)
- height(box)
返回类型:double precision
示例:
1 2 3 4 5
SELECT height(box '((0,0),(1,1))') AS RESULT; result -------- 1 (1 row)
- isclosed(path)
返回类型:boolean
示例:
1 2 3 4 5
SELECT isclosed(path '((0,0),(1,1),(2,0))') AS RESULT; result -------- t (1 row)
- isopen(path)
返回类型:boolean
示例:
1 2 3 4 5
SELECT isopen(path '[(0,0),(1,1),(2,0)]') AS RESULT; result -------- t (1 row)
- length(object)
返回类型:double precision
示例:
1 2 3 4 5
SELECT length(path '((-1,0),(1,0))') AS RESULT; result -------- 4 (1 row)
- npoints(path)
返回类型:int
示例:
1 2 3 4 5
SELECT npoints(path '[(0,0),(1,1),(2,0)]') AS RESULT; result -------- 3 (1 row)
- npoints(polygon)
返回类型:int
示例:
1 2 3 4 5
SELECT npoints(polygon '((1,1),(0,0))') AS RESULT; result -------- 2 (1 row)
- pclose(path)
返回类型:path
示例:
1 2 3 4 5
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
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
SELECT radius(circle '((0,0),2.0)') AS RESULT; result -------- 2 (1 row)
- width(box)
返回类型:double precision
示例:
1 2 3 4 5
SELECT width(box '((0,0),(1,1))') AS RESULT; result -------- 1 (1 row)
几何类型转换函数
- box(circle)
返回类型:box
示例:
1 2 3 4 5
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
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
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
SELECT circle(box '((0,0),(1,1))') AS RESULT; result ------------------------------- <(0.5,0.5),0.707106781186548> (1 row)
- circle(point, double precision)
返回类型:circle
示例:
1 2 3 4 5
SELECT circle(point '(0,0)', 2.0) AS RESULT; result ----------- <(0,0),2> (1 row)
- circle(polygon)
返回类型:circle
示例:
1 2 3 4 5
SELECT circle(polygon '((0,0),(1,1),(2,0))') AS RESULT; result ------------------------------------------- <(1,0.333333333333333),0.924950591148529> (1 row)
- lseg(box)
返回类型:lseg
示例:
1 2 3 4 5
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
SELECT lseg(point '(-1,0)', point '(1,0)') AS RESULT; result ---------------- [(-1,0),(1,0)] (1 row)
- path(polygon)
返回类型:path
示例:
1 2 3 4 5
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
SELECT point(23.4, -44.5) AS RESULT; result -------------- (23.4,-44.5) (1 row)
- point(box)
返回类型:point
示例:
1 2 3 4 5
SELECT point(box '((-1,0),(1,0))') AS RESULT; result -------- (0,0) (1 row)
- point(circle)
返回类型:point
示例:
1 2 3 4 5
SELECT point(circle '((0,0),2.0)') AS RESULT; result -------- (0,0) (1 row)
- point(lseg)
返回类型:point
示例:
1 2 3 4 5
SELECT point(lseg '((-1,0),(1,0))') AS RESULT; result -------- (0,0) (1 row)
- point(polygon)
返回类型:point
示例:
1 2 3 4 5
SELECT point(polygon '((0,0),(1,1),(2,0))') AS RESULT; result ----------------------- (1,0.333333333333333) (1 row)
- polygon(box)
返回类型:polygon
示例:
1 2 3 4 5
SELECT polygon(box '((0,0),(1,1))') AS RESULT; result --------------------------- ((0,0),(0,1),(1,1),(1,0)) (1 row)
- polygon(circle)
返回类型:polygon
示例:
1 2 3 4 5 6
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)
返回类型:polygon
示例:
1 2 3 4 5 6
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
SELECT polygon(path '((0,0),(1,1),(2,0))') AS RESULT; result --------------------- ((0,0),(1,1),(2,0)) (1 row)
父主题: 函数和操作符