« Shape to SVG Map converter | メイン | 座標参照系のPURL »

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>';

?>

トラックバック

このページのトラックバックURL:
http://www.typepad.jp/t/trackback/229612/6937845

このページへのトラックバック一覧 ISO6709Tool for PHP:

検索

注目エントリー

2008年8月

          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            

最近のトラックバック