geo.inc.php 2.41 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
<?php
Feu's avatar
Feu committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Copyright 2007
 * - Julien Etelain <julien CHEZ pmad POINT net>
 *
 * Ce fichier fait partie du site de l'Association des 0tudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
23

Ayolo's avatar
Ayolo committed
24
/**
Feu's avatar
Feu committed
25
 * @file
Ayolo's avatar
Ayolo committed
26
 * Fonctions de calcul geographique
Feu's avatar
Feu committed
27 28 29
 * Toute latitude positive => Nord, negative => Sud
 * Toute longiture positive => Est, negative => Ouest
 * @see geopoint
Ayolo's avatar
Ayolo committed
30 31 32
 */

/**
Feu's avatar
Feu committed
33 34 35
 * Converti une latitude/longitude exprimé en radians en degrés
 * @param $rad La valeur en radians
 * @return un texte representatnt la valeur en degrés (NN°NN'NN")
Feu's avatar
Feu committed
36
 * @ingroup display_cts_formsupport
Ayolo's avatar
Ayolo committed
37 38 39 40 41 42 43 44 45 46 47
 */
function geo_radians_to_degrees ( $rad )
{
  $degrees = $rad*360/2/M_PI;
  $deg = floor($degrees);
  $minutes = ($degrees-$deg)*60;
  $min = floor($minutes);
  $sec = round(($minutes-$min)*60,2);
  return $deg."°".$min."'".$sec."\"";
}

Feu's avatar
Feu committed
48 49
/**
 * Converti une latitude/longitude exprimé en degrés en radians
Feu's avatar
Feu committed
50
 * @param $deg Texte representant la valeur en degrés (NN°NN'NN" ou NN,NNNN)
Feu's avatar
Feu committed
51
 * @return la valeur en radians
Feu's avatar
Feu committed
52
 * @ingroup display_cts_formsupport
Feu's avatar
Feu committed
53
 */
Ayolo's avatar
Ayolo committed
54 55 56 57 58
function geo_degrees_to_radians ( $deg )
{
  if ( ereg("^([0-9]+)°([0-9]+)'([0-9,\.]+)\"(E|N|S|O|W)$",$deg,$regs) )
  {
    $res = ((((str_replace(",",".",$regs[3])/60)+$regs[2])/60)+$regs[1])*2*M_PI/360;
59

Ayolo's avatar
Ayolo committed
60 61
    if ( $regs[4] == "O" || $regs[4] == "S" || $regs[4] == "W" )
      return -1*$res;
62

Ayolo's avatar
Ayolo committed
63
    return $res;
64
  }
Feu's avatar
Feu committed
65
  elseif ( ereg("^([0-9]+)°([0-9]+)'([0-9,\.]+)\"$",$deg,$regs) )
66
    return ((((str_replace(",",".",$regs[3])/60)+$regs[2])/60)+$regs[1])*2*M_PI/360;
Feu's avatar
Feu committed
67 68 69
  elseif ( ereg("^([0-9]+)([,\.])([0-9]+)([ENSOW]?)$",$deg,$regs) )
  {
    $res = floatval($regs[1].".".$regs[3]);
70

Feu's avatar
Feu committed
71 72
    if ( $regs[4] == "O" || $regs[4] == "S" || $regs[4] == "W" )
      return -1*$res;
73

Feu's avatar
Feu committed
74 75
    return $res;
  }
Ayolo's avatar
Ayolo committed
76 77 78 79
  return NULL;
}


80
?>