PostgreSQL User's Guide
Prev | Chapter 5. Functions | Next

# Geometric Functions

The geometric types point, box, lseg, line, path, polygon, and circle have a large set of native support functions.

Table 5-12. Geometric Functions

Function | Returns | Description | Example
--- | --- | --- | ---
area(object) | float8 | area of item | area(box '((0,0),(1,1))')
box(box,box) | box | intersection box | box(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))')
center(object) | point | center of item | center(box '((0,0),(1,2))')
diameter(circle) | float8 | diameter of circle | diameter(circle '((0,0),2.0)')
height(box) | float8 | vertical size of box | height(box '((0,0),(1,1))')
isclosed(path) | bool | a closed path? | isclosed(path '((0,0),(1,1),(2,0))')
isopen(path) | bool | an open path? | isopen(path '[(0,0),(1,1),(2,0)]')
length(object) | float8 | length of item | length(path '((-1,0),(1,0))')
pclose(path) | path | convert path to closed | popen(path '[(0,0),(1,1),(2,0)]')
npoint(path) | int4 | number of points | npoints(path '[(0,0),(1,1),(2,0)]')
popen(path) | path | convert path to open path | popen(path '((0,0),(1,1),(2,0))')
radius(circle) | float8 | radius of circle | radius(circle '((0,0),2.0)')
width(box) | float8 | horizontal size | width(box '((0,0),(1,1))')

Table 5-13. Geometric Type Conversion Functions

Function | Returns | Description | Example
--- | --- | --- | ---
box(circle) | box | circle to box | box('((0,0),2.0)'::circle)
box(point,point) | box | points to box | box('(0,0)'::point,'(1,1)'::point)
box(polygon) | box | polygon to box | box('((0,0),(1,1),(2,0))'::polygon)
circle(box) | circle | to circle | circle('((0,0),(1,1))'::box)
circle(point,float8) | circle | point to circle | circle('(0,0)'::point,2.0)
lseg(box) | lseg | box diagonal to lseg | lseg('((-1,0),(1,0))'::box)
lseg(point,point) | lseg | points to lseg | lseg('(-1,0)'::point,'(1,0)'::point)
path(polygon) | point | polygon to path | path('((0,0),(1,1),(2,0))'::polygon)
point(circle) | point | center | point('((0,0),2.0)'::circle)
point(lseg,lseg) | point | intersection | point('((-1,0),(1,0))'::lseg, '((-2,-2),(2,2))'::lseg)
point(polygon) | point | center | point('((0,0),(1,1),(2,0))'::polygon)
polygon(box) | polygon | 12 point polygon | polygon('((0,0),(1,1))'::box)
polygon(circle) | polygon | 12-point polygon | polygon('((0,0),2.0)'::circle)
polygon(`npts`,circle) | polygon | `npts` polygon | polygon(12,'((0,0),2.0)'::circle)
polygon(path) | polygon | path to polygon | polygon('((0,0),(1,1),(2,0))'::path)

Table 5-14. Geometric Upgrade Functions

Function | Returns | Description | Example
--- | --- | --- | ---
isoldpath(path) | path | test path for pre-v6.1 form | isoldpath('(1,3,0,0,1,1,2,0)'::path)
revertpoly(polygon) | polygon | to pre-v6.1 | revertpoly('((0,0),(1,1),(2,0))'::polygon)
upgradepath(path) | path | to pre-v6.1 | upgradepath('(1,3,0,0,1,1,2,0)'::path)
upgradepoly(polygon) | polygon | to pre-v6.1 | upgradepoly('(0,1,2,0,1,0)'::polygon)

Prev | Home | Next
Formatting Functions | Up | IP V4 Functions