« あけましておめでとうございます | メイン | 「世界の地図」コンテンツサービスがリリースされました。 »

I tried to add GIS functions (distance_sphere and distance_spheroid) as native functions for MySQL.

I tried to add GIS functions (distance_sphere and distance_spheroid) as native functions for MySQL.
(source & patch: mysql-native-distance_spheroid-1.0.tar.gz)

I had already released the functions as UDF.
(see http://okilab.jp/blog/2008/07/distance_sphere_distance_spher.html)

"distance_sphere()" returns linear distance in meters between two lat/lon points. Uses a spherical earth and radius of 6370986 meters.
"distance_spheroid()" returns linear distance between two lat/lon points given a particular spheroid.

BUILDING
------------------------
1) Put the sources (item_sphr_geofunc.h, item_sphr_geofunc.cc, calc_distance_spheroid.h calc_distance_spheroid.cc) into mysql-5.1.*-beta-GIS/sql directory.

2) To add new native functions, edit 4 files (Makefile.in, item.h, item_func.h item_create.cc) in mysql-5.1.*-beta-GIS/sql.

I made patches for 'mysql-5.1.23-beta-GIS' that is released on http://downloads.mysql.com/forge/mysql-5.1.23-beta-GIS/. Please use or refer to the patches.
(e.g)
patch Makefile.in < Makefile.in.patch
patch item.h < item.h.patch
patch item_create.cc < item_create.cc.patch
patch item_func.h < item_func.h.patch

3) Make as usual.
(e.g)
./configure
./make
./make install

USING
------------------------
(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;


MySQLへGIS関数(distance_sphere と distance_spheroid)をネィティブ関数として追加してみました。
(ソースとパッチ: mysql-native-distance_spheroid-1.0.tar.gz)

この関数はUDFとして既に公開済みのものです。
(mysql-native-distance_spheroid-1.0.tar.gzを見て下さい。)

distance_sphere(point, point)
 2つの緯度経度を結ぶ直線距離をメートルで返します。地球を半径6,370,986mの球形として計算します。
distance_spheroid(point, point, spheroid)
 回転楕円体を指定して2つの緯度経度を結ぶ直線距離を計算します。現在、点間のみが実装されています。

ビルド
------------------------
1) ソース(item_sphr_geofunc.h, item_sphr_geofunc.cc, calc_distance_spheroid.h calc_distance_spheroid.cc)を mysql-5.1.*-beta-GIS/sql ディレクトリに置きます。

2) ネィティブ関数として追加するために、mysql-5.1.*-beta-GIS/sql にある4つのファイル(Makefile.in, item.h, item_func.h item_create.cc)を編集します。

 http://downloads.mysql.com/forge/mysql-5.1.23-beta-GIS/. にある mysql-5.1.23-beta-GIS へのパッチファイルを作成しました。これを使い、あるいは参照してください。
 (例)
patch Makefile.in < Makefile.in.patch
patch item.h < item.h.patch
patch item_create.cc < item_create.cc.patch
patch item_func.h < item_func.h.patch

3) いつものようにメイクしてください。
 (例)
./configure
./make
./make install

使用方法
------------------------
 (例)
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://www.mailpia.jp/cgi-bin/mt_32/mt-tb.cgi/147

コメント (1)

okumula:

パッチの例のところに
patch item.h と、一つだけ書いていたのですが、それ一つだと勘違いされる可能性もあるので、4つ全てを記述しました。

気づかせていただいた
http://bluenotes.justblog.jp/technote/2009/03/mysql-d809.html
に感謝です。

コメントを投稿