Geometric Operators
PostgreSQL includes a number of operators to assist in comparing geometric data types included with PostgreSQL.
Some of these operators are implicit Boolean returns (for example, << and >>), and others provide new results from the input elements like math operators (for example, + and -).
Listing
|
+
|
Translation (for example, point '(2,0)' + point '(0,1)')
|
|
-
|
Translation (for example, point '(2,0)' - point '(0,1)')
|
|
*
|
Scaling/rotation
|
|
/
|
Scaling/rotation
|
|
#
|
Intersection
|
|
#
|
Number of points in polygon
|
|
##
|
Point of closest proximity
|
|
&&
|
Overlaps
|
|
&<
|
Overlaps to left
|
|
&>
|
Overlaps to right
|
|
<->
|
Distance between
|
|
<<
|
Is left of
|
|
<^
|
Is below
|
|
>>
|
Is right of
|
|
>^
|
Is above
|
|
?#
|
Intersects or overlaps
|
|
?-
|
Is horizontal
|
|
?-|
|
Is perpendicular
|
|
@-@
|
Length or circumference
|
|
?|
|
Is vertical
|
|
?||
|
Is parallel
|
|
@
|
Contained or on
|
|
@@
|
Center of
|
|
~=
|
Same as
|
Notes/Examples
Add a point to a box:
box '((0,0),(1,1))' ** point '(2,0)'
Select all boxes that lay to the left of the given box:
SELECT * FROM map WHERE the box << box '((5,5),(4,4))';
Select the lines parallel to the line segment given:
SELECT * FROM map WHERE the lines ?|| lseg '((1,1),(3,3))';
|