ISO6709Tool for C#

C#用のISO6709(地理座標表記方法)のパーサ&シリアライザが、公開されました。
ISO6709 parser and serializer for C# were open to the public on the following sites.

http://www.codeproject.com/KB/cs/Coordinate.aspx

ISO6709記法の格納効率の良さについても言及されています。
The goodness of the storage efficiency of the ISO6709 notation has been described.

ISO6709Tool for PHP

PHP用のISO6709パーサ&シリアライザも作成しました。LGPLライセンスに基づいて、ご使用ください。
We also open ISO6709 tools for PHP. Please use it based on the LGPL license.

<?php

// =============================================================================
//
// ISO6709; ISO6709 (Latitude, Longitude and Altitude format)
//          Parser and Serializer for PHP
//           Copyright (C) 2007 Satoru Takagi, SVG Map Consortium
//
// History:
// 2007.04.26 First release
// =============================================================================
//
// This software is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by  the  Free
// Software Foundation; either version 2.1 of the License, or (at  your  option)
// any later version.
//
// This library is distributed in the hope that it will be  useful,  but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for  more
// details.
//
// You should have received a copy of the  GNU  Lesser  General  Public  License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =============================================================================

class ISO6709 {
var $latitude;
var $longitude;
var $altitude;

function ISO6709( $in ){
  $sec = 0.0;
  $min = 0.0;
  $deg = 0.0;
  ereg('([+-])([0-9][0-9])(([0-9][0-9])|())(([0-9][0-9])|())(([\.][0-9]+)|())([+-])([01][0-9][0-9])(([0-9][0-9])|())(([0-9][0-9])|())(([\.][0-9]+)|())(([+-][0-9]*\.?[0-9]*)|())(CRS(.*)|())[/]' , $in , $arr);
  if ( $arr != null ){
   if ( $arr[7] != null ){
    $sec = floatval( $arr[7] . $arr[10] );
    $min = intval( $arr[4] );
    $deg = intval( $arr[2] );
   } else if ( $arr[4] != null ){
    $min = floatval( $arr[4] . $arr[10] );
    $deg = intval( $arr[2] );
   } else {
    $deg = floatval( $arr[2] . $arr[10] );
   }
   $this -> latitude = floatval( $arr[1] . ( $deg + ( $min + $sec / 60.0 ) / 60.0 ) );
   
   $sec = 0.0;
   $min = 0.0;
   $deg = 0.0;
   if ( $arr[18] != null ){
    $sec = floatval( $arr[18] . $arr[21] );
    $min = intval( $arr[15] );
    $deg = intval( $arr[13] );
   } else if ( $arr[15] != null ){
    $min = floatval( $arr[15] . $arr[21] );
    $deg = intval( $arr[13] );
   } else {
    $deg = floatval( $arr[13] . $arr[21] );
   }
   $this -> longitude = floatval( $arr[12] . ( $deg + ( $min + $sec / 60.0 ) / 60.0 ) );
   
   if ( $arr[24] != null ){
    $this -> altitude = floatval( $arr[24] );
   }
  }
}

function toString( $format , $fractions ) {
  if ( $fractions == null ){
   $fractions = 6;
  }
  if ( $format == null ){
   $format = "d";
  }
  $alat = abs($this -> latitude);
  $alon = abs($this -> longitude);
  if ( $this -> latitude > 0 ){
   $str = "+";
  } else {
   $str = "-";
  }
  $str = $str . $this -> getLatOrLonStr( $alat , $format , $fractions , 2 );
  if ( $this -> longitude > 0 ){
   $str = $str . "+";
  } else {
   $str = $str . "-";
  }
  $str = $str . $this -> getLatOrLonStr( $alon , $format , $fractions , 3 );
  if ( $this -> altitude != null ){
   $aalt = abs( $this -> altitude );
   if ( $this -> altitude > 0 ){
    $str = $str . "+";
   } else {
    $str = $str . "-";
   }
   $str = $str . $aalt;
  }
  $str = $str . "/";
  return ( $str );
}

function getLatOrLonStr ( $latOrLon , $format , $fractions , $degLength ){
  if ( $fractions == 0){
   $rex = '([0-9]+)';
  } else {
   $rex = '(([0-9]+[\.][0-9]{0,'. $fractions .'})|([0-9]+))';
  }
  $latOrLon += 1000.0;
  if ( $format =="d" ){
   ereg( $rex , $latOrLon , $ret );
   return ( substr( $ret[1] ,  4 - $degLength  ) );
  } else {
   $deg = floor( $latOrLon );
   $min = ( $latOrLon - $deg ) * 60.0;
   if ( $format =="dm" ){
    ereg( $rex , $min + 100.0 , $ret );
    return ( substr( $deg , 4 - $degLength ) . substr( $ret[1] , 1 ) );
   } else {
    $sec = ( $min - floor( $min ) ) * 60.0;
    ereg( $rex , $sec + 100.0 , $ret );
    $min = floor ( 100.0 + $min );
    return ( substr( $deg , 4 - $degLength ) . substr( $min , 1 ) . substr( $ret[1] , 1 ) );
   }
  }
}
}

if (isset($_GET["position"])) {
$req = str_replace( " " , "+" , $_GET["position"] );
} else {
$req = "+35.5+139.5+100.0/";
}

$pos = new ISO6709($req);
$latitude = $pos -> latitude;
$longitude = $pos -> longitude;
$altitude = $pos -> altitude;

echo "<font color=red>Example: iso6709.php?position=+3530.224+13924.448+48.2/</font><br><br>";
echo "<font color=blue>input:$req = lat:$latitude long:$longitude alt:$altitude</font><br><br>";

echo 'toString(d):' .  $pos -> toString( "d" , 6 ) . '<br>';
echo 'toString(dm):' . $pos -> toString( "dm" , 6 ) . '<br>';
echo 'toString(dms):' . $pos -> toString( "dms" , 6 ) . '<br>';

?>

ISO6709Tool for JavaScript

ISO6709parser for Javascript

JavaScript用のISO6709パーサ&シリアライザも作成しました。LGPLライセンスに基づいて、ご使用ください。
We also open ISO6709 tools for JavaScript. Please use it based on the LGPL license.

2007.4.20 Bug fix


ISO6709 Tool for JavaScript Test Page
data:   fractions:   format:

ISO6709Tool for Java

ISO6709の文字列をパースして緯度・経度・高度数値にしたり、逆に緯度・経度・高度数値から、ISO6709文字列を生成したりできるツールを 公開します。

つたないコードですがご勘弁を・・

LGPLライセンスに基づいて、ご使用ください。

We open ISO6709 tools for java (parser and serializer) to the public. Please use it based on the LGPL license.

Download ISO6709Tool.zip

ISO6709の適用先

ISO6709の適用先を紹介したいと思います。

以下は、それぞれ、エスケープしなければならない文字がありますが、それはとりあえず省略して説明しています。

  • XMLエンコーディング (含 RDF/XML)
    例:
    <Point>+35.36083+138.72750/</Point>
  • HTMLメタデータ (microformats)
    例:
    <abbr class="geo" title="+275916+0865640+8850/">Mount Everest</abbr>
    <meta name="geo.position" content="+47.1595+130.0894/" />
  • URLエンコーディング
    例:
    http://hoge.net/pl?point=+35.36083+138.72750/
  • スプレッドシートや、筆記など
    例:
    番号 名前 場所
    富士山 +35.3608+138.7275/
    甲斐駒ケ岳 +35.7580+138.2367/

ISO6709のBNF

BNF description for ISO 6709-1983(E)

Number (N)
 N = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"

Number for Degrees (D)
 D = N
Number for Minutes (M)
 M = N
Number for Seconds (S)
 S = N

Integer part of Degrees for Latitude (DLAT)
 DLAT = ("+"|"-") D D
 "+" represents North.
 "-" represents South.
 -90<=DLAT<=+90

Integer part of Degrees for Longitude (DLON)
 DLON = ("+"|"-") D D D
 "+" represents East.
 "-" represents West.
 -180<=DLON<=+180

Decimal Fraction of Degrees (DP)
 DP = "." 1*(D)

Integer part of Minutes (MI)
 MI = M M
 0<=MI<60

Decimal Fraction of Minutes (MP)
 MP = "." 1*(M)

Integer part of Seconds (SI)
 SI = S S
 0<=SI<60

Decimal Fraction of Seconds (SP)
 SP = "." 1*(S)

 LatitudeInD   = DLAT [ DP ]       = ("+"|"-") D D [ "." 1*(D) ]
 LatitudeInDM  = DLAT MI [ MP  ]   = ("+"|"-") D D M M [ "." 1*(M) ]
 LatitudeInDMS = DLAT MI SI [ SP ] = ("+"|"-") D D M M S S [ "." 1*(S) ]

 LongitudeInD   = DLON [ DP ]       = ("+"|"-") D D D [ "." 1*(D) ]
 LongitudeInDM  = DLON MI [ MP ]    = ("+"|"-") D D D M M [ "." 1*(M) ]
 LongitudeInDMS = DLON MI SI [ SP ] = ("+"|"-") D D D M M S S [ "." 1*(S) ]

Altitude [m] (Altitude)
 Altitude = ("+"|"-") 1*(N)  ["." 1*(N) ]

Delimiter
 Delimiter = "/"

 LatLonAltInD = LatitudeInD LongitudeInD [Altitude] Delimiter
 LatLonAltInDM = LatitudeInDM LongitudeInDM [Altitude] Delimiter
 LatLonAltInDMS = LatitudeInDMS LongitudeInDMS [Altitude] Delimiter

ISO6709 Latitude Longitude Altitude Representation
 LatLonAlt = LatLonAltInD | LatLonAltInDM | LatLonAltInDMS

Examples:
 +40-075/
 +40.20361-075.00417/
 +4012.22-007500.25/
 +401213.1-0750015.1/
 +40.20361-075.00417+350.517/

ISO6709の記法とサンプル

  1. 度表現での記法
    ±DD.DDDD±DDD.DDDD/
  2. 度分表現での記法
    ±DDMM.MMM±DDDMM.MMM/
  3. 度分秒表現での記法
    ±DDMMSS.SS±DDDMMSS.SS/
  • 緯度を一番目に、経度を二番目に書きます。
  • それぞれの値は必ず符号が必要です。
    緯度:北緯=+ 南緯=-
    経度:東経=+ 西経=-
  • それぞれ、整数部は固定長です。
    満たない場合は、0で埋める
    (このため、整数部の数字の数から、最初が緯度で二番目が経度であることが明示的になっています。)
  • 小数点以下は、可変長です。
    (無くてもかまわない)
  • "/"がデリミタです。
  • 空間参照系(例えばWGS-84など)は、考慮されていません。
    (この辺の課題・情報・考察はまた後日)

高度をオプションで付けることができます。
 ±DD.DDDD±DDD.DDDD±AAA.AAA/
 単位はメートル[m]です。
 やはり符号は必須です。
 高度は、整数部、小数部ともに可変長です。
 度分秒などのほかの表現でも付けることができます。

例:
富士山頂 北緯35度21分39秒、東経138度43分39秒は、
度分秒表現で
 +352139+1384339/
度表現では(電卓つかって換算してみてください)
 +35.36083+138.72750/
高度をつければ、
 +352139+1384339+3776/

東京タワー 北緯:35度39分31.075秒、東経:139度44分43.48秒は、
度分秒表現で、
 +353931.075+1394443.48/
度表現では
 +35.658632+139.745411/

ISO6709とは

このカテゴリでは、ISO6709について色々な情報を提供していこうと思います。

まずは、ISO6709自体について。

SVG Mapは、オープンでマッシュアップ自在な地図プラットホームを目指した活動なわけですが(この辺は詳しくはまた別の記事で)、そもそもの話として、その地図がどこの地図? という情報は、基本中の基本の情報になるわけですね。

「どこ?」を表現する方法は沢山(Web上にもほんとうにたくさん)ありますが、全世界共通で、しかも義務教育のレベルでみんなが認知している「どこ?」表現は、とりもなおさず「緯度経度」なわけです。某Maps系のサービスもみんな使ってます。

#緯度経度以外で、ポピュラーな「どこ?」表現は、「住所・アドレス」ですが・・・これは地域によって、その記述ルールがばらばらで、「共通の表現」というには厳しいものでしょう。

ということで、緯度経度の情報はSVG Mapの重要な情報なのですが、その表記方法は?というと、これまた方法は沢山(Web上にもほんとうにたくさん)在ることが判明しています。#どれぐらいあるかはまた後日

そんな中、注目しているのが、ISOの緯度経度(+高度)の記述仕様 ISO6709
正式名称は、ISO 6709-1983(E)というそうです。

これは、丁度ISO8601という日時表現の記述仕様が、インターネット(勿論Webでも(例W3CDTF))多用されていることからの類推で、緯度経度の標準的な表記方法として、広められる素質を持つ仕様だと考えているものです。

記法は比較的単純、しかも、度表現だけでなく、度分秒表現も可能、そして、どちらの数字が緯度でどちらの数字が経度かも一目瞭然な明解さも備えています。

検索

注目エントリー

2008年7月

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

最近のトラックバック