Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
9.11. Geometric Functions and Operators
Prev UpChapter 9. Functions and OperatorsHome Next

9.11. Geometric Functions and Operators

The geometric typespoint,box,lseg,line,path,polygon, andcircle have a large set of native support functions and operators, shown inTable 9.31,Table 9.32, andTable 9.33.

Caution

Note that thesame as operator,~=, represents the usual notion of equality for thepoint,box,polygon, andcircle types. Some of these types also have an= operator, but= compares for equalareas only. The other scalar comparison operators (<= and so on) likewise compare areas for these types.

Table 9.31. Geometric Operators

OperatorDescriptionExample
+Translationbox '((0,0),(1,1))' + point '(2.0,0)'
-Translationbox '((0,0),(1,1))' - point '(2.0,0)'
*Scaling/rotationbox '((0,0),(1,1))' * point '(2.0,0)'
/Scaling/rotationbox '((0,0),(2,2))' / point '(2.0,0)'
#Point or box of intersectionbox '((1,-1),(-1,1))' # box '((1,1),(-2,-2))'
#Number of points in path or polygon# path '((1,0),(0,1),(-1,0))'
@-@Length or circumference@-@ path '((0,0),(1,0))'
@@Center@@ circle '((0,0),10)'
##Closest point to first operand on second operandpoint '(0,0)' ## lseg '((2,0),(0,2))'
<->Distance betweencircle '((0,0),1)' <-> circle '((5,0),1)'
&&Overlaps? (One point in common makes this true.)box '((0,0),(1,1))' && box '((0,0),(2,2))'
<<Is strictly left of?circle '((0,0),1)' << circle '((5,0),1)'
>>Is strictly right of?circle '((5,0),1)' >> circle '((0,0),1)'
&<Does not extend to the right of?box '((0,0),(1,1))' &< box '((0,0),(2,2))'
&>Does not extend to the left of?box '((0,0),(3,3))' &> box '((0,0),(2,2))'
<<|Is strictly below?box '((0,0),(3,3))' <<| box '((3,4),(5,5))'
|>>Is strictly above?box '((3,4),(5,5))' |>> box '((0,0),(3,3))'
&<|Does not extend above?box '((0,0),(1,1))' &<| box '((0,0),(2,2))'
|&>Does not extend below?box '((0,0),(3,3))' |&> box '((0,0),(2,2))'
<^Is below (allows touching)?circle '((0,0),1)' <^ circle '((0,5),1)'
>^Is above (allows touching)?circle '((0,5),1)' >^ circle '((0,0),1)'
?#Intersects?lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))'
?-Is horizontal??- lseg '((-1,0),(1,0))'
?-Are horizontally aligned?point '(1,0)' ?- point '(0,0)'
?|Is vertical??| lseg '((-1,0),(1,0))'
?|Are vertically aligned?point '(0,1)' ?| point '(0,0)'
?-|Is perpendicular?lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))'
?||Are parallel?lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))'
@>Contains?circle '((0,0),2)' @> point '(1,1)'
<@Contained in or on?point '(1,1)' <@ circle '((0,0),2)'
~=Same as?polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'

Note

BeforePostgreSQL 8.2, the containment operators@> and<@ were respectively called~ and@. These names are still available, but are deprecated and will eventually be removed.

Table 9.32. Geometric Functions

FunctionReturn TypeDescriptionExample
area(object)double precisionareaarea(box '((0,0),(1,1))')
center(object)pointcentercenter(box '((0,0),(1,2))')
diameter(circle)double precisiondiameter of circlediameter(circle '((0,0),2.0)')
height(box)double precisionvertical size of boxheight(box '((0,0),(1,1))')
isclosed(path)booleana closed path?isclosed(path '((0,0),(1,1),(2,0))')
isopen(path)booleanan open path?isopen(path '[(0,0),(1,1),(2,0)]')
length(object)double precisionlengthlength(path '((-1,0),(1,0))')
npoints(path)intnumber of pointsnpoints(path '[(0,0),(1,1),(2,0)]')
npoints(polygon)intnumber of pointsnpoints(polygon '((1,1),(0,0))')
pclose(path)pathconvert path to closedpclose(path '[(0,0),(1,1),(2,0)]')
popen(path)pathconvert path to openpopen(path '((0,0),(1,1),(2,0))')
radius(circle)double precisionradius of circleradius(circle '((0,0),2.0)')
width(box)double precisionhorizontal size of boxwidth(box '((0,0),(1,1))')

Table 9.33. Geometric Type Conversion Functions

FunctionReturn TypeDescriptionExample
box(circle)boxcircle to boxbox(circle '((0,0),2.0)')
box(point)boxpoint to empty boxbox(point '(0,0)')
box(point,point)boxpoints to boxbox(point '(0,0)', point '(1,1)')
box(polygon)boxpolygon to boxbox(polygon '((0,0),(1,1),(2,0))')
bound_box(box,box)boxboxes to bounding boxbound_box(box '((0,0),(1,1))', box '((3,3),(4,4))')
circle(box)circlebox to circlecircle(box '((0,0),(1,1))')
circle(point,double precision)circlecenter and radius to circlecircle(point '(0,0)', 2.0)
circle(polygon)circlepolygon to circlecircle(polygon '((0,0),(1,1),(2,0))')
line(point,point)linepoints to lineline(point '(-1,0)', point '(1,0)')
lseg(box)lsegbox diagonal to line segmentlseg(box '((-1,0),(1,0))')
lseg(point,point)lsegpoints to line segmentlseg(point '(-1,0)', point '(1,0)')
path(polygon)pathpolygon to pathpath(polygon '((0,0),(1,1),(2,0))')
point(double precision,double precision)pointconstruct pointpoint(23.4, -44.5)
point(box)pointcenter of boxpoint(box '((-1,0),(1,0))')
point(circle)pointcenter of circlepoint(circle '((0,0),2.0)')
point(lseg)pointcenter of line segmentpoint(lseg '((-1,0),(1,0))')
point(polygon)pointcenter of polygonpoint(polygon '((0,0),(1,1),(2,0))')
polygon(box)polygonbox to 4-point polygonpolygon(box '((0,0),(1,1))')
polygon(circle)polygoncircle to 12-point polygonpolygon(circle '((0,0),2.0)')
polygon(npts,circle)polygoncircle tonpts-point polygonpolygon(12, circle '((0,0),2.0)')
polygon(path)polygonpath to polygonpolygon(path '((0,0),(1,1),(2,0))')

It is possible to access the two component numbers of apoint as though the point were an array with indexes 0 and 1. For example, ift.p is apoint column thenSELECT p[0] FROM t retrieves the X coordinate andUPDATE t SET p[1] = ... changes the Y coordinate. In the same way, a value of typebox orlseg can be treated as an array of twopoint values.

Thearea function works for the typesbox,circle, andpath. Thearea function only works on thepath data type if the points in thepath are non-intersecting. For example, thepath'((0,0),(0,1),(2,1),(2,2),(1,2),(1,0),(0,0))'::PATH will not work; however, the following visually identicalpath'((0,0),(0,1),(1,1),(1,2),(2,2),(2,1),(1,1),(1,0),(0,0))'::PATH will work. If the concept of an intersecting versus non-intersectingpath is confusing, draw both of the abovepaths side by side on a piece of graph paper.


Prev Up Next
9.10. Enum Support Functions Home 9.12. Network Address Functions and Operators
epubpdf
Go to PostgreSQL 9.5
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp