30th September 2021: PostgreSQL 14 Released!
Unsupported versions: 6.4
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

Geometric Functions

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

Table 10-5. Geometric Functions

Function Returns Description Example
area(box) float8 area of box area('((0,0),(1,1))'::box)
area(circle) float8 area of circle area('((0,0),2.0)'::circle)
box(box,box) box boxes to intersection box box('((0,0),(1,1))','((0.5,0.5),(2,2))')
center(box) point center of object center('((0,0),(1,2))'::box)
center(circle) point center of object center('((0,0),2.0)'::circle)
diameter(circle) float8 diameter of circle diameter('((0,0),2.0)'::circle)
height(box) float8 vertical size of box height('((0,0),(1,1))'::box)
isclosed(path) bool TRUE if this is a closed path isclosed('((0,0),(1,1),(2,0))'::path)
isopen(path) bool TRUE if this is an open path isopen('[(0,0),(1,1),(2,0)]'::path)
length(lseg) float8 length of line segment length('((-1,0),(1,0))'::lseg)
length(path) float8 length of path length('((0,0),(1,1),(2,0))'::path)
pclose(path) path convert path to closed variant popen('[(0,0),(1,1),(2,0)]'::path)
point(lseg,lseg) point convert to point (intersection) point('((-1,0),(1,0))'::lseg,'((-2,-2),(2,2))'::lseg)
points(path) int4 number of points in path points('[(0,0),(1,1),(2,0)]'::path)
popen(path) path convert path to open variant popen('((0,0),(1,1),(2,0))'::path)
radius(circle) float8 radius of circle radius('((0,0),2.0)'::circle)
width(box) float8 horizontal size of box width('((0,0),(1,1))'::box)

Table 10-6. Geometric Type Conversion Functions

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

Table 10-7. 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 convert pre-v6.1 polygon revertpoly('((0,0),(1,1),(2,0))'::polygon)
upgradepath(path) path convert pre-v6.1 path upgradepath('(1,3,0,0,1,1,2,0)'::path)
upgradepoly(polygon) polygon convert pre-v6.1 polygon upgradepoly('(0,1,2,0,1,0)'::polygon)