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>@></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><@></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>