I tried to build "distance_sphere(), distance_spheroid() for MySQL" on Windows.
I used "Visual Studio 2008 C++ Express Edition", but it is not the only way.
I have little experience of developing software on Windows.
I request your comment.
You needs MySQL source files to build the UDF.
However you can use MySQL that installed with binary package (mysql-5.1.23-beta-GIS-GIS-win32.zip).
Notice: I used Japanese edition, therefore descriptions of operating is not precise.
* Prepare environment.
Visual Studio 2008 C++ (You can use "Express Edition")
CMake (http://www.cmake.org/)
* Download "mysql-5.1.23-beta-GIS.zip" and unzip into your_working_directory.
(http://downloads.mysql.com/forge/mysql-5.1.23-beta-GIS/)
* Create "win\build-vs9.bat" (copy from "win\build-vs8.bat" and edit 3 lines)
copy win\vs8cache.txt cmakecache.txt → copy win\vs9cache.txt cmakecache.txt
cmake -G "Visual Studio 8 2005" → cmake -G "Visual Studio 9 2008"
copy cmakecache.txt win\vs8cache.txt → copy cmakecache.txt win\vs9cache.txt
* Modify "sql\CMakeLists.txt"
+ Change
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN)
↓
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -D_USE_MATH_DEFINES)
+ Add following 3 lines at tail
ADD_LIBRARY(udf_distance_spheroid MODULE udf_distance_spheroid.cc udf_distance_spheroid.def calc_distance_spheroid.cc spatial.cc)
ADD_DEPENDENCIES(udf_distance_spheroid strings)
TARGET_LINK_LIBRARIES(udf_distance_spheroid strings)
* Copy the source code of the UDF(mysql-udf-distance_spheroid-1.0.tar.gz) into sql\ directory.
calc_distance_spheroid.cc
calc_distance_spheroid.h
udf_distance_spheroid.cc
* Create "udf_distance_spheroid.def" into sql\ directory.
LIBRARY udf_distance_spheroid
VERSION 1.0
EXPORTS
distance_spheroid
distance_spheroid_init
distance_spheroid_deinit
distance_sphere
distance_sphere_init
distance_sphere_deinit
* Put commands on windows command prompt
cd your_working_directory.
win\configure
win\build-vs9.bat
* Open "MySql.sln" with VC++
* Change "Active Solution" to "Release" in "Build" > "Manager" menu.
* Add "/FORCE:UNRESOLVED" into "Build" > "Linker" > "Command Line" about propety of udf_distance_spheroid
* Build "udf_distance_spheroid"
* Build "udf_distance_spheroid" again
* Copy "udf_distance_spheroid.dll" created in "sql\Release" into your "lib" directory in your MySQL install directory.
(e.g.: C:\Program Files\MySQL\MySQL Server 5.1\lib)
* Test
CREATE FUNCTION distance_sphere RETURNS REAL SONAME "udf_distance_spheroid.dll";
CREATE FUNCTION distance_spheroid RETURNS REAL SONAME "udf_distance_spheroid.dll";
SELECT distance_sphere(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326)) AS dist;
SELECT distance_spheroid(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326),'SPHEROID["GRS_1980",6378137,298.257222101]') AS dist;
Please refer sample files if you want.
"distance_sphere(), distance_spheroid() for MySQL" を Windows で使用するにはどうすればいいかという質問がありましたので、Visual Studio 2008 C++ Express Edition を使って作ってみました(他でも可能だと思いますが試していません)。
dll を作るのにMySQLのソースが必要になりますが、MySQL本体はバイナリイメージからインストールしたもので利用可能です。
Windows上の開発は慣れていないので、いろいろ、おかしなことをやっているかもしれません。お気づきの点がございましたら、コメントよろしくお願いします。
構築環境
Visual Studio 2008 C++(Express Editionも可)
CMake (http://www.cmake.org/)
mysql-5.1.23-beta-GIS.zipをダウンロードし作業ディレクトリに解凍する。
(http://downloads.mysql.com/forge/mysql-5.1.23-beta-GIS/)
win\build-vs9.bat を作成する。win\build-vs8.bat をコピーし、以下の3行を修正する。
copy win\vs8cache.txt cmakecache.txt → copy win\vs9cache.txt cmakecache.txt
cmake -G "Visual Studio 8 2005" → cmake -G "Visual Studio 9 2008"
copy cmakecache.txt win\vs8cache.txt → copy cmakecache.txt win\vs9cache.txt
sql\CMakeLists.txt を修正
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN)
↓
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -D_USE_MATH_DEFINES)
最後に以下の2行を追加
ADD_LIBRARY(udf_distance_spheroid MODULE udf_distance_spheroid.cc udf_distance_spheroid.def calc_distance_spheroid.cc spatial.cc)
ADD_DEPENDENCIES(udf_distance_spheroid strings)
TARGET_LINK_LIBRARIES(udf_distance_spheroid strings)
sql\に以下のファイルをコピー
calc_distance_spheroid.cc
calc_distance_spheroid.h
udf_distance_spheroid.cc
sql\に"udf_distance_spheroid.def"を作成
LIBRARY udf_distance_spheroid
VERSION 1.0
EXPORTS
distance_spheroid
distance_spheroid_init
distance_spheroid_deinit
distance_sphere
distance_sphere_init
distance_sphere_deinit
コマンドプロンプトで
cd 作業ディレクトリ
win\configure
win\build-vs9.bat
MySql.sln が作成されるので、これをVC++でオープン
ビルド>構成マネージャ>アクティブソリューションを Release に変更
udf_distance_spheroid のプロパティ ビルド>リンカ>コマンドライン に
/FORCE:UNRESOLVED
を追加
udf_distance_spheroid をビルド
その状態で再度ビルド
sql\Release に作成された udf_distance_spheroid.dll を MySQL本体をインストールしフォルダの lib ディレクトリ
(例:C:\Program Files\MySQL\MySQL Server 5.1\lib) にコピーする。
テスト
CREATE FUNCTION distance_sphere RETURNS REAL SONAME "udf_distance_spheroid.dll";
CREATE FUNCTION distance_spheroid RETURNS REAL SONAME "udf_distance_spheroid.dll";
SELECT distance_sphere(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326)) AS dist;
SELECT distance_spheroid(GEOMFROMTEXT('POINT(136 36)',4326),GEOMFROMTEXT('POINT(135 35)',4326),'SPHEROID["GRS_1980",6378137,298.257222101]') AS dist;
参考にサンプルをおいておきますので、必要に応じてご参照ください。