バージョンごとのドキュメント一覧

F.15. earthdistance — 大圏距離を計算する #

<title>earthdistance &mdash; calculate great-circle distances</title>

The <filename>earthdistance</filename> module provides two different approaches to calculating great circle distances on the surface of the Earth. The one described first depends on the <filename>cube</filename> module. The second one is based on the built-in <type>point</type> data type, using longitude and latitude for the coordinates. earthdistanceは地表面上の大圏距離を計算する、2つの異なる方式を提供します。 最初に説明する方式はcubeモジュールに依存します。 2番目の方式は、座標系として緯度経度を使用した、組み込みのpointデータ型を基にしたものです。

In this module, the Earth is assumed to be perfectly spherical. (If that's too inaccurate for you, you might want to look at the <application><ulink url="https://postgis.net/">PostGIS</ulink></application> project.) このモジュールでは地球は完全な球体であると仮定します。 (この精度が不十分な場合は、PostGISプロジェクトを参照することを勧めます。)

The <filename>cube</filename> module must be installed before <filename>earthdistance</filename> can be installed (although you can use the <literal>CASCADE</literal> option of <command>CREATE EXTENSION</command> to install both in one command). cubeモジュールはearthdistanceをインストールする前にインストールしなければなりません(一つのコマンドで両方をインストールするためにCREATE EXTENSIONCASCADEオプションを使うこともできますが)。

注意

It is strongly recommended that <filename>earthdistance</filename> and <filename>cube</filename> be installed in the same schema, and that that schema be one for which CREATE privilege has not been and will not be granted to any untrusted users. Otherwise there are installation-time security hazards if <filename>earthdistance</filename>'s schema contains objects defined by a hostile user. Furthermore, when using <filename>earthdistance</filename>'s functions after installation, the entire search path should contain only trusted schemas. earthdistancecubeは同じスキーマにインストールし、そのスキーマは信頼できないユーザにCREATE権限を許可していないし、今後も許可することのないものとすることを強く勧めます。 さもないと、earthdistanceのスキーマが悪意のあるユーザにより定義されたオブジェクトを含んでいた場合に、インストール時のセキュリティ問題になります。 さらに、インストール後にearthdistanceの関数を使う時には、サーチパス全体には信頼するスキーマだけが含まれるようにすべきです。

F.15.1. cubeを基にした地表距離 #

<title>Cube-Based Earth Distances</title>

Data is stored in cubes that are points (both corners are the same) using 3 coordinates representing the x, y, and z distance from the center of the Earth. A <glossterm linkend="glossary-domain">domain</glossterm> <type>earth</type> over type <type>cube</type> is provided, which includes constraint checks that the value meets these restrictions and is reasonably close to the actual surface of the Earth. 地球中心からのx、y、z距離をあらわす3つの座標を使用した点(両隅が同じ)であるcubeとして、データは格納されます。 cube型上にearthドメインが提供されます。 これには、値がこれら制限を満たすか、また値が実際の地表面に十分近いかどうかの整合性検査を含みます。

The radius of the Earth is obtained from the <function>earth()</function> function. It is given in meters. But by changing this one function you can change the module to use some other units, or to use a different value of the radius that you feel is more appropriate. 地球の半径はearth()関数から入手されます。 この単位はメートルです。 しかしこの1つの関数を変更することで、何らかの他の単位を使用するようにしたり、より適切と考える別の半径を使用したりするようにこのモジュールを変更することができます。

This package has applications to astronomical databases as well. Astronomers will probably want to change <function>earth()</function> to return a radius of <literal>180/pi()</literal> so that distances are in degrees. このパッケージは天文学データベースへの応用もあります。 天文学者はおそらく距離が度単位になるように、earth()180/pi()の半径を返すものと変更したいでしょう。

Functions are provided to support input in latitude and longitude (in degrees), to support output of latitude and longitude, to calculate the great circle distance between two points and to easily specify a bounding box usable for index searches. 緯度経度(度単位)の入力をサポート、緯度経度の出力をサポート、2点間の大圏距離を計算、インデックス検索に使用可能な簡単に外接矩形を指定するための関数が提供されます。

The provided functions are shown in <xref linkend="earthdistance-cube-functions"/>. 提供されている関数は表 F.5に示されています。

表F.5 cubeを基にしたearthdistanceの関数

<title>Cube-Based Earthdistance Functions</title>

Function 関数

Description 説明

earth () → float8

Returns the assumed radius of the Earth. 地球の想定半径を返します。

sec_to_gc ( float8 ) → float8

Converts the normal straight line (secant) distance between two points on the surface of the Earth to the great circle distance between them. 地表の2点間の通常の直線(割線)距離を大圏距離に変換します。

gc_to_sec ( float8 ) → float8

Converts the great circle distance between two points on the surface of the Earth to the normal straight line (secant) distance between them. 地表の2点間の大圏距離を通常の直線(割線)距離に変換します。

ll_to_earth ( float8, float8 ) → earth

Returns the location of a point on the surface of the Earth given its latitude (argument 1) and longitude (argument 2) in degrees. 度単位で指定された緯度(第1引数)と経度(第2引数)に対する地表位置を返します。

latitude ( earth ) → float8

Returns the latitude in degrees of a point on the surface of the Earth. 地表上の点の緯度を度単位で返します。

longitude ( earth ) → float8

Returns the longitude in degrees of a point on the surface of the Earth. 地表上の点の経度を度単位で返します。

earth_distance ( earth, earth ) → float8

Returns the great circle distance between two points on the surface of the Earth. 地表上の2点間の大圏距離を返します。

earth_box ( earth, float8 ) → cube

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. 位置から指定した大圏距離内の点に対するcube@>演算子を使用するインデックス検索に適した矩形を返します。 矩形内の点の一部は指定した大圏距離の外部にあります。 このため、earth_distanceを使用した第2の検査を問い合わせに含めなければなりません。


F.15.2. pointを基にした地表距離 #

<title>Point-Based Earth Distances</title>

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. このモジュールの第2部分はpoint型の値として地球上の位置を表現することに依存します。 ここで第1要素は経度を度単位で、第2要素は緯度を度単位で表現していると見なします。 直感的に経度はX軸、緯度はY軸という考えがより合うため、点は(経度, 緯度)として見なされますが、逆には見なされません。

A single operator is provided, shown in <xref linkend="earthdistance-point-operators"/>. 表 F.6に示されている1つの演算子が提供されます。

表F.6 pointを基にしたearthdistanceの演算子

<title>Point-Based Earthdistance Operators</title>

Operator 演算子

Description 説明

point <@> pointfloat8

Computes the distance in statute miles between two points on the Earth's surface. 法定マイル単位の地表の2点間の距離を計算します。


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. このモジュールのcubeを基にした場合と異なり、ここでの単位はコード内に固定で記載されることに注意してください。 earth()関数を変更しても、この演算子の結果には影響しません。

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. 緯度経度表現の1つの欠点は、極近辺と経度±180度近辺の限界条件に注意する必要があることです。 cubeを基にした表現ではこうした不連続性を防止できます。