diff options
Diffstat (limited to '')
-rw-r--r-- | doc/src/sgml/html/functions-geometry.html | 887 |
1 files changed, 887 insertions, 0 deletions
diff --git a/doc/src/sgml/html/functions-geometry.html b/doc/src/sgml/html/functions-geometry.html new file mode 100644 index 0000000..d80dfee --- /dev/null +++ b/doc/src/sgml/html/functions-geometry.html @@ -0,0 +1,887 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.11. Geometric Functions and Operators</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="functions-enum.html" title="9.10. Enum Support Functions" /><link rel="next" href="functions-net.html" title="9.12. Network Address Functions and Operators" /></head><body id="docContent" class="container-fluid col-10"><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.11. Geometric Functions and Operators</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-enum.html" title="9.10. Enum Support Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 14.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-net.html" title="9.12. Network Address Functions and Operators">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-GEOMETRY"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.11. Geometric Functions and Operators</h2></div></div></div><p> + The geometric types <code class="type">point</code>, <code class="type">box</code>, + <code class="type">lseg</code>, <code class="type">line</code>, <code class="type">path</code>, + <code class="type">polygon</code>, and <code class="type">circle</code> have a large set of + native support functions and operators, shown in <a class="xref" href="functions-geometry.html#FUNCTIONS-GEOMETRY-OP-TABLE" title="Table 9.35. Geometric Operators">Table 9.35</a>, <a class="xref" href="functions-geometry.html#FUNCTIONS-GEOMETRY-FUNC-TABLE" title="Table 9.36. Geometric Functions">Table 9.36</a>, and <a class="xref" href="functions-geometry.html#FUNCTIONS-GEOMETRY-CONV-TABLE" title="Table 9.37. Geometric Type Conversion Functions">Table 9.37</a>. + </p><div class="table" id="FUNCTIONS-GEOMETRY-OP-TABLE"><p class="title"><strong>Table 9.35. Geometric Operators</strong></p><div class="table-contents"><table class="table" summary="Geometric Operators" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature"> + Operator + </p> + <p> + Description + </p> + <p> + Example(s) + </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">+</code> <code class="type">point</code> + → <code class="returnvalue"><em class="replaceable"><code>geometric_type</code></em></code> + </p> + <p> + Adds the coordinates of the second <code class="type">point</code> to those of each + point of the first argument, thus performing translation. + Available for <code class="type">point</code>, <code class="type">box</code>, <code class="type">path</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(1,1),(0,0)' + point '(2,0)'</code> + → <code class="returnvalue">(3,1),(2,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">path</code> <code class="literal">+</code> <code class="type">path</code> + → <code class="returnvalue">path</code> + </p> + <p> + Concatenates two open paths (returns NULL if either path is closed). + </p> + <p> + <code class="literal">path '[(0,0),(1,1)]' + path '[(2,2),(3,3),(4,4)]'</code> + → <code class="returnvalue">[(0,0),(1,1),(2,2),(3,3),(4,4)]</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">-</code> <code class="type">point</code> + → <code class="returnvalue"><em class="replaceable"><code>geometric_type</code></em></code> + </p> + <p> + Subtracts the coordinates of the second <code class="type">point</code> from those + of each point of the first argument, thus performing translation. + Available for <code class="type">point</code>, <code class="type">box</code>, <code class="type">path</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(1,1),(0,0)' - point '(2,0)'</code> + → <code class="returnvalue">(-1,1),(-2,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">*</code> <code class="type">point</code> + → <code class="returnvalue"><em class="replaceable"><code>geometric_type</code></em></code> + </p> + <p> + Multiplies each point of the first argument by the second + <code class="type">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 class="type">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 class="replaceable"><code>x</code></em> axis. + Available for <code class="type">point</code>, <code class="type">box</code>,<a href="#ftn.FUNCTIONS-GEOMETRY-ROTATION-FN" class="footnote"><sup class="footnote" id="FUNCTIONS-GEOMETRY-ROTATION-FN">[a]</sup></a> + <code class="type">path</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">path '((0,0),(1,0),(1,1))' * point '(3.0,0)'</code> + → <code class="returnvalue">((0,0),(3,0),(3,3))</code> + </p> + <p> + <code class="literal">path '((0,0),(1,0),(1,1))' * point(cosd(45), sind(45))</code> + → <code class="returnvalue">((0,0),(0.7071067811865475,0.7071067811865475),(0,1.414213562373095))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">/</code> <code class="type">point</code> + → <code class="returnvalue"><em class="replaceable"><code>geometric_type</code></em></code> + </p> + <p> + Divides each point of the first argument by the second + <code class="type">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 class="type">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 class="replaceable"><code>x</code></em> axis. + Available for <code class="type">point</code>, <code class="type">box</code>,<a href="functions-geometry.html#ftn.FUNCTIONS-GEOMETRY-ROTATION-FN" class="footnoteref"><sup class="footnoteref">[a]</sup></a> <code class="type">path</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">path '((0,0),(1,0),(1,1))' / point '(2.0,0)'</code> + → <code class="returnvalue">((0,0),(0.5,0),(0.5,0.5))</code> + </p> + <p> + <code class="literal">path '((0,0),(1,0),(1,1))' / point(cosd(45), sind(45))</code> + → <code class="returnvalue">((0,0),(0.7071067811865476,-0.7071067811865476),(1.4142135623730951,0))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="literal">@-@</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes the total length. + Available for <code class="type">lseg</code>, <code class="type">path</code>. + </p> + <p> + <code class="literal">@-@ path '[(0,0),(1,0),(1,1)]'</code> + → <code class="returnvalue">2</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="literal">@@</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">point</code> + </p> + <p> + Computes the center point. + Available for <code class="type">box</code>, <code class="type">lseg</code>, + <code class="type">polygon</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">@@ box '(2,2),(0,0)'</code> + → <code class="returnvalue">(1,1)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="literal">#</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">integer</code> + </p> + <p> + Returns the number of points. + Available for <code class="type">path</code>, <code class="type">polygon</code>. + </p> + <p> + <code class="literal"># path '((1,0),(0,1),(-1,0))'</code> + → <code class="returnvalue">3</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">#</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">point</code> + </p> + <p> + Computes the point of intersection, or NULL if there is none. + Available for <code class="type">lseg</code>, <code class="type">line</code>. + </p> + <p> + <code class="literal">lseg '[(0,0),(1,1)]' # lseg '[(1,0),(0,1)]'</code> + → <code class="returnvalue">(0.5,0.5)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">box</code> <code class="literal">#</code> <code class="type">box</code> + → <code class="returnvalue">box</code> + </p> + <p> + Computes the intersection of two boxes, or NULL if there is none. + </p> + <p> + <code class="literal">box '(2,2),(-1,-1)' # box '(1,1),(-2,-2)'</code> + → <code class="returnvalue">(1,1),(-1,-1)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">##</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">point</code> + </p> + <p> + Computes the closest point to the first object on the second object. + Available for these pairs of types: + (<code class="type">point</code>, <code class="type">box</code>), + (<code class="type">point</code>, <code class="type">lseg</code>), + (<code class="type">point</code>, <code class="type">line</code>), + (<code class="type">lseg</code>, <code class="type">box</code>), + (<code class="type">lseg</code>, <code class="type">lseg</code>), + (<code class="type">line</code>, <code class="type">lseg</code>). + </p> + <p> + <code class="literal">point '(0,0)' ## lseg '[(2,0),(0,2)]'</code> + → <code class="returnvalue">(1,1)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal"><-></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes the distance between the objects. + Available for all geometric types except <code class="type">polygon</code>, + for all combinations + of <code class="type">point</code> with another geometric type, and for + these additional pairs of types: + (<code class="type">box</code>, <code class="type">lseg</code>), + (<code class="type">lseg</code>, <code class="type">line</code>), + (<code class="type">polygon</code>, <code class="type">circle</code>) + (and the commutator cases). + </p> + <p> + <code class="literal">circle '<(0,0),1>' <-> circle '<(5,0),1>'</code> + → <code class="returnvalue">3</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">@></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Does first object contain second? + Available for these pairs of types: + (<code class="literal">box</code>, <code class="literal">point</code>), + (<code class="literal">box</code>, <code class="literal">box</code>), + (<code class="literal">path</code>, <code class="literal">point</code>), + (<code class="literal">polygon</code>, <code class="literal">point</code>), + (<code class="literal">polygon</code>, <code class="literal">polygon</code>), + (<code class="literal">circle</code>, <code class="literal">point</code>), + (<code class="literal">circle</code>, <code class="literal">circle</code>). + </p> + <p> + <code class="literal">circle '<(0,0),2>' @> point '(1,1)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal"><@</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object contained in or on second? + Available for these pairs of types: + (<code class="literal">point</code>, <code class="literal">box</code>), + (<code class="literal">point</code>, <code class="literal">lseg</code>), + (<code class="literal">point</code>, <code class="literal">line</code>), + (<code class="literal">point</code>, <code class="literal">path</code>), + (<code class="literal">point</code>, <code class="literal">polygon</code>), + (<code class="literal">point</code>, <code class="literal">circle</code>), + (<code class="literal">box</code>, <code class="literal">box</code>), + (<code class="literal">lseg</code>, <code class="literal">box</code>), + (<code class="literal">lseg</code>, <code class="literal">line</code>), + (<code class="literal">polygon</code>, <code class="literal">polygon</code>), + (<code class="literal">circle</code>, <code class="literal">circle</code>). + </p> + <p> + <code class="literal">point '(1,1)' <@ circle '<(0,0),2>'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">&&</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Do these objects overlap? (One point in common makes this true.) + Available for <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(1,1),(0,0)' && box '(2,2),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal"><<</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object strictly left of second? + Available for <code class="type">point</code>, <code class="type">box</code>, + <code class="type">polygon</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">circle '<(0,0),1>' << circle '<(5,0),1>'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">>></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object strictly right of second? + Available for <code class="type">point</code>, <code class="type">box</code>, + <code class="type">polygon</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">circle '<(5,0),1>' >> circle '<(0,0),1>'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">&<</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Does first object not extend to the right of second? + Available for <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(1,1),(0,0)' &< box '(2,2),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">&></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Does first object not extend to the left of second? + Available for <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(3,3),(0,0)' &> box '(2,2),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal"><<|</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object strictly below second? + Available for <code class="type">point</code>, <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(3,3),(0,0)' <<| box '(5,5),(3,4)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">|>></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object strictly above second? + Available for <code class="type">point</code>, <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(5,5),(3,4)' |>> box '(3,3),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">&<|</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Does first object not extend above second? + Available for <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(1,1),(0,0)' &<| box '(2,2),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">|&></code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Does first object not extend below second? + Available for <code class="type">box</code>, <code class="type">polygon</code>, + <code class="type">circle</code>. + </p> + <p> + <code class="literal">box '(3,3),(0,0)' |&> box '(2,2),(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">box</code> <code class="literal"><^</code> <code class="type">box</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object below second (allows edges to touch)? + </p> + <p> + <code class="literal">box '((1,1),(0,0))' <^ box '((2,2),(1,1))'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">box</code> <code class="literal">>^</code> <code class="type">box</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is first object above second (allows edges to touch)? + </p> + <p> + <code class="literal">box '((2,2),(1,1))' >^ box '((1,1),(0,0))'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">?#</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Do these objects intersect? + Available for these pairs of types: + (<code class="type">box</code>, <code class="type">box</code>), + (<code class="type">lseg</code>, <code class="type">box</code>), + (<code class="type">lseg</code>, <code class="type">lseg</code>), + (<code class="type">lseg</code>, <code class="type">line</code>), + (<code class="type">line</code>, <code class="type">box</code>), + (<code class="type">line</code>, <code class="type">line</code>), + (<code class="type">path</code>, <code class="type">path</code>). + </p> + <p> + <code class="literal">lseg '[(-1,0),(1,0)]' ?# box '(2,2),(-2,-2)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="literal">?-</code> <code class="type">line</code> + → <code class="returnvalue">boolean</code> + </p> + <p class="func_signature"> + <code class="literal">?-</code> <code class="type">lseg</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is line horizontal? + </p> + <p> + <code class="literal">?- lseg '[(-1,0),(1,0)]'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">point</code> <code class="literal">?-</code> <code class="type">point</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Are points horizontally aligned (that is, have same y coordinate)? + </p> + <p> + <code class="literal">point '(1,0)' ?- point '(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="literal">?|</code> <code class="type">line</code> + → <code class="returnvalue">boolean</code> + </p> + <p class="func_signature"> + <code class="literal">?|</code> <code class="type">lseg</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Is line vertical? + </p> + <p> + <code class="literal">?| lseg '[(-1,0),(1,0)]'</code> + → <code class="returnvalue">f</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">point</code> <code class="literal">?|</code> <code class="type">point</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Are points vertically aligned (that is, have same x coordinate)? + </p> + <p> + <code class="literal">point '(0,1)' ?| point '(0,0)'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">line</code> <code class="literal">?-|</code> <code class="type">line</code> + → <code class="returnvalue">boolean</code> + </p> + <p class="func_signature"> + <code class="type">lseg</code> <code class="literal">?-|</code> <code class="type">lseg</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Are lines perpendicular? + </p> + <p> + <code class="literal">lseg '[(0,0),(0,1)]' ?-| lseg '[(0,0),(1,0)]'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="type">line</code> <code class="literal">?||</code> <code class="type">line</code> + → <code class="returnvalue">boolean</code> + </p> + <p class="func_signature"> + <code class="type">lseg</code> <code class="literal">?||</code> <code class="type">lseg</code> + → <code class="returnvalue">boolean</code> + </p> + <p> + Are lines parallel? + </p> + <p> + <code class="literal">lseg '[(-1,0),(1,0)]' ?|| lseg '[(-1,2),(1,2)]'</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <em class="replaceable"><code>geometric_type</code></em> <code class="literal">~=</code> <em class="replaceable"><code>geometric_type</code></em> + → <code class="returnvalue">boolean</code> + </p> + <p> + Are these objects the same? + Available for <code class="type">point</code>, <code class="type">box</code>, + <code class="type">polygon</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))'</code> + → <code class="returnvalue">t</code> + </p></td></tr></tbody><tbody class="footnotes"><tr><td colspan="1"><div id="ftn.FUNCTIONS-GEOMETRY-ROTATION-FN" class="footnote"><p><a href="#FUNCTIONS-GEOMETRY-ROTATION-FN" class="para"><sup class="para">[a] </sup></a><span class="quote">“<span class="quote">Rotating</span>”</span> 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.</p></div></td></tr></tbody></table></div></div><br class="table-break" /><div class="caution"><h3 class="title">Caution</h3><p> + Note that the <span class="quote">“<span class="quote">same as</span>”</span> operator, <code class="literal">~=</code>, + represents the usual notion of equality for the <code class="type">point</code>, + <code class="type">box</code>, <code class="type">polygon</code>, and <code class="type">circle</code> types. + Some of the geometric types also have an <code class="literal">=</code> operator, but + <code class="literal">=</code> compares for equal <span class="emphasis"><em>areas</em></span> only. + The other scalar comparison operators (<code class="literal"><=</code> and so + on), where available for these types, likewise compare areas. + </p></div><div class="note"><h3 class="title">Note</h3><p> + Before <span class="productname">PostgreSQL</span> 14, the point + is strictly below/above comparison operators <code class="type">point</code> + <code class="literal"><<|</code> <code class="type">point</code> and <code class="type">point</code> + <code class="literal">|>></code> <code class="type">point</code> were respectively + called <code class="literal"><^</code> and <code class="literal">>^</code>. These + names are still available, but are deprecated and will eventually be + removed. + </p></div><div class="table" id="FUNCTIONS-GEOMETRY-FUNC-TABLE"><p class="title"><strong>Table 9.36. Geometric Functions</strong></p><div class="table-contents"><table class="table" summary="Geometric Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature"> + Function + </p> + <p> + Description + </p> + <p> + Example(s) + </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.1.1.1.1" class="indexterm"></a> + <code class="function">area</code> ( <em class="replaceable"><code>geometric_type</code></em> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes area. + Available for <code class="type">box</code>, <code class="type">path</code>, <code class="type">circle</code>. + A <code class="type">path</code> input must be closed, else NULL is returned. + Also, if the <code class="type">path</code> is self-intersecting, the result may be + meaningless. + </p> + <p> + <code class="literal">area(box '(2,2),(0,0)')</code> + → <code class="returnvalue">4</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.2.1.1.1" class="indexterm"></a> + <code class="function">center</code> ( <em class="replaceable"><code>geometric_type</code></em> ) + → <code class="returnvalue">point</code> + </p> + <p> + Computes center point. + Available for <code class="type">box</code>, <code class="type">circle</code>. + </p> + <p> + <code class="literal">center(box '(1,2),(0,0)')</code> + → <code class="returnvalue">(0.5,1)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.3.1.1.1" class="indexterm"></a> + <code class="function">diagonal</code> ( <code class="type">box</code> ) + → <code class="returnvalue">lseg</code> + </p> + <p> + Extracts box's diagonal as a line segment + (same as <code class="function">lseg(box)</code>). + </p> + <p> + <code class="literal">diagonal(box '(1,2),(0,0)')</code> + → <code class="returnvalue">[(1,2),(0,0)]</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.4.1.1.1" class="indexterm"></a> + <code class="function">diameter</code> ( <code class="type">circle</code> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes diameter of circle. + </p> + <p> + <code class="literal">diameter(circle '<(0,0),2>')</code> + → <code class="returnvalue">4</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.5.1.1.1" class="indexterm"></a> + <code class="function">height</code> ( <code class="type">box</code> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes vertical size of box. + </p> + <p> + <code class="literal">height(box '(1,2),(0,0)')</code> + → <code class="returnvalue">2</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.6.1.1.1" class="indexterm"></a> + <code class="function">isclosed</code> ( <code class="type">path</code> ) + → <code class="returnvalue">boolean</code> + </p> + <p> + Is path closed? + </p> + <p> + <code class="literal">isclosed(path '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.7.1.1.1" class="indexterm"></a> + <code class="function">isopen</code> ( <code class="type">path</code> ) + → <code class="returnvalue">boolean</code> + </p> + <p> + Is path open? + </p> + <p> + <code class="literal">isopen(path '[(0,0),(1,1),(2,0)]')</code> + → <code class="returnvalue">t</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.8.1.1.1" class="indexterm"></a> + <code class="function">length</code> ( <em class="replaceable"><code>geometric_type</code></em> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes the total length. + Available for <code class="type">lseg</code>, <code class="type">path</code>. + </p> + <p> + <code class="literal">length(path '((-1,0),(1,0))')</code> + → <code class="returnvalue">4</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.9.1.1.1" class="indexterm"></a> + <code class="function">npoints</code> ( <em class="replaceable"><code>geometric_type</code></em> ) + → <code class="returnvalue">integer</code> + </p> + <p> + Returns the number of points. + Available for <code class="type">path</code>, <code class="type">polygon</code>. + </p> + <p> + <code class="literal">npoints(path '[(0,0),(1,1),(2,0)]')</code> + → <code class="returnvalue">3</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.10.1.1.1" class="indexterm"></a> + <code class="function">pclose</code> ( <code class="type">path</code> ) + → <code class="returnvalue">path</code> + </p> + <p> + Converts path to closed form. + </p> + <p> + <code class="literal">pclose(path '[(0,0),(1,1),(2,0)]')</code> + → <code class="returnvalue">((0,0),(1,1),(2,0))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.11.1.1.1" class="indexterm"></a> + <code class="function">popen</code> ( <code class="type">path</code> ) + → <code class="returnvalue">path</code> + </p> + <p> + Converts path to open form. + </p> + <p> + <code class="literal">popen(path '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">[(0,0),(1,1),(2,0)]</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.12.1.1.1" class="indexterm"></a> + <code class="function">radius</code> ( <code class="type">circle</code> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes radius of circle. + </p> + <p> + <code class="literal">radius(circle '<(0,0),2>')</code> + → <code class="returnvalue">2</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.13.1.1.1" class="indexterm"></a> + <code class="function">slope</code> ( <code class="type">point</code>, <code class="type">point</code> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes slope of a line drawn through the two points. + </p> + <p> + <code class="literal">slope(point '(0,0)', point '(2,1)')</code> + → <code class="returnvalue">0.5</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.6.2.2.14.1.1.1" class="indexterm"></a> + <code class="function">width</code> ( <code class="type">box</code> ) + → <code class="returnvalue">double precision</code> + </p> + <p> + Computes horizontal size of box. + </p> + <p> + <code class="literal">width(box '(1,2),(0,0)')</code> + → <code class="returnvalue">1</code> + </p></td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="FUNCTIONS-GEOMETRY-CONV-TABLE"><p class="title"><strong>Table 9.37. Geometric Type Conversion Functions</strong></p><div class="table-contents"><table class="table" summary="Geometric Type Conversion Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature"> + Function + </p> + <p> + Description + </p> + <p> + Example(s) + </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.1.1.1.1" class="indexterm"></a> + <code class="function">box</code> ( <code class="type">circle</code> ) + → <code class="returnvalue">box</code> + </p> + <p> + Computes box inscribed within the circle. + </p> + <p> + <code class="literal">box(circle '<(0,0),2>')</code> + → <code class="returnvalue">(1.414213562373095,1.414213562373095),(-1.414213562373095,-1.414213562373095)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">box</code> ( <code class="type">point</code> ) + → <code class="returnvalue">box</code> + </p> + <p> + Converts point to empty box. + </p> + <p> + <code class="literal">box(point '(1,0)')</code> + → <code class="returnvalue">(1,0),(1,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">box</code> ( <code class="type">point</code>, <code class="type">point</code> ) + → <code class="returnvalue">box</code> + </p> + <p> + Converts any two corner points to box. + </p> + <p> + <code class="literal">box(point '(0,1)', point '(1,0)')</code> + → <code class="returnvalue">(1,1),(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">box</code> ( <code class="type">polygon</code> ) + → <code class="returnvalue">box</code> + </p> + <p> + Computes bounding box of polygon. + </p> + <p> + <code class="literal">box(polygon '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">(2,1),(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.5.1.1.1" class="indexterm"></a> + <code class="function">bound_box</code> ( <code class="type">box</code>, <code class="type">box</code> ) + → <code class="returnvalue">box</code> + </p> + <p> + Computes bounding box of two boxes. + </p> + <p> + <code class="literal">bound_box(box '(1,1),(0,0)', box '(4,4),(3,3)')</code> + → <code class="returnvalue">(4,4),(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.6.1.1.1" class="indexterm"></a> + <code class="function">circle</code> ( <code class="type">box</code> ) + → <code class="returnvalue">circle</code> + </p> + <p> + Computes smallest circle enclosing box. + </p> + <p> + <code class="literal">circle(box '(1,1),(0,0)')</code> + → <code class="returnvalue"><(0.5,0.5),0.7071067811865476></code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">circle</code> ( <code class="type">point</code>, <code class="type">double precision</code> ) + → <code class="returnvalue">circle</code> + </p> + <p> + Constructs circle from center and radius. + </p> + <p> + <code class="literal">circle(point '(0,0)', 2.0)</code> + → <code class="returnvalue"><(0,0),2></code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">circle</code> ( <code class="type">polygon</code> ) + → <code class="returnvalue">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 class="literal">circle(polygon '((0,0),(1,3),(2,0))')</code> + → <code class="returnvalue"><(1,1),1.6094757082487299></code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.9.1.1.1" class="indexterm"></a> + <code class="function">line</code> ( <code class="type">point</code>, <code class="type">point</code> ) + → <code class="returnvalue">line</code> + </p> + <p> + Converts two points to the line through them. + </p> + <p> + <code class="literal">line(point '(-1,0)', point '(1,0)')</code> + → <code class="returnvalue">{0,-1,0}</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.10.1.1.1" class="indexterm"></a> + <code class="function">lseg</code> ( <code class="type">box</code> ) + → <code class="returnvalue">lseg</code> + </p> + <p> + Extracts box's diagonal as a line segment. + </p> + <p> + <code class="literal">lseg(box '(1,0),(-1,0)')</code> + → <code class="returnvalue">[(1,0),(-1,0)]</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">lseg</code> ( <code class="type">point</code>, <code class="type">point</code> ) + → <code class="returnvalue">lseg</code> + </p> + <p> + Constructs line segment from two endpoints. + </p> + <p> + <code class="literal">lseg(point '(-1,0)', point '(1,0)')</code> + → <code class="returnvalue">[(-1,0),(1,0)]</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.12.1.1.1" class="indexterm"></a> + <code class="function">path</code> ( <code class="type">polygon</code> ) + → <code class="returnvalue">path</code> + </p> + <p> + Converts polygon to a closed path with the same list of points. + </p> + <p> + <code class="literal">path(polygon '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">((0,0),(1,1),(2,0))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.13.1.1.1" class="indexterm"></a> + <code class="function">point</code> ( <code class="type">double precision</code>, <code class="type">double precision</code> ) + → <code class="returnvalue">point</code> + </p> + <p> + Constructs point from its coordinates. + </p> + <p> + <code class="literal">point(23.4, -44.5)</code> + → <code class="returnvalue">(23.4,-44.5)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">point</code> ( <code class="type">box</code> ) + → <code class="returnvalue">point</code> + </p> + <p> + Computes center of box. + </p> + <p> + <code class="literal">point(box '(1,0),(-1,0)')</code> + → <code class="returnvalue">(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">point</code> ( <code class="type">circle</code> ) + → <code class="returnvalue">point</code> + </p> + <p> + Computes center of circle. + </p> + <p> + <code class="literal">point(circle '<(0,0),2>')</code> + → <code class="returnvalue">(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">point</code> ( <code class="type">lseg</code> ) + → <code class="returnvalue">point</code> + </p> + <p> + Computes center of line segment. + </p> + <p> + <code class="literal">point(lseg '[(-1,0),(1,0)]')</code> + → <code class="returnvalue">(0,0)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">point</code> ( <code class="type">polygon</code> ) + → <code class="returnvalue">point</code> + </p> + <p> + Computes center of polygon (the mean of the + positions of the polygon's points). + </p> + <p> + <code class="literal">point(polygon '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">(1,0.3333333333333333)</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <a id="id-1.5.8.17.7.2.2.18.1.1.1" class="indexterm"></a> + <code class="function">polygon</code> ( <code class="type">box</code> ) + → <code class="returnvalue">polygon</code> + </p> + <p> + Converts box to a 4-point polygon. + </p> + <p> + <code class="literal">polygon(box '(1,1),(0,0)')</code> + → <code class="returnvalue">((0,0),(0,1),(1,1),(1,0))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">polygon</code> ( <code class="type">circle</code> ) + → <code class="returnvalue">polygon</code> + </p> + <p> + Converts circle to a 12-point polygon. + </p> + <p> + <code class="literal">polygon(circle '<(0,0),2>')</code> + → <code class="returnvalue">((-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></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">polygon</code> ( <code class="type">integer</code>, <code class="type">circle</code> ) + → <code class="returnvalue">polygon</code> + </p> + <p> + Converts circle to an <em class="replaceable"><code>n</code></em>-point polygon. + </p> + <p> + <code class="literal">polygon(4, circle '<(3,0),1>')</code> + → <code class="returnvalue">((2,0),(3,1),(4,1.2246063538223773e-16),(3,-1))</code> + </p></td></tr><tr><td class="func_table_entry"><p class="func_signature"> + <code class="function">polygon</code> ( <code class="type">path</code> ) + → <code class="returnvalue">polygon</code> + </p> + <p> + Converts closed path to a polygon with the same list of points. + </p> + <p> + <code class="literal">polygon(path '((0,0),(1,1),(2,0))')</code> + → <code class="returnvalue">((0,0),(1,1),(2,0))</code> + </p></td></tr></tbody></table></div></div><br class="table-break" /><p> + It is possible to access the two component numbers of a <code class="type">point</code> + as though the point were an array with indexes 0 and 1. For example, if + <code class="literal">t.p</code> is a <code class="type">point</code> column then + <code class="literal">SELECT p[0] FROM t</code> retrieves the X coordinate and + <code class="literal">UPDATE t SET p[1] = ...</code> changes the Y coordinate. + In the same way, a value of type <code class="type">box</code> or <code class="type">lseg</code> can be treated + as an array of two <code class="type">point</code> values. + </p></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-enum.html" title="9.10. Enum Support Functions">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-net.html" title="9.12. Network Address Functions and Operators">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.10. Enum Support Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 14.5 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.12. Network Address Functions and Operators</td></tr></table></div></body></html>
\ No newline at end of file |