PHP Classes
elePHPant
Icontem

File: tools/ll_conv.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Pierre FAUQUE  >  Genealogy Classes  >  tools/ll_conv.php  >  Download  
File: tools/ll_conv.php
Role: Auxiliary script
Content type: text/plain
Description: Tool: longitude/latitude conversions
Class: Genealogy Classes
Manage genealogy trees for a family
Author: By
Last change:
Date: 3 years ago
Size: 3,732 bytes
 

Contents

Class file image Download
<?php

// ll_conv.php (longitude/latitude conversions)
// Sexagesimal to decimal (and reverse) to store in the database
// 48 51' 15.29" N => 48.8542472222
// -124.54824759 => 124 32' 53.69" W

// Pierre FAUQUE 02-03/09/2009
// pierre@fauque.net


// --- Texts. can be translated -------
define(TXT_TITL, "Angle conversions. (sexagesimal &lt;==&gt; decimal)");
define(TXT_CONV, "Conversions");
define(TXT_CVRT, "Convert");
define(TXT_LONG, "Longitude");
define(TXT_LATI, "Latitude");
define(TXT_LATN, "North latitude");
define(TXT_LATS, "South latitude");
define(TXT_LONE, "Est longitude");
define(TXT_LONW, "West longitude");
define(TXT_NOTA, "NB: Decimal separator is a dot, not a comma");
// ------------------------------------
?>

<html>

<head>
<title><?php echo TXT_TITL; ?></title>
</head>

<body>
<?php
if($_POST['submit']) {

   
// --- sexagesimal to decimal
   
if($_POST['conv'] == 'sexdec') {
        switch(
$_POST['where']) {
            case
'E' : $coef = 1; break;
            case
'N' : $coef = 1; break;
            case
'W' : $coef = -1; break;
            case
'S' : $coef = -1; break;
        }
        if(
$_POST['sec']) { $nbsec = $_POST['sec']; } else { $nbsec = 0; }
        if(
$_POST['min']) { $nbmin = $_POST['min']; } else { $nbmin = 0; }
       
$deg_in = $_POST['deg'].'&deg; '.$nbmin.'\' '.$nbsec.'" '.$_POST['where'];
       
$deg_out = ($_POST['deg']+((($nbmin*60)+$nbsec)/3600))*$coef;
       
$resultat = $deg_in.' ==&gt; '.$deg_out."<hr>\n";
    }

   
// --- decimal to sexagesimal
   
if($_POST['conv'] == 'decsex') {
       
$coords = $_POST['coords'];
       
$deg_in = $coords;
        if(
$_POST['where'] == 'lat') {
            if(
$coords >= 0) { $pc = 'N'; } else { $pc = 'S'; $coords *= -1; } }
        else {
            if(
$coords >= 0) { $pc = 'E'; } else { $pc = 'W'; $coords *= -1; }
        }
       
$deg = floor($coords);
       
$nbsec = ($coords-$deg)*3600;
       
$min = floor($nbsec/60);
       
$sec = round($nbsec-($min*60),2);
        if(
$sec == 60) { $sec = 0; $min +=1; }
        if(
$min == 60) { $min = 0; $deg +=1; }
       
$deg_out = $deg.'&deg; '.$min.'\' '.$sec.'" '.$pc;
       
$resultat = $deg_in.' ==&gt; '.$deg_out."<hr>\n";
    }
}
echo
$resultat;
?>

<!-- sexagesimal to decimal -->
<form name='sexdec' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
   <table border='0'>
      <tr>
         <td width='400'>
            Deg: <input type='text' name='deg' size='3'>
            Min: <input type='text' name='min' size='3'>
            Sec: <input type='text' name='sec' size='3'> &nbsp; &nbsp; &nbsp;
            <select name='where'>
               <option value='N'><?php echo TXT_LATN; ?>
<option value='S'><?php echo TXT_LATS; ?>
<option value='E'><?php echo TXT_LONE; ?>
<option value='W'><?php echo TXT_LONW; ?>
</select>
            <input type='hidden' name='conv' value='sexdec'>
         </td><td>
            <input type='submit' name='submit' value='<?php echo TXT_CVRT; ?>'>
         </td>
      </tr>
   </table>
</form>

<!-- decimal to sexagesimal -->
<form name='decsex' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
   <table border='0'>
      <tr>
         <td width='400'>
            Deg (dec.): <input type='text' name='coords' size='23'> &nbsp; &nbsp; &nbsp;
            <select name='where'>
               <option value='lat'><?php echo TXT_LATI; ?>
<option value='lon'><?php echo TXT_LONG; ?>
</select>
            <input type='hidden' name='conv' value='decsex'>
         </td><td>
            <input type='submit' name='submit' value='<?php echo TXT_CVRT; ?>'>
         </td>
      </tr>
   </table>
</form>
<span style='color:#909090'><?php echo TXT_NOTA; ?></span>
</body>

</html>