« MySQL向け距離関数 distance_sphere(), distance_spheroid() のドキュメント | メイン | US-PALAで鎌倉で『眞鍋かをりのココだけの話』 »

The Documentation of UDF, distance_sphere() and distance_spheroid(), for MySQL

This is a documentation of UDF, distance_sphere() and distance_spheroid(), for MySQL.

These UDF(User Defined Function), distance_sphere() and distance_spheroid(), are compatible with same name functions in PostGIS.

FUNCTION
------------------------
distance_sphere(point, point)
returns linear distance in meters between two lat/lon points. Uses a spherical earth and radius of 6370986 meters. Faster than distance_spheroid(), but less accurate. Only implemented for points.

distance_spheroid(point, point, spheroid)
returns linear distance between two lat/lon points given a particular spheroid. Currently only implemented for points.


BUILDING
------------------------
Compile with mysql-5.1.*-beta-GIS sources.
(You can download at http://downloads.mysql.com/forge/mysql-5.1.23-beta-GIS/ )

1) Put the sources into mysql-5.1.*-beta-GIS/sql directory.

2) Compile with mysql-5.1.*-beta-GIS sources.
(e.g.)
g++ -DMYSQL_SERVER -shared -o udf_distance_spheroid.so -I../regex -I../sql -I../include spatial.cc calc_distance_spheroid.cc udf_distance_spheroid.cc

3) Move "udf_distance_spheroid.so" to mysql libirary directory.
(e.g.)
mv udf_distance_spheroid.so /usr/local/mysql/lib/mysql


USING
------------------------
1) Add the functions as UDF to MySQL.
(e.g.)

mysql> CREATE FUNCTION distance_sphere RETURNS REAL SONAME "udf_distance_spheroid.so";

mysql> CREATE FUNCTION distance_spheroid RETURNS REAL SONAME "udf_distance_spheroid.so";

2) Using in query
(e.g.)

mysql> SELECT distance_sphere(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326)) AS dist;

mysql> SELECT distance_spheroid(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326),'SPHEROID["GRS_1980",6378137,298.257222101]') AS dist;

トラックバック

このエントリーのトラックバックURL:
http://okilab.jp/cgi/mt_3/mt-tb.cgi/134

この一覧は、次のエントリーを参照しています: The Documentation of UDF, distance_sphere() and distance_spheroid(), for MySQL:

» distance_sphere(), distance_spheroid() for MySQL 送信元 OKILab.jp開発日記
I release 2 functions, distance_sphere(), distance_spheroid(), for MySQL. The... [詳しくはこちら]

コメントを投稿