# 9.11. 幾何函式及運算子

The geometric types `point`, `box`, `lseg`, `line`, `path`, `polygon`, and `circle` have a large set of native support functions and operators, shown in [Table 9.36](https://www.postgresql.org/docs/current/functions-geometry.html#FUNCTIONS-GEOMETRY-OP-TABLE), [Table 9.37](https://www.postgresql.org/docs/current/functions-geometry.html#FUNCTIONS-GEOMETRY-FUNC-TABLE), and [Table 9.38](https://www.postgresql.org/docs/current/functions-geometry.html#FUNCTIONS-GEOMETRY-CONV-TABLE).

#### **Table 9.36. Geometric Operators**

| <p>Operator</p><p>Description</p><p>Example(s)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | - | -------------------------------------------------- |
| <p><em><code>geometric\_type</code></em> <code>+</code> <code>point</code> → <em><code>geometric\_type</code></em></p><p>Adds the coordinates of the second <code>point</code> to those of each point of the first argument, thus performing translation. Available for <code>point</code>, <code>box</code>, <code>path</code>, <code>circle</code>.</p><p><code>box '(1,1),(0,0)' + point '(2,0)'</code> → <code>(3,1),(2,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>path</code> <code>+</code> <code>path</code> → <code>path</code></p><p>Concatenates two open paths (returns NULL if either path is closed).</p><p><code>path '\[(0,0),(1,1)]' + path '\[(2,2),(3,3),(4,4)]'</code> → <code>\[(0,0),(1,1),(2,2),(3,3),(4,4)]</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>-</code> <code>point</code> → <em><code>geometric\_type</code></em></p><p>Subtracts the coordinates of the second <code>point</code> from those of each point of the first argument, thus performing translation. Available for <code>point</code>, <code>box</code>, <code>path</code>, <code>circle</code>.</p><p><code>box '(1,1),(0,0)' - point '(2,0)'</code> → <code>(-1,1),(-2,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>\*</code> <code>point</code> → <em><code>geometric\_type</code></em></p><p>Multiplies each point of the first argument by the second <code>point</code> (treating a point as being a complex number represented by real and imaginary parts, and performing standard complex multiplication). If one interprets the second <code>point</code> as a vector, this is equivalent to scaling the object's size and distance from the origin by the length of the vector, and rotating it counterclockwise around the origin by the vector's angle from the <em><code>x</code></em> axis. Available for <code>point</code>, <code>box</code>,<a href="https://www.postgresql.org/docs/current/functions-geometry.html#ftn.FUNCTIONS-GEOMETRY-ROTATION-FN"><sup>\[a]</sup></a> <code>path</code>, <code>circle</code>.</p><p><code>path '((0,0),(1,0),(1,1))' \* point '(3.0,0)'</code> → <code>((0,0),(3,0),(3,3))</code></p><p><code>path '((0,0),(1,0),(1,1))' \* point(cosd(45), sind(45))</code> → <code>((0,0),​(0.7071067811865475,0.7071067811865475),​(0,1.414213562373095))</code></p> |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>/</code> <code>point</code> → <em><code>geometric\_type</code></em></p><p>Divides each point of the first argument by the second <code>point</code> (treating a point as being a complex number represented by real and imaginary parts, and performing standard complex division). If one interprets the second <code>point</code> as a vector, this is equivalent to scaling the object's size and distance from the origin down by the length of the vector, and rotating it clockwise around the origin by the vector's angle from the <em><code>x</code></em> axis. Available for <code>point</code>, <code>box</code>,<a href="https://www.postgresql.org/docs/current/functions-geometry.html#ftn.FUNCTIONS-GEOMETRY-ROTATION-FN"><sup>\[a]</sup></a> <code>path</code>, <code>circle</code>.</p><p><code>path '((0,0),(1,0),(1,1))' / point '(2.0,0)'</code> → <code>((0,0),(0.5,0),(0.5,0.5))</code></p><p><code>path '((0,0),(1,0),(1,1))' / point(cosd(45), sind(45))</code> → <code>((0,0),​(0.7071067811865476,-0.7071067811865476),​(1.4142135623730951,0))</code></p>       |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>@-@</code> <em><code>geometric\_type</code></em> → <code>double precision</code></p><p>Computes the total length. Available for <code>lseg</code>, <code>path</code>.</p><p><code>@-@ path '\[(0,0),(1,0),(1,1)]'</code> → <code>2</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>@@</code> <em><code>geometric\_type</code></em> → <code>point</code></p><p>Computes the center point. Available for <code>box</code>, <code>lseg</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>@@ box '(2,2),(0,0)'</code> → <code>(1,1)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>#</code> <em><code>geometric\_type</code></em> → <code>integer</code></p><p>Returns the number of points. Available for <code>path</code>, <code>polygon</code>.</p><p><code># path '((1,0),(0,1),(-1,0))'</code> → <code>3</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>#</code> <em><code>geometric\_type</code></em> → <code>point</code></p><p>Computes the point of intersection, or NULL if there is none. Available for <code>lseg</code>, <code>line</code>.</p><p><code>lseg '\[(0,0),(1,1)]' # lseg '\[(1,0),(0,1)]'</code> → <code>(0.5,0.5)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>box</code> <code>#</code> <code>box</code> → <code>box</code></p><p>Computes the intersection of two boxes, or NULL if there is none.</p><p><code>box '(2,2),(-1,-1)' # box '(1,1),(-2,-2)'</code> → <code>(1,1),(-1,-1)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>##</code> <em><code>geometric\_type</code></em> → <code>point</code></p><p>Computes the closest point to the first object on the second object. Available for these pairs of types: (<code>point</code>, <code>box</code>), (<code>point</code>, <code>lseg</code>), (<code>point</code>, <code>line</code>), (<code>lseg</code>, <code>box</code>), (<code>lseg</code>, <code>lseg</code>), (<code>line</code>, <code>lseg</code>).</p><p><code>point '(0,0)' ## lseg '\[(2,0),(0,2)]'</code> → <code>(1,1)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code><-></code> <em><code>geometric\_type</code></em> → <code>double precision</code></p><p>Computes the distance between the objects. Available for all seven geometric types, for all combinations of <code>point</code> with another geometric type, and for these additional pairs of types: (<code>box</code>, <code>lseg</code>), (<code>lseg</code>, <code>line</code>), (<code>polygon</code>, <code>circle</code>) (and the commutator cases).</p><p><code>circle '<(0,0),1>' <-> circle '<(5,0),1>'</code> → <code>3</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>@></code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Does first object contain second? Available for these pairs of types: (<code>box</code>, <code>point</code>), (<code>box</code>, <code>box</code>), (<code>path</code>, <code>point</code>), (<code>polygon</code>, <code>point</code>), (<code>polygon</code>, <code>polygon</code>), (<code>circle</code>, <code>point</code>), (<code>circle</code>, <code>circle</code>).</p><p><code>circle '<(0,0),2>' @> point '(1,1)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code><@</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Is first object contained in or on second? Available for these pairs of types: (<code>point</code>, <code>box</code>), (<code>point</code>, <code>lseg</code>), (<code>point</code>, <code>line</code>), (<code>point</code>, <code>path</code>), (<code>point</code>, <code>polygon</code>), (<code>point</code>, <code>circle</code>), (<code>box</code>, <code>box</code>), (<code>lseg</code>, <code>box</code>), (<code>lseg</code>, <code>line</code>), (<code>polygon</code>, <code>polygon</code>), (<code>circle</code>, <code>circle</code>).</p><p><code>point '(1,1)' <@ circle '<(0,0),2>'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>&&</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Do these objects overlap? (One point in common makes this true.) Available for <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(1,1),(0,0)' && box '(2,2),(0,0)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code><<</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Is first object strictly left of second? Available for <code>point</code>, <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>circle '<(0,0),1>' << circle '<(5,0),1>'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>>></code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Is first object strictly right of second? Available for <code>point</code>, <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>circle '<(5,0),1>' >> circle '<(0,0),1>'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>&<</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Does first object not extend to the right of second? Available for <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(1,1),(0,0)' &< box '(2,2),(0,0)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>&></code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Does first object not extend to the left of second? Available for <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(3,3),(0,0)' &> box '(2,2),(0,0)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code><<                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | </code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Is first object strictly below second? Available for <code>point</code>, <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(3,3),(0,0)' << | box '(5,5),(3,4)'</code> → <code>t</code></p>                                                                        |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | >></code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Is first object strictly above second? Available for <code>point</code>, <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(5,5),(3,4)'  | >> box '(3,3),(0,0)'</code> → <code>t</code></p>                                                                     |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>&<                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | </code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Does first object not extend above second? Available for <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(1,1),(0,0)' &<                 | box '(2,2),(0,0)'</code> → <code>t</code></p>                                                                        |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | &></code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Does first object not extend below second? Available for <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>box '(3,3),(0,0)'                  | &> box '(2,2),(0,0)'</code> → <code>t</code></p>                                                                     |                                                    |                                                                                                                 |   |                                                    |
| <p><code>box</code> <code><^</code> <code>box</code> → <code>boolean</code></p><p>Is first object below second (allows edges to touch)?</p><p><code>box '((1,1),(0,0))' <^ box '((2,2),(1,1))'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>box</code> <code>>^</code> <code>box</code> → <code>boolean</code></p><p>Is first object above second (allows edges to touch)?</p><p><code>box '((2,2),(1,1))' >^ box '((1,1),(0,0))'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><em><code>geometric\_type</code></em> <code>?#</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Do these objects intersect? Available for these pairs of types: (<code>box</code>, <code>box</code>), (<code>lseg</code>, <code>box</code>), (<code>lseg</code>, <code>lseg</code>), (<code>lseg</code>, <code>line</code>), (<code>line</code>, <code>box</code>), (<code>line</code>, <code>line</code>), (<code>path</code>, <code>path</code>).</p><p><code>lseg '\[(-1,0),(1,0)]' ?# box '(2,2),(-2,-2)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>?-</code> <code>line</code> → <code>boolean</code></p><p><code>?-</code> <code>lseg</code> → <code>boolean</code></p><p>Is line horizontal?</p><p><code>?- lseg '\[(-1,0),(1,0)]'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>point</code> <code>?-</code> <code>point</code> → <code>boolean</code></p><p>Are points horizontally aligned (that is, have same y coordinate)?</p><p><code>point '(1,0)' ?- point '(0,0)'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| <p><code>?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | </code> <code>line</code> → <code>boolean</code></p><p><code>?                                                                                                                                                                                    | </code> <code>lseg</code> → <code>boolean</code></p><p>Is line vertical?</p><p><code>?                               | lseg '\[(-1,0),(1,0)]'</code> → <code>f</code></p> |                                                                                                                 |   |                                                    |
| <p><code>point</code> <code>?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | </code> <code>point</code> → <code>boolean</code></p><p>Are points vertically aligned (that is, have same x coordinate)?</p><p><code>point '(0,1)' ?                                                                                              | point '(0,0)'</code> → <code>t</code></p>                                                                            |                                                    |                                                                                                                 |   |                                                    |
| <p><code>line</code> <code>?-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | </code> <code>line</code> → <code>boolean</code></p><p><code>lseg</code> <code>?-                                                                                                                                                                 | </code> <code>lseg</code> → <code>boolean</code></p><p>Are lines perpendicular?</p><p><code>lseg '\[(0,0),(0,1)]' ?- | lseg '\[(0,0),(1,0)]'</code> → <code>t</code></p>  |                                                                                                                 |   |                                                    |
| <p><code>line</code> <code>?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |                                                                                                                                                                                                                                                   | </code> <code>line</code> → <code>boolean</code></p><p><code>lseg</code> <code>?                                     |                                                    | </code> <code>lseg</code> → <code>boolean</code></p><p>Are lines parallel?</p><p><code>lseg '\[(-1,0),(1,0)]' ? |   | lseg '\[(-1,2),(1,2)]'</code> → <code>t</code></p> |
| <p><em><code>geometric\_type</code></em> <code>\~=</code> <em><code>geometric\_type</code></em> → <code>boolean</code></p><p>Are these objects the same? Available for <code>point</code>, <code>box</code>, <code>polygon</code>, <code>circle</code>.</p><p><code>polygon '((0,0),(1,1))' \~= polygon '((1,1),(0,0))'</code> → <code>t</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |
| [<sup>\[a\]</sup>](https://www.postgresql.org/docs/current/functions-geometry.html#FUNCTIONS-GEOMETRY-ROTATION-FN) “Rotating” a box with these operators only moves its corner points: the box is still considered to have sides parallel to the axes. Hence the box's size is not preserved, as a true rotation would do.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                   |                                                                                                                      |                                                    |                                                                                                                 |   |                                                    |

#### Caution

Note that the “same as” operator, `~=`, represents the usual notion of equality for the `point`, `box`, `polygon`, and `circle` types. Some of the geometric types also have an `=` operator, but `=` compares for equal *areas* only. The other scalar comparison operators (`<=` and so on), where available for these types, likewise compare areas.

#### Note

Before PostgreSQL 14, the point is strictly below/above comparison operators `point` `<<|` `point` and `point` `|>>` `point` were respectively called `<^` and `>^`. These names are still available, but are deprecated and will eventually be removed.

#### **Table 9.37. Geometric Functions**

| <p>Function</p><p>Description</p><p>Example(s)</p>                                                                                                                                                                                                                                                                                                                                                               |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>area</code> ( <em><code>geometric\_type</code></em> ) → <code>double precision</code></p><p>Computes area. Available for <code>box</code>, <code>path</code>, <code>circle</code>. A <code>path</code> input must be closed, else NULL is returned. Also, if the <code>path</code> is self-intersecting, the result may be meaningless.</p><p><code>area(box '(2,2),(0,0)')</code> → <code>4</code></p> |
| <p><code>center</code> ( <em><code>geometric\_type</code></em> ) → <code>point</code></p><p>Computes center point. Available for <code>box</code>, <code>circle</code>.</p><p><code>center(box '(1,2),(0,0)')</code> → <code>(0.5,1)</code></p>                                                                                                                                                                  |
| <p><code>diagonal</code> ( <code>box</code> ) → <code>lseg</code></p><p>Extracts box's diagonal as a line segment (same as <code>lseg(box)</code>).</p><p><code>diagonal(box '(1,2),(0,0)')</code> → <code>\[(1,2),(0,0)]</code></p>                                                                                                                                                                             |
| <p><code>diameter</code> ( <code>circle</code> ) → <code>double precision</code></p><p>Computes diameter of circle.</p><p><code>diameter(circle '<(0,0),2>')</code> → <code>4</code></p>                                                                                                                                                                                                                         |
| <p><code>height</code> ( <code>box</code> ) → <code>double precision</code></p><p>Computes vertical size of box.</p><p><code>height(box '(1,2),(0,0)')</code> → <code>2</code></p>                                                                                                                                                                                                                               |
| <p><code>isclosed</code> ( <code>path</code> ) → <code>boolean</code></p><p>Is path closed?</p><p><code>isclosed(path '((0,0),(1,1),(2,0))')</code> → <code>t</code></p>                                                                                                                                                                                                                                         |
| <p><code>isopen</code> ( <code>path</code> ) → <code>boolean</code></p><p>Is path open?</p><p><code>isopen(path '\[(0,0),(1,1),(2,0)]')</code> → <code>t</code></p>                                                                                                                                                                                                                                              |
| <p><code>length</code> ( <em><code>geometric\_type</code></em> ) → <code>double precision</code></p><p>Computes the total length. Available for <code>lseg</code>, <code>path</code>.</p><p><code>length(path '((-1,0),(1,0))')</code> → <code>4</code></p>                                                                                                                                                      |
| <p><code>npoints</code> ( <em><code>geometric\_type</code></em> ) → <code>integer</code></p><p>Returns the number of points. Available for <code>path</code>, <code>polygon</code>.</p><p><code>npoints(path '\[(0,0),(1,1),(2,0)]')</code> → <code>3</code></p>                                                                                                                                                 |
| <p><code>pclose</code> ( <code>path</code> ) → <code>path</code></p><p>Converts path to closed form.</p><p><code>pclose(path '\[(0,0),(1,1),(2,0)]')</code> → <code>((0,0),(1,1),(2,0))</code></p>                                                                                                                                                                                                               |
| <p><code>popen</code> ( <code>path</code> ) → <code>path</code></p><p>Converts path to open form.</p><p><code>popen(path '((0,0),(1,1),(2,0))')</code> → <code>\[(0,0),(1,1),(2,0)]</code></p>                                                                                                                                                                                                                   |
| <p><code>radius</code> ( <code>circle</code> ) → <code>double precision</code></p><p>Computes radius of circle.</p><p><code>radius(circle '<(0,0),2>')</code> → <code>2</code></p>                                                                                                                                                                                                                               |
| <p><code>slope</code> ( <code>point</code>, <code>point</code> ) → <code>double precision</code></p><p>Computes slope of a line drawn through the two points.</p><p><code>slope(point '(0,0)', point '(2,1)')</code> → <code>0.5</code></p>                                                                                                                                                                      |
| <p><code>width</code> ( <code>box</code> ) → <code>double precision</code></p><p>Computes horizontal size of box.</p><p><code>width(box '(1,2),(0,0)')</code> → <code>1</code></p>                                                                                                                                                                                                                               |

#### **Table 9.38. Geometric Type Conversion Functions**

| <p>Function</p><p>Description</p><p>Example(s)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>box</code> ( <code>circle</code> ) → <code>box</code></p><p>Computes box inscribed within the circle.</p><p><code>box(circle '<(0,0),2>')</code> → <code>(1.414213562373095,1.414213562373095),​(-1.414213562373095,-1.414213562373095)</code></p>                                                                                                                                                                                                                                                                                                                                                                       |
| <p><code>box</code> ( <code>point</code> ) → <code>box</code></p><p>Converts point to empty box.</p><p><code>box(point '(1,0)')</code> → <code>(1,0),(1,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>box</code> ( <code>point</code>, <code>point</code> ) → <code>box</code></p><p>Converts any two corner points to box.</p><p><code>box(point '(0,1)', point '(1,0)')</code> → <code>(1,1),(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>box</code> ( <code>polygon</code> ) → <code>box</code></p><p>Computes bounding box of polygon.</p><p><code>box(polygon '((0,0),(1,1),(2,0))')</code> → <code>(2,1),(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| <p><code>bound\_box</code> ( <code>box</code>, <code>box</code> ) → <code>box</code></p><p>Computes bounding box of two boxes.</p><p><code>bound\_box(box '(1,1),(0,0)', box '(4,4),(3,3)')</code> → <code>(4,4),(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><code>circle</code> ( <code>box</code> ) → <code>circle</code></p><p>Computes smallest circle enclosing box.</p><p><code>circle(box '(1,1),(0,0)')</code> → <code><(0.5,0.5),0.7071067811865476></code></p>                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>circle</code> ( <code>point</code>, <code>double precision</code> ) → <code>circle</code></p><p>Constructs circle from center and radius.</p><p><code>circle(point '(0,0)', 2.0)</code> → <code><(0,0),2></code></p>                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>circle</code> ( <code>polygon</code> ) → <code>circle</code></p><p>Converts polygon to circle. The circle's center is the mean of the positions of the polygon's points, and the radius is the average distance of the polygon's points from that center.</p><p><code>circle(polygon '((0,0),(1,3),(2,0))')</code> → <code><(1,1),1.6094757082487299></code></p>                                                                                                                                                                                                                                                         |
| <p><code>line</code> ( <code>point</code>, <code>point</code> ) → <code>line</code></p><p>Converts two points to the line through them.</p><p><code>line(point '(-1,0)', point '(1,0)')</code> → <code>{0,-1,0}</code></p>                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>lseg</code> ( <code>box</code> ) → <code>lseg</code></p><p>Extracts box's diagonal as a line segment.</p><p><code>lseg(box '(1,0),(-1,0)')</code> → <code>\[(1,0),(-1,0)]</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>lseg</code> ( <code>point</code>, <code>point</code> ) → <code>lseg</code></p><p>Constructs line segment from two endpoints.</p><p><code>lseg(point '(-1,0)', point '(1,0)')</code> → <code>\[(-1,0),(1,0)]</code></p>                                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><code>path</code> ( <code>polygon</code> ) → <code>path</code></p><p>Converts polygon to a closed path with the same list of points.</p><p><code>path(polygon '((0,0),(1,1),(2,0))')</code> → <code>((0,0),(1,1),(2,0))</code></p>                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>point</code> ( <code>double precision</code>, <code>double precision</code> ) → <code>point</code></p><p>Constructs point from its coordinates.</p><p><code>point(23.4, -44.5)</code> → <code>(23.4,-44.5)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>point</code> ( <code>box</code> ) → <code>point</code></p><p>Computes center of box.</p><p><code>point(box '(1,0),(-1,0)')</code> → <code>(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>point</code> ( <code>circle</code> ) → <code>point</code></p><p>Computes center of circle.</p><p><code>point(circle '<(0,0),2>')</code> → <code>(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| <p><code>point</code> ( <code>lseg</code> ) → <code>point</code></p><p>Computes center of line segment.</p><p><code>point(lseg '\[(-1,0),(1,0)]')</code> → <code>(0,0)</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><code>point</code> ( <code>polygon</code> ) → <code>point</code></p><p>Computes center of polygon (the mean of the positions of the polygon's points).</p><p><code>point(polygon '((0,0),(1,1),(2,0))')</code> → <code>(1,0.3333333333333333)</code></p>                                                                                                                                                                                                                                                                                                                                                                       |
| <p><code>polygon</code> ( <code>box</code> ) → <code>polygon</code></p><p>Converts box to a 4-point polygon.</p><p><code>polygon(box '(1,1),(0,0)')</code> → <code>((0,0),(0,1),(1,1),(1,0))</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>polygon</code> ( <code>circle</code> ) → <code>polygon</code></p><p>Converts circle to a 12-point polygon.</p><p><code>polygon(circle '<(0,0),2>')</code> → <code>((-2,0),​(-1.7320508075688774,0.9999999999999999),​(-1.0000000000000002,1.7320508075688772),​(-1.2246063538223773e-16,2),​(0.9999999999999996,1.7320508075688774),​(1.732050807568877,1.0000000000000007),​(2,2.4492127076447545e-16),​(1.7320508075688776,-0.9999999999999994),​(1.0000000000000009,-1.7320508075688767),​(3.673819061467132e-16,-2),​(-0.9999999999999987,-1.732050807568878),​(-1.7320508075688767,-1.0000000000000009))</code></p> |
| <p><code>polygon</code> ( <code>integer</code>, <code>circle</code> ) → <code>polygon</code></p><p>Converts circle to an <em><code>n</code></em>-point polygon.</p><p><code>polygon(4, circle '<(3,0),1>')</code> → <code>((2,0),​(3,1),​(4,1.2246063538223773e-16),​(3,-1))</code></p>                                                                                                                                                                                                                                                                                                                                           |
| <p><code>polygon</code> ( <code>path</code> ) → <code>polygon</code></p><p>Converts closed path to a polygon with the same list of points.</p><p><code>polygon(path '((0,0),(1,1),(2,0))')</code> → <code>((0,0),(1,1),(2,0))</code></p>                                                                                                                                                                                                                                                                                                                                                                                          |

It is possible to access the two component numbers of a `point` as though the point were an array with indexes 0 and 1. For example, if `t.p` is a `point` column then `SELECT p[0] FROM t` retrieves the X coordinate and `UPDATE t SET p[1] = ...` changes the Y coordinate. In the same way, a value of type `box` or `lseg` can be treated as an array of two `point` values.
