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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| <?php
header('Content-type: text/html; charset=utf-8');
require("config.php");
require("configNA.php");
function getDistance($ori_lat,$ori_lon,$des_lat,$des_lon) {
$a = sin(($des_lat - $ori_lat)/2) * sin(($des_lat - $ori_lat)/2) + cos(($ori_lat)) * cos(($des_lat)) * sin(($des_lon - $ori_lon)/2) * sin(($des_lon - $ori_lon)/2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return number_format((6371 * $c), 10); //6371 = rayon de la terre
}
$lat=45.544012;
$lon=-73.552372;
$lat=45.44912;
$lon=-73.308721;
$lat=45.517557;
$lon=-73.515651;
$lonPlus=$lon+1;
$lonMoins=$lon-1;
$latPlus=$lat+1;
$latMoins=$lat-1;
$daoBase=new DaoBase();
$cod_pos='';
$tabZipCoord=array();
//lon+1
$psql='select cod_pos,lat,lon from cod_pos where lon<'.$lonPlus.' and lon>'.$lon.' order by lon asc limit 0,500';
$daoBase->execute($psql,'read');
echo '<h1>'.$psql.'</h1>';
if ($daoBase->numRows()<=0)
{
echo 'No ZipCod found ['.$daoBase->numRows().']';
die;
}
echo $daoBase->numRows().' zip_cod found<br />';
while($row = $daoBase->getArray()) {
// print_r($row);
// echo '<br />';
$cod_pos.='"'.$row['cod_pos'].'",';
}
$cod_pos = substr($cod_pos,0, -1);
//lon +1
$psql='select cod_pos,lat,lon from cod_pos where lon>'.$lonMoins.' and lon<'.$lon.' order by lon desc limit 0,500';
$daoBase->execute($psql,'read');
echo '<h1>'.$psql.'</h1>';
if ($daoBase->numRows()<=0)
{
echo 'No ZipCod found ['.$daoBase->numRows().']';
die;
}
echo $daoBase->numRows().' zip_cod found<br />';
while($row = $daoBase->getArray()) {
// print_r($row);
// echo '<br />';
$cod_pos.='"'.$row['cod_pos'].'",';
}
$cod_pos = substr($cod_pos,0, -1);
echo $cod_pos;
//lat +1
$psql='select cod_pos,lat,lon from cod_pos where lat<'.$latPlus.' and lat>'.$lat.' and cod_pos in ('.$cod_pos.') order by lat asc limit 0,10';
$daoBase->execute($psql,'read');
echo '<h1>'.$psql.'</h1>';
if ($daoBase->numRows()<=0)
{
echo 'No ZipCod found ['.$daoBase->numRows().']';
die;
}
echo $daoBase->numRows().' zip_cod found<br />';
$i=0;
while($row = $daoBase->getArray()) {
print_r($row);
echo '<br />';
$tabZipCoord[$i]['cod_pos']=$row['cod_pos'];
$tabZipCoord[$i]['lon_rad']=3.141592653 * ($row['lon']/180);
$tabZipCoord[$i]['lat_rad']=3.141592653 * ($row['lat']/180);
$i++;
}
//lat -1
$psql='select cod_pos,lat,lon from cod_pos where lat>'.$latMoins.' and lat<'.$lat.' and cod_pos in ('.$cod_pos.') order by lat desc limit 0,10';
$daoBase->execute($psql,'read');
echo '<h1>'.$psql.'</h1>';
if ($daoBase->numRows()<=0)
{
echo 'No ZipCod found ['.$daoBase->numRows().']';
die;
}
echo $daoBase->numRows().' zip_cod found<br />';
$cod_pos='';
while($row = $daoBase->getArray()) {
print_r($row);
echo '<br />';
$tabZipCoord[$i]['cod_pos']=$row['cod_pos'];
$tabZipCoord[$i]['lon_rad']=3.141592653 * ($row['lon']/180);
$tabZipCoord[$i]['lat_rad']=3.141592653 * ($row['lat']/180);
$i++;
}
echo '<h1>Final Tab</h1>';
//Get good cod_pos
print_r($tabZipCoord);
$lon_rad=3.141592653 * ($lon/180);
$lat_rad=3.141592653 * ($lat/180);
$tabFinal=array();
for ($j=0;$j<$i;$j++){
$tabFinal[$tabZipCoord[$j]['cod_pos']]=getDistance($lat_rad, $lon_rad, $tabZipCoord[$j]['lat_rad'], $tabZipCoord[$j]['lon_rad']);
}
echo '<h1>Tableaux de distances</h1>';
print_r($tabFinal);
$tabSave=array_flip($tabFinal);
echo '<h1>Tableaux de distances TRIE</h1>';
sort($tabFinal,SORT_NUMERIC);
print_r($tabFinal);
print_r($tabSave);
echo '<h1> Code postal final : '.$tabSave[$tabFinal[0]].'</h1>';
?> |
Partager