Home Explore Blog CI



postgresql

4th chunk of `doc/src/sgml/earthdistance.sgml`
9e9b378b2996ea1da620ac897c06095c5bdbe3e189e71f100000000100000beb
 role="func_signature">
        <indexterm><primary>earth_distance</primary></indexterm>
        <function>earth_distance</function> ( <type>earth</type>, <type>earth</type> )
        <returnvalue>float8</returnvalue>
       </para>
       <para>
        Returns the great circle distance between two points on the
        surface of the Earth.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>earth_box</primary></indexterm>
        <function>earth_box</function> ( <type>earth</type>, <type>float8</type> )
        <returnvalue>cube</returnvalue>
       </para>
       <para>
        Returns a box suitable for an indexed search using the <type>cube</type>
        <literal>@&gt;</literal>
        operator for points within a given great circle distance of a location.
        Some points in this box are further than the specified great circle
        distance from the location, so a second check using
        <function>earth_distance</function> should be included in the query.
       </para></entry>
      </row>
     </tbody>
   </tgroup>
  </table>

 </sect2>

 <sect2 id="earthdistance-point-based">
  <title>Point-Based Earth Distances</title>

  <para>
   The second part of the module relies on representing Earth locations as
   values of type <type>point</type>, in which the first component is taken to
   represent longitude in degrees, and the second component is taken to
   represent latitude in degrees.  Points are taken as (longitude, latitude)
   and not vice versa because longitude is closer to the intuitive idea of
   x-axis and latitude to y-axis.
  </para>

  <para>
   A single operator is provided, shown
   in <xref linkend="earthdistance-point-operators"/>.
  </para>

  <table id="earthdistance-point-operators">
   <title>Point-Based Earthdistance Operators</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Operator
       </para>
       <para>
        Description
       </para></entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>point</type> <literal>&lt;@&gt;</literal> <type>point</type>
        <returnvalue>float8</returnvalue>
       </para>
       <para>
        Computes the distance in statute miles between
        two points on the Earth's surface.
       </para></entry>
      </row>
     </tbody>
   </tgroup>
  </table>

  <para>
   Note that unlike the <type>cube</type>-based part of the module, units
   are hardwired here: changing the <function>earth()</function> function will
   not affect the results of this operator.
  </para>

  <para>
   One disadvantage of the longitude/latitude representation is that
   you need to be careful about the edge conditions near the poles
   and near +/- 180 degrees of longitude.  The <type>cube</type>-based
   representation avoids these discontinuities.
  </para>

 </sect2>

</sect1>

Title: Point-Based Earth Distance Calculations in earthdistance Module
Summary
The text describes the point-based earth distance calculations within the `earthdistance` module, contrasting it with the cube-based methods. It uses `point` data types, where the first component is longitude and the second is latitude. A single operator `<@>` calculates the distance in statute miles between two points. The module highlights the difference between the cube-based and point-based approach, noting the hardcoded units in the latter and the need to handle edge cases near the poles and +/- 180 degrees longitude.