coordinate transform in Ruby on OGR
With 'Ruby on OGR' (Ruby with SWIG binding of OGR for Ruby, this term is stupidly made-up by me!), coordinate transformation is as easy as forrowing:
Ruby on OGR を使えば,座標変換は下のように簡単に書ける。
Coordination Transformation ist einfach mit Ruby an OGR.
require 'gdal/ogr'ix = Gdal::Osr::SpatialReference.new
ix.import_from_epsg(2451)
wgs84 = Gdal::Osr::SpatialReference.new
wgs84.import_from_epsg(4326)
ct = Gdal::Osr::CoordinateTransformation.new(ix, wgs84)
g = Gdal::Ogr.create_geometry_from_wkt('POINT(0 0)')
g.transform(ct)
p g.export_to_wkt
This ruby script will produce:
Das Ergebnis ist:
"POINT (139.833333333333428 36.000000000000036)"
この結果を,国土地理院の緯度、経度への換算と比較してみる。平面直角座標系 IX 系の座標 (0, 0) を変換した結果は以下の通り。
- 緯度:36°00′00.00000″=36.00000...
- 経度:139°50′00.00000″=139.833333333333...
以下,数値計算法的に詰めの甘い分析だが,残差は,緯度方向に3.5527136788005e-14,経度方向に4.2632564145606e-13。というか,このくらいの値だと,両プログラムの数値の表示打ち切りの影響下にあることが考えられる。
が,とりあえずはこの残差が大圏距離でどのくらいであるかを
Great-Circle Distance in Rubyにより計算してみると,以下のようになった。
irb(main):025:0> sprintf("%.50f", distance(139.833333333333, 36.00000, 139.833333333333428, 36.000000000000036))
=> "0.00000000000000000000000000000000000000000000000000"
数値計算法的にとってもいい加減な検証だとは思うが,国土地理院による計算と有意な差はないものとして使っていって問題ないと考えておく。