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

FunctionReturnsDescriptionExample
area(object)float8area of itemarea(box '((0,0),(1,1))')
box(box,box)boxintersection boxbox(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))')
center(object)pointcenter of itemcenter(box '((0,0),(1,2))')
diameter(circle)float8diameter of circlediameter(circle '((0,0),2.0)')
height(box)float8vertical size of boxheight(box '((0,0),(1,1))')
isclosed(path)boola closed path?isclosed(path '((0,0),(1,1),(2,0))')
isopen(path)boolan open path?isopen(path '[(0,0),(1,1),(2,0)]')
length(object)float8length of itemlength(path '((-1,0),(1,0))')
pclose(path)pathconvert path to closedpopen(path '[(0,0),(1,1),(2,0)]')
npoint(path)int4number of pointsnpoints(path '[(0,0),(1,1),(2,0)]')
popen(path)pathconvert path to open pathpopen(path '((0,0),(1,1),(2,0))')
radius(circle)float8radius of circleradius(circle '((0,0),2.0)')
width(box)float8horizontal sizewidth(box '((0,0),(1,1))')

Table 5-13. Geometric Type Conversion Functions

FunctionReturnsDescriptionExample
box(circle)boxcircle to boxbox('((0,0),2.0)'::circle)
box(point,point)boxpoints to boxbox('(0,0)'::point,'(1,1)'::point)
box(polygon)boxpolygon to boxbox('((0,0),(1,1),(2,0))'::polygon)
circle(box)circleto circlecircle('((0,0),(1,1))'::box)
circle(point,float8)circlepoint to circlecircle('(0,0)'::point,2.0)
lseg(box)lsegbox diagonal to lseglseg('((-1,0),(1,0))'::box)
lseg(point,point)lsegpoints to lseglseg('(-1,0)'::point,'(1,0)'::point)
path(polygon)pointpolygon to pathpath('((0,0),(1,1),(2,0))'::polygon)
point(circle)pointcenterpoint('((0,0),2.0)'::circle)
point(lseg,lseg)pointintersectionpoint('((-1,0),(1,0))'::lseg, '((-2,-2),(2,2))'::lseg)
point(polygon)pointcenterpoint('((0,0),(1,1),(2,0))'::polygon)
polygon(box)polygon12 point polygonpolygon('((0,0),(1,1))'::box)
polygon(circle)polygon12-point polygonpolygon('((0,0),2.0)'::circle)
polygon(npts,circle)polygonnpts polygonpolygon(12,'((0,0),2.0)'::circle)
polygon(path)polygonpath to polygonpolygon('((0,0),(1,1),(2,0))'::path)

Table 5-14. Geometric Upgrade Functions

FunctionReturnsDescriptionExample
isoldpath(path)pathtest path for pre-v6.1 formisoldpath('(1,3,0,0,1,1,2,0)'::path)
revertpoly(polygon)polygonto pre-v6.1revertpoly('((0,0),(1,1),(2,0))'::polygon)
upgradepath(path)pathto pre-v6.1upgradepath('(1,3,0,0,1,1,2,0)'::path)
upgradepoly(polygon)polygonto pre-v6.1upgradepoly('(0,1,2,0,1,0)'::polygon)