2013-11-05 11:18:30 +00:00
< ? php
if ( ! function_exists ( 'htmlspecialchars_decode' ) )
{
function htmlspecialchars_decode ( $text )
{
return strtr ( $text , array_flip ( get_html_translation_table ( HTML_SPECIALCHARS )));
}
}
require_once 'framework/common/curl.php' ;
function supprDecimales ( $dec ) {
if ( $dec > 0 )
return floor ( $dec );
else
return ceil ( $dec );
}
function dec2dms ( $dec ) {
$d = supprDecimales ( $dec );
$m = supprDecimales (( $dec - $d ) * 60 );
$s = abs ( round (((( $dec - $d ) * 60 ) - $m ) * 60 ));
$m = abs ( $m );
return $d . '°' . $m . " ' " . $s . '"' ;
}
/**/
function ALG0001 ( $phi , $e ) {
$temp = ( 1 - ( $e * sin ( $phi ) ) ) / ( 1 + ( $e * sin ( $phi ) ) );
$L = log ( tan ( ( pi () / 4 ) + ( $phi / 2 ) ) * pow ( $temp , ( $e / 2 ) ));
return $L ;
}
/** Calcul de la latitude à partir de la latitude isométrique
**/
function ALG0002 ( $L , $e , $epsilon ) {
$phi [ 0 ] = 2 * atan ( exp ( $L )) - ( pi () / 2 );
$i = 0 ;
do {
$i ++ ;
$temp = ( 1 + ( $e * sin ( $phi [ $i - 1 ] ) ) ) / ( 1 - ( $e * sin ( $phi [ $i - 1 ] ) ) );
$phi [ $i ] = 2 * atan ( pow ( $temp , ( $e / 2 )) * exp ( $L ) ) - pi () / 2 ;
}
while ( abs ( $phi [ $i ] - $phi [ $i - 1 ]) >= $epsilon );
return $phi [ $i ];
}
/** Transformation de coordonnées en projection conique conforme de Lambert , en coordonnées géographiques
** @ param double $X Coordonnée X en projection conique conforme de Lambert du point
** @ param double $Y Coordonnée Y en projection conique conforme de Lambert du point
** @ param double $n Exposant de la projection
** @ param double $c Constante de la projection
** @ param double $Xs Coordonnée Xs en projection du pôle
** @ param double $Ys Coordonnée Ys en projection du pôle
** @ param double $lambdac Longitude de l ' origine par rapport au méridien origine
** @ param double $e Première excentricité de l ' ellipsoïde
** @ param double $epsilon Tolérance de convergence
** @ return array lambda Longitude par rapport au méridien origine
** phi Latitude
**/
function ALG0004 ( $X , $Y , $n , $c , $Xs , $Ys , $lambdac , $e , $epsilon ) {
$R = sqrt ( pow (( $X - $Xs ), 2 ) + pow (( $Y - $Ys ), 2 ) );
$gamma = atan (( $X - $Xs ) / ( $Ys - $Y ));
$lambda = $lambdac + ( $gamma / $n );
$L = ( - 1 / $n ) * log ( abs ( $R / $c ));
$phi = ALG0002 ( $L , $e , $epsilon );
$coords [ 'lambda' ] = $lambda ;
$coords [ 'phi' ] = $phi ;
return $coords ;
}
/** Transformation des coordonnées géographiques ellipsoïdales en coordonnées cartésiennes
**
**/
function ALG0009 ( $lambda , $phi , $he , $a , $e ) {
$N = ALG0021 ( $phi , $a , $e );
$X = ( $N + $he ) * cos ( $phi ) * cos ( $lambda );
$Y = ( $N + $he ) * cos ( $phi ) * sin ( $lambda );
$Z = ( $N * ( 1 - $e * $e ) + $he ) * sin ( $phi );
$coords [ 'X' ] = $X ;
$coords [ 'Y' ] = $Y ;
$coords [ 'Z' ] = $Z ;
return $coords ;
}
/**/
function ALG0012 ( $X , $Y , $Z , $a , $e , $epsilon ) {
$lambda = atan ( $Y / $X );
$P = sqrt ( $X * $X + $Y * $Y );
$phi [ 0 ] = atan ( $Z / ( $P * ( 1 - ( ( $a * $e * $e ) / sqrt ( $X * $X + $Y * $Y + $Z * $Z ) ) ) ) );
$i = 0 ;
do
{
$i ++ ;
$temp = pow (( 1 - ( $a * $e * $e * cos ( $phi [ $i - 1 ] ) / ( $P * sqrt ( 1 - $e * $e * sin ( $phi [ $i - 1 ]) * sin ( $phi [ $i - 1 ]))))), - 1 );
$phi [ $i ] = atan ( $temp * $Z / $P );
}
while ( abs ( $phi [ $i ] - $phi [ $i - 1 ]) >= $epsilon );
$phix = $phi [ $i ];
$he = ( $P / cos ( $phix )) - ( $a / sqrt ( 1 - $e * $e * sin ( $phix ) * sin ( $phix )));
$coords [ 'lambda' ] = $lambda ;
$coords [ 'phi' ] = $phix ;
$coords [ 'he' ] = $he ;
return $coords ;
}
/** Transformation d ' un jeu de 7 paramètres entre 2 systèmes géodésiques
** @ param double $Tx Translation suivant l ' axe des X ( de 1 vers 2 )
** @ param double $Ty Translation suivant l ' axe des Y ( de 1 vers 2 )
** @ param double $Tz Translation suivant l ' axe des Z ( de 1 vers 2 )
** @ param double $D Facteur d ' échelle de 1 vers 2
** @ param double $Rx Angle de rotation autour de l ' axe des X en radian ( de 1 vers 2 )
** @ param double $Ry Angle de rotation autour de l ' axe des Y en radian ( de 1 vers 2 )
** @ param double $Rz Angle de rotation autour de l ' axe des Z en radian ( de 1 vers 2 )
** @ param double $U Vecteur de coordonnées cartésiennes tridimensionnelles dans le système 1 : U = ( Ux , Uy , Uz )
** @ return array Vecteur de coordonnées cartésiennes tridimensionnelles dans le système 2 , V = ( Vx , Vy , Vz )
*/
function ALG0013 ( $Tx , $Ty , $Tz , $D , $Rx , $Ry , $Rz , $U ) {
$V = array ();
$V [ 'X' ] = $Tx + $U [ 'X' ] * ( 1 + $D ) + $U [ 'Z' ] * $Ry - $U [ 'Y' ] * $Rz ;
$V [ 'Y' ] = $Ty + $U [ 'Y' ] * ( 1 + $D ) + $U [ 'X' ] * $Rz - $U [ 'Z' ] * $Rx ;
$V [ 'Z' ] = $Tz + $U [ 'Z' ] * ( 1 + $D ) + $U [ 'Y' ] * $Rx - $U [ 'X' ] * $Ry ;
return $V ;
}
/** Détermination des paramètres de calcul d ' une projection Lambert conique
** dans le cas tangent , avec ou sans facteur d ' échelle en fonction des paramètres de définition usuels
** @ return array n , C , lambdac , Xs , Ys
**/
function ALG0019 ( $lambda0 , $phi0 , $k0 , $X0 , $Y0 , $a , $e ) {
$lambdac = $lambda0 ;
$n = sin ( $phi0 );
$C = $k0 * ALG0021 ( $phi0 , $a , $e ) * tan ( pi () / 2 - $phi0 ) * exp ( $n * ALG0001 ( $phi0 , $e ) );
$Xs = $X0 ;
$Ys = $Y0 + $k0 * ALG0021 ( $phi0 , $a , $e ) * tan ( pi () / 2 - $phi0 ) ;
$tab [ 'e' ] = $e ;
$tab [ 'n' ] = $n ;
$tab [ 'C' ] = $C ;
$tab [ 'lambdac' ] = $lambdac ;
$tab [ 'Xs' ] = $Xs ;
$tab [ 'Ys' ] = $Ys ;
return $tab ;
}
/** Calcul de la grande normale de l ' ellipsoïde
** @ param double $phi Latitude
** @ param double $a Demi - grand axe de l ' ellipsoïde
** @ param double $e Première excentricité de l ' ellipsoïde
** @ return double
**/
function ALG0021 ( $phi , $a , $e ) {
$N = $a / sqrt ( 1 - $e * $e * sin ( $phi ) * sin ( $phi ) );
return $N ;
}
/** Calcul des constantes d ' une projection Lambert conique conforme dans le cas sécant
** @ param double $lambda0 Longitude origine en radian par rapport au méridien origine
** @ param double $phi0 Latitude origine
** @ param double $X0 Coordonnée X en projection du point origine
** @ param double $Y0 Coordonnée Y en projection du point origine
** @ param double $phi1 Latitude en radian du 1 er parallèle automécoïque
** @ param double $phi2 Latitude en radian du 2 ème parallèle automécoïque
** @ param double $a Demi - grand axe de l ' ellipsoïde
** @ param double $e Première excentricité de l ' ellipsoïde
** @ return array n , C , lambdac , Xs , Ys
**/
function ALG0054 ( $lambda0 , $phi0 , $X0 , $Y0 , $phi1 , $phi2 , $a , $e ) {
$lambdac = $lambda0 ;
$n = ( ( log ( ( ALG0021 ( $phi2 , $a , $e ) * cos ( $phi2 )) / ( ALG0021 ( $phi1 , $a , $e ) * cos ( $phi1 )) )) / ( ALG0001 ( $phi1 , $e ) - ALG0001 ( $phi2 , $e ) ));
$C = (( ALG0021 ( $phi1 , $a , $e ) * cos ( $phi1 )) / $n ) * exp ( $n * ALG0001 ( $phi1 , $e ));
if ( $phi0 == ( pi () / 2 )) {
$Xs = $X0 ;
$Ys = $Y0 ;
} else {
$Xs = $X0 ;
$Ys = $Y0 + $C * exp ( - 1 * $n * ALG0001 ( $phi0 , $e ));
}
$tab = array ( 'e' => $e ,
'n' => $n ,
'C' => $C ,
'lambdac' => $lambdac ,
'Xs' => $Xs ,
'Ys' => $Ys );
return $tab ;
}
function Lambert2WGS84 ( $X , $Y , $orig = 'L93' ) {
$epsilon = 0.00000000001 ;
$lambdac = 0.04079234433 ; // pour greenwich
$e = 0.08248325676 ; // première excentricité de l ellipsoïde Clarke 1880 français
$he = 100 ;
$a = 6378249.2 ; // demi-grand axe de l'ellipsoide
$Tx = - 168 ;
$Ty = - 60 ;
$Tz = + 320 ;
$D = 0 ;
$Rx = $Ry = $Rz = 0 ;
$orig = strtoupper ( $orig );
switch ( $orig ) {
case 'LI' :
case 'L1' : $n = 0.7604059656 ;
$c = 11603796.98 ;
$Xs = 600000 ;
$Ys = 5657616.674 ;
break ;
case 'LII' :
case 'LIIE' :
case 'L2E' :
case 'L2' : $n = 0.7289686274 ;
$c = 11745793.39 ;
$Xs = 600000 ;
if ( $orig == 'L2E' || $orig == 'LIIE' )
$Ys = 8199695.768 ;
else $Ys = 6199695.768 ;
break ;
case 'LIII' :
case 'L3' : $n = 0.6959127966 ;
$c = 11947992.52 ;
$Xs = 600000 ;
$Ys = 6791905.085 ;
break ;
case 'LIV' :
case 'L4' : $n = 0.6712679322 ;
$c = 12136281.99 ;
$Xs = 234.358 ;
$Ys = 7239161.542 ;
break ;
case 'L93' :
default : $n = 0.7256077650 ;
$c = 11745255.426 ;
$Xs = 700000 ;
$Ys = 12655612.050 ;
break ;
}
$coords = ALG0004 ( $X , $Y , $n , $c , $Xs , $Ys , $lambdac , $e , $epsilon );
$coords = ALG0009 ( $coords [ 'lambda' ], $coords [ 'phi' ], $he , $a , $e );
$coords = ALG0013 ( $Tx , $Ty , $Tz , $D , $Rx , $Ry , $Rz , $coords );
$a = 6378137.0 ; // ellipsoïdes WGS84
$f = 1 / 298.257223563 ;
$b = $a * ( 1 - $f );
$e = sqrt (( $a * $a - $b * $b ) / ( $a * $a ));
$X = $coords [ 'X' ];
$Y = $coords [ 'Y' ];
$Z = $coords [ 'Z' ];
$coords = ALG0012 ( $X , $Y , $Z , $a , $e , $epsilon );
$xy [ 'long' ] = rad2deg ( $coords [ 'lambda' ]);
$xy [ 'lat' ] = rad2deg ( $coords [ 'phi' ]);
return $xy ;
}
/**
* Function to convert geographic coordinates to " lambert 2 etendue " coordinates
* from : http :// www . forumsig . org / showthread . php ? p = 64050 #post64050
**/
function geos2lambert ( $latitude , $longitude ) {
//0)degres-minutes-secondes + orientation (d,m,s,o) en radian
$lambda_w = $longitude * pi () / 180 ;
$phi_w = $latitude * pi () / 180 ;
//1) coordonnées géographiques WGS84 (phi_w,lambda_w) en coordonnées cartésiennes WGS84 (X_w,Y_w,Z_w)
$a_w = 6378137.0 ;
$b_w = 6356752.314 ;
$e2_w = ( $a_w * $a_w - $b_w * $b_w ) / ( $a_w * $a_w );
//et on a la grande normale de l'ellipsoide WGS84
$N = $a_w / sqrt ( 1 - $e2_w * pow ( sin ( $phi_w ), 2 ));
//ainsi on obtient
$X_w = $N * cos ( $phi_w ) * cos ( $lambda_w );
$Y_w = $N * cos ( $phi_w ) * sin ( $lambda_w );
$Z_w = $N * ( 1 - $e2_w ) * sin ( $phi_w );
//Ref.: http://www.ign.fr/telechargement/MPr...RCE/NTG_80.pdf and http://de.wikipedia.org/wiki/WGS84
//2) coordonnées cartésiennes WGS84 (X_w,Y_w,Z_w) en coordonnées cartésiennes NTF (X_n,Y_n,Z_n)
$dX = 168.0 ;
$dY = 60.0 ;
$dZ = - 320.0 ;
$X_n = $X_w + $dX ;
$Y_n = $Y_w + $dY ;
$Z_n = $Z_w + $dZ ;
//ref.: http://support.esrifrance.fr/Documents/Generalites/Projections/Generalites/Generalites.htm#2
//3) coordonnées cartésiennes NTF (X_n,Y_n,Z_n) en coordonnées géographiques NTF (phi_n,lambda_n)
$a_n = 6378249.2 ;
$b_n = 6356515.0 ;
$e2_n = ( $a_n * $a_n - $b_n * $b_n ) / ( $a_n * $a_n );
//on définit une tolérance de convergence
$epsilon = pow ( 10 , - 10 );
//puis on amorce une boucle de calcul
$p0 = atan ( $Z_n / sqrt ( $X_n * $X_n + $Y_n * $Y_n ) * ( 1 - ( $a_n * $e2_n ) / ( sqrt ( $X_n * $X_n + $Y_n * $Y_n + $Z_n * $Z_n ))));
$p1 = atan (( $Z_n / sqrt ( $X_n * $X_n + $Y_n * $Y_n )) / ( 1 - ( $a_n * $e2_n * cos ( $p0 )) / ( sqrt (( $X_n * $X_n + $Y_n * $Y_n ) * ( 1 - $e2_n * pow ( sin ( $p0 ), 2 ))))));
while ( ! ( abs ( $p1 - $p0 ) < $epsilon )){
$p0 = $p1 ;
$p1 = atan (( $Z_n / sqrt ( $X_n * $X_n + $Y_n * $Y_n )) / ( 1 - ( $a_n * $e2_n * cos ( $p0 )) / ( sqrt (( $X_n * $X_n + $Y_n * $Y_n ) * ( 1 - $e2_n * pow ( sin ( $p0 ), 2 ))))));
}
$phi_n = $p1 ;
$lambda_n = atan ( $Y_n / $X_n );
//4) coordonnées géographiques NTF (phi_n,lambda_n) en coordonnées projetées en Lambert II étendu (X_l2e, Y_l2e)
$n = 0.7289686274 ;
$c = 11745793.39 ;
$Xs = 600000.0 ;
$Ys = 8199695.768 ;
$e_n = sqrt ( $e2_n );
$lambda0 = 0.04079234433198 ; //correspond à la longitude en radian de Paris (2°20'14.025" E) par rapport à Greenwich
//puis on calcule la latitude isométrique
$L = log ( tan ( pi () / 4 + $phi_n / 2 ) * pow ((( 1 - $e_n * sin ( $phi_n )) / ( 1 + $e_n * sin ( $phi_n ))),( $e_n / 2 )));
//enfin on projette
$X_l2e = $Xs + $c * exp (( - $n * $L )) * sin ( $n * ( $lambda_n - $lambda0 ));
$Y_l2e = $Ys - $c * exp (( - $n * $L )) * cos ( $n * ( $lambda_n - $lambda0 ));
return array ( " x_l2e " => $X_l2e , " y_l2e " => $Y_l2e );
}
/** Conversion WGS84 en Lambert93
** NTG_71 . pdf
** http :// www . ign . fr / affiche_rubrique . asp ? rbr_id = 1700 & lng_id = FR
**/
function geos2lambert93 ( $latitude , $longitude ) {
// Système WGS84
$a = 6378137 ; // demi grand axe de l'ellipsoide (m)
$e = 0.08181919106 ; // première excentricitè de l'ellipsoide
// Paramètres de projections
$l0 = $lc = deg2rad ( 3 ); // longitude de référence
$phi0 = deg2rad ( 46.5 ); // latitude d'origine en radian
$phi1 = deg2rad ( 44 ); // 1er parallele automécoïque
$phi2 = deg2rad ( 49 ); // 2eme parallele automécoïque
$x0 = 700000 ; //coordonnées à l'origine
$y0 = 6600000 ; //coordonnées à l'origine
// coordonnées du point à traduire
$phi = deg2rad ( $latitude );
$l = deg2rad ( $longitude );
// calcul des grandes normales
$gN1 = $a / sqrt ( 1 - $e * $e * sin ( $phi1 ) * sin ( $phi1 ));
$gN2 = $a / sqrt ( 1 - $e * $e * sin ( $phi2 ) * sin ( $phi2 ));
//calculs de slatitudes isométriques
$gl1 = log ( tan ( pi () / 4 + $phi1 / 2 ) * pow (( 1 - $e * sin ( $phi1 )) / ( 1 + $e * sin ( $phi1 )), $e / 2 ));
$gl2 = log ( tan ( pi () / 4 + $phi2 / 2 ) * pow (( 1 - $e * sin ( $phi2 )) / ( 1 + $e * sin ( $phi2 )), $e / 2 ));
$gl0 = log ( tan ( pi () / 4 + $phi0 / 2 ) * pow (( 1 - $e * sin ( $phi0 )) / ( 1 + $e * sin ( $phi0 )), $e / 2 ));
$gl = log ( tan ( pi () / 4 + $phi / 2 ) * pow (( 1 - $e * sin ( $phi )) / ( 1 + $e * sin ( $phi )), $e / 2 ));
//calcul de l'exposant de la projection
$n = ( log (( $gN2 * cos ( $phi2 )) / ( $gN1 * cos ( $phi1 )))) / ( $gl1 - $gl2 ); //ok
//calcul de la constante de projection
$c = (( $gN1 * cos ( $phi1 )) / $n ) * exp ( $n * $gl1 ); //ok
//calcul des coordonnées
$ys = $y0 + $c * exp ( - 1 * $n * $gl0 );
//calcul des coordonnées lambert
$x93 = $x0 + $c * exp ( - 1 * $n * $gl ) * sin ( $n * ( $l - $lc ));
$y93 = $ys - $c * exp ( - 1 * $n * $gl ) * cos ( $n * ( $l - $lc ));
return array ( " x_93 " => $x93 , " y_93 " => $y93 );
}
//http://www.ign.fr/telechargement/MPro/geodesie/CIRCE/transfo.pdf
//http://www.ign.fr/telechargement/MPro/geodesie/CIRCE/NTG_80.pdf
//http://www.ign.fr/telechargement/MPro/geodesie/CIRCE/NTG_71.pdf
/**
print_r ( Lambert2WGS84 ( 591647.56 , 2426659.65 ));
print_r ( geos2lambert ( 48.838245134184 , 2.2227849815878 ));
**/
/** The point - in - polygon algorythm allows you to programmatically check if a particular point is inside a polygon or outside of it . A common way to tackle the problem is to count how many times a line drawn from the point ( in any direction ) intersects with the polygon boundary . If they intersect an even number of times , then the point is outside .
I used that approach in this PHP code , which doesn 't contain detailed comments yet. A few people asked if I could post it anyway, so there it is... I' ll try to add some more comment as soon as I have some spare time .
The returned values are :
" vertex " if the point sits exactly on a vertex AND you left true as the value for $pointOnVertex .
" boundary " if the point sits on the boundary . If $pointOnVertex is false , then " boundary " is also returned if the point is on a vertex .
" inside " if the point is inside the polygon .
" outside " if , you guessed it , the point is outside of the polygon .
*/
class pointLocation {
var $pointOnVertex = true ; // Check if the point sits exactly on one of the vertices
function pointLocation () {
}
function pointInPolygon ( $point , $polygon , $pointOnVertex = true ) {
$this -> pointOnVertex = $pointOnVertex ;
// Transform string coordinates into arrays with x and y values
$point = $this -> pointStringToCoordinates ( $point );
$vertices = array ();
foreach ( $polygon as $vertex ) {
$vertices [] = $this -> pointStringToCoordinates ( $vertex );
}
//print_r($vertices);
//die();
// Check if the point sits exactly on a vertex
if ( $this -> pointOnVertex == true && $this -> pointOnVertex ( $point , $vertices ) == true ) {
return " vertex " ;
}
// Check if the point is inside the polygon or on the boundary
$intersections = 0 ;
$vertices_count = count ( $vertices );
echo " vertices_count= $vertices_count " . EOL ;
for ( $i = 1 ; $i < $vertices_count ; $i ++ ) {
$vertex1 = $vertices [ $i - 1 ];
$vertex2 = $vertices [ $i ];
if ( $vertex1 [ 'y' ] == $vertex2 [ 'y' ] && $vertex1 [ 'y' ] == $point [ 'y' ] && $point [ 'x' ] > min ( $vertex1 [ 'x' ], $vertex2 [ 'x' ]) && $point [ 'x' ] < max ( $vertex1 [ 'x' ], $vertex2 [ 'x' ])) {
// Check if point is on an horizontal polygon boundary
return " boundary " ;
}
if ( $point [ 'y' ] > min ( $vertex1 [ 'y' ], $vertex2 [ 'y' ]) && $point [ 'y' ] <= max ( $vertex1 [ 'y' ], $vertex2 [ 'y' ]) && $point [ 'x' ] <= max ( $vertex1 [ 'x' ], $vertex2 [ 'x' ]) && $vertex1 [ 'y' ] != $vertex2 [ 'y' ]) {
$xinters = ( $point [ 'y' ] - $vertex1 [ 'y' ]) * ( $vertex2 [ 'x' ] - $vertex1 [ 'x' ]) / ( $vertex2 [ 'y' ] - $vertex1 [ 'y' ]) + $vertex1 [ 'x' ];
if ( $xinters == $point [ 'x' ]) {
// Check if point is on the polygon boundary (other than horizontal)
return " boundary " ;
}
if ( $vertex1 [ 'x' ] == $vertex2 [ 'x' ] || $point [ 'x' ] <= $xinters ) {
$intersections ++ ;
}
}
}
// If the number of edges we passed through is even, then it's in the polygon.
echo " intersections= $intersections " . EOL ;
if ( $intersections % 2 != 0 ) {
return " inside " ;
} else {
return " outside " ;
}
}
function pointOnVertex ( $point , $vertices ) {
foreach ( $vertices as $vertex ) {
if ( $point == $vertex ) {
return true ;
}
}
}
function pointStringToCoordinates ( $pointString ) {
$coordinates = explode ( ' ' , $pointString );
return array ( 'x' => $coordinates [ 0 ], 'y' => $coordinates [ 1 ]);
}
}
class MMap {
2014-06-02 08:41:24 +00:00
protected $iDb ;
2013-11-05 11:18:30 +00:00
private $accesDist = true ;
private $referer = '' ;
private $body = '' ;
private $header = '' ;
private $cookie = '' ;
private $codeRetour = 0 ;
public $codeRetourG = 0 ; // Code retour de l'api Google
public $codeRetourY = 0 ; // Code retour de l'api Yahoo
public $codeRetourM = 0 ; // Code retour de l'api Mappy
public $codeRetourC = 0 ; // Code retour de l'api Cloudmade
public $geocodeur = '' ;
public $latitudeDec = 0 ; // Latitude en Décimal
public $latitudeDeg = 0 ; // Latitude en Dégrés
public $longitudeDec = 0 ; // Longitude en Décimal
public $longitudeDeg = 0 ; // Longitude en Dégrés
public $altitude = NULL ; // Altitude en mètres
public $l93x = NULL ; // Lambert 93, coordonnée X
public $l93y = NULL ; // Lambert 93, coordonnée Y
public $precision = 0 ;
public $adresseValidee = '' ;
public $enCache = false ;
2014-05-29 20:10:26 +00:00
// private $apiKeyG='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw';
private $apiKeyG = 'AIzaSyBfyIMaVwm1nn8AupBf-asC816R71LZl8g' ;
2013-11-05 11:18:30 +00:00
// private $apiKey='ABQIAAAAuKBtUyFonYJBl1fqfc78tRT4Qe_2x2fax4Crd4sBzQI-tDkl3BRm2l2feTV5Lnx0Ah-aTIlwHtglpA';
private $apiKeyY = 'klII0gzV34Ho2TCsN3XiXeh4No033AifxMeDXfFXj8TDCXO3WAtOLj9c74VsV45HcII-' ;
private $apiKeyC = 'ae5216123e414fcd84b8ca9a0f43a68c' ;
2014-06-17 07:54:38 +00:00
public function __construct ( $accesDist = true , $db = null )
2014-06-02 08:41:24 +00:00
{
if ( $db === null ) {
$this -> iDb = new WDB ();
} else {
$this -> iDb = $db ;
}
2013-11-05 11:18:30 +00:00
$this -> accesDist = $accesDist ;
}
2014-06-17 07:54:38 +00:00
/*
http :// platform . beta . mapquest . com / geocoding / v1 / address ? key = YOUR_KEY_HERE & location = Lancaster , PA & callback = renderGeocode
http :// platform . beta . mapquest . com / geocoding / v1 / address ? key = YOUR_KEY_HERE & callback = renderOptions & inFormat = kvp & outFormat = json & location = 77 rue lost al lann , 29000 quimper , france
Client ID : 83955
Email Address : buzuk77 @ aim . com
Registry Password : tU2cA4qV
Forums User Name :
JS / AS3 Key : Fmjtd % 7 Clu61nuuzlu % 2 Cr0 % 3 Do5 - 5 a1sd
*/
/*
GeoCodingHandler . ashx ? addr =
< wsdl : import namespace = " http://dev.virtualearth.net/webservices/v1/imagery/contracts " location = " http://dev.virtualearth.net/webservices/v1/metadata/imageryservice/imageryservice1.wsdl " />
API keybing = 56 D6CBA671C986D3EA11B1B48F97507BE9B46999
*/
2014-06-02 08:41:24 +00:00
public function geoCodeAdrCpVilleM ( $adresse , $cp , $ville , $pays = '' )
{
2013-11-05 11:18:30 +00:00
if ( $pays == '' ) $pays = 'France' ;
if ( preg_match ( '/^([0-9]{1,4} )(.*)$/' , $adresse , $matches )) {
$adresseVoie = trim ( $matches [ 2 ]);
$adresseNum = trim ( $matches [ 1 ]);
} else {
$adresseVoie = trim ( $adresse );
$adresseNum = '' ;
}
$url = 'http://axe.mappy.com/services/loc/get.aspx?countryName=' . urlencode ( $pays ) . '&townName=' . urlencode ( $ville ) . '&wayName=' . urlencode ( $adresseVoie ) . '&number=' . urlencode ( $adresseNum ) . '&namedPlaceSearch=0&interactive=1&auth=maiaTest&format=json' ;
$page = getUrl ( $url , '' , '' , '' , false , '' , '' , 3 );
$res = json_decode ( $page [ 'body' ]);
$result = $res -> geocode -> answer ;
//print_r($page);
//print_r($result);die($url);
//$this->codeRetourM=
switch ( $result -> geocode_level -> code ) {
case 0 : $this -> precision = 0 ; break ; // No geocoding
case 1 : $this -> precision = 1 ; break ; // Country level geocoding
case 2 : $this -> precision = 4 ; break ; // Town level geocoding
case 3 : $this -> precision = 6 ; break ; // Way level geocoding
case 4 : $this -> precision = 8 ; break ; // Road element level geocoding
2014-05-29 20:10:26 +00:00
default : /*die('Precisions Inconnue : "'.$result->geocode_level->code.'"='.$result->geocode_level->label.EOL.$page['body']);*/ break ;
2013-11-05 11:18:30 +00:00
}
$this -> adresseValidee =@ preg_replace ( '/ +/' , ' ' , strtoupper ( str_replace ( ''' , " ' " , trim ( htmlspecialchars_decode ( $result -> road_element -> number . ' ' . $result -> way -> name , ENT_QUOTES )))));
$this -> codeRetourM =@ $result -> global_score ;
/*
$result -> postal_code -> postal_code
$result -> subcountry -> iso_code // 11
$result -> subcountry -> language
$result -> subcountry -> Ile - de - France
$result -> town -> language ] => FRE
$result -> town -> name ] => Nanterre
$result -> town -> official_code ] => 92050
$result -> town -> postal_codes -> postal_code ] => 92000
*/
/*
2014-06-17 07:54:38 +00:00
0 Unknown location . ( Since 2.59 )
1 Country level accuracy . ( Since 2.59 )
2 Region ( state , province , prefecture , etc . ) level accuracy . ( Since 2.59 )
3 Sub - region ( county , municipality , etc . ) level accuracy . ( Since 2.59 )
4 Town ( city , village ) level accuracy . ( Since 2.59 )
5 Post code ( zip code ) level accuracy . ( Since 2.59 )
6 Street level accuracy . ( Since 2.59 )
7 Intersection level accuracy . ( Since 2.59 )
8 Address level accuracy . ( Since 2.59 )
*/
2013-11-05 11:18:30 +00:00
$this -> latitudeDec =@ $result -> location -> coordinates -> y ;
$this -> longitudeDec =@ $result -> location -> coordinates -> x ;
$this -> latitudeDeg = dec2dms ( $this -> latitudeDec );
$this -> longitudeDeg = dec2dms ( $this -> longitudeDec );
$this -> geocodeur = 'Mappy' ;
//if ($this->codeRetourM>0)
return true ;
return false ;
}
public function geoCodeAdrCpVilleC ( $adresse , $cp , $ville , $pays = '' ) {
$this -> geocodeur = 'Cloudmade' ;
$this -> precision = 0 ;
2014-05-06 11:53:53 +00:00
$fileName = LOG_PATH . '/geoCodeur' . $this -> geocodeur . '.log' ;
2014-05-29 20:10:26 +00:00
$tmp =@ explode ( '|' , file_get_contents ( $fileName ));
$nbQuery =@ $tmp [ 1 ] * 1 ;
2013-11-05 11:18:30 +00:00
if ( $pays == '' ) $pays = 'France' ;
/* if ( preg_match ( '/^([0-9]{1,4} )(.*)$/' , $adresse , $matches )) {
$adresseVoie = trim ( $matches [ 2 ]);
$adresseNum = trim ( $matches [ 1 ]);
} else {
$adresseVoie = trim ( $adresse );
$adresseNum = '' ;
} */
$url = 'http://beta.geocoding.cloudmade.com/v3/' . $this -> apiKeyC . '/api/geo.location.search.2?format=json&source=OSM&enc=UTF-8&limit=10&locale=fr&q=' . urlencode ( " $adresse $cp $ville $pays " );
$page = getUrl ( $url , '' , '' , '' , false , '' , '' , 15 );
$this -> body = $page [ 'body' ];
$this -> codeRetour = $page [ 'code' ];
$this -> header = $page [ 'header' ];
2014-05-29 20:10:26 +00:00
$nbQuery ++ ;
file_put_contents ( $fileName , $this -> geocodeur . '|' . $nbQuery . '|' . $this -> codeRetour . " | $url | " . date ( 'Y-m-d H:i:s' ) . '|' . $this -> body . EOL );
2013-11-05 11:18:30 +00:00
$res =@ json_decode ( utf8_decode ( $page [ 'body' ]));
if ( $this -> codeRetour == 200 && $res -> status -> success == 1 ) {
$geoCodage = $res -> places [ 0 ];
$this -> codeRetourC = 1 ;
switch ( $geoCodage -> addressType ) {
case 'housenumber' : $this -> precision = 8 ; break ;
case 'street' : $this -> precision = 6 ; break ;
case 'zip' : $this -> precision = 5 ; break ;
2014-05-29 20:10:26 +00:00
case 'city' : $this -> precision = 4 ; break ;
case 'district' : $this -> precision = 3 ; break ;
case 'sight' : $this -> precision = 0 ; break ;
2013-11-05 11:18:30 +00:00
default :
//print_r($res);
//die('addressType inconnue : '.$geoCodage->addressType.EOL);
break ;
}
$this -> adresseValidee =@ trim ( strtoupper ( preg_replace ( '/\s+/' , ' ' , $geoCodage -> houseNumber . ' ' . $geoCodage -> street . ', ' .
$geoCodage -> zip . ' ' . $geoCodage -> city . ', ' . str_replace ( ',' , ' ' , $geoCodage -> country ))));
$this -> latitudeDec = $geoCodage -> position -> lat ;
$this -> longitudeDec = $geoCodage -> position -> lon ;
$this -> latitudeDeg = dec2dms ( $this -> latitudeDec );
$this -> longitudeDeg = dec2dms ( $this -> longitudeDec );
/* print_r ( $res );
echo $this -> adresseValidee . EOL ;
echo 'lat=' . $this -> latitudeDec . EOL ;
echo 'lon=' . $this -> longitudeDec . EOL ;
echo 'precis=' . $this -> precision . EOL ;
die ( $url ); */
2014-05-29 20:10:26 +00:00
if ( $this -> precision > 0 )
return true ;
2013-11-05 11:18:30 +00:00
}
//print_r($page);
//print_r($res);
//die($url);
return false ;
}
private function geoCodeAdrCpVilleY ( $address ) {
$this -> geocodeur = 'Yahoo' ;
$this -> precision = 0 ;
2014-05-06 11:53:53 +00:00
$fileName = LOG_PATH . '/geoCodeur' . $this -> geocodeur . '.log' ;
2014-05-29 20:10:26 +00:00
$tmp =@ explode ( '|' , file_get_contents ( $fileName ));
$nbQuery =@ $tmp [ 1 ] * 1 ;
2013-11-05 11:18:30 +00:00
2014-05-29 20:10:26 +00:00
$url = 'http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text%3D%22' . rawurlencode ( $address ) . '%22&format=xml' ;
2013-11-05 11:18:30 +00:00
$_result = false ;
2014-05-29 20:10:26 +00:00
$page = getUrl ( $url , '' , '' , '' , false , '' , '' , 3 );
2013-11-05 11:18:30 +00:00
$this -> body = $page [ 'body' ];
$this -> codeRetour = $page [ 'code' ];
$this -> header = $page [ 'header' ];
2014-05-29 20:10:26 +00:00
$nbQuery ++ ;
file_put_contents ( $fileName , $this -> geocodeur . '|' . $nbQuery . '|' . $this -> codeRetour . " | $url | " . date ( 'Y-m-d H:i:s' ) . '|' . $this -> body . EOL );
2013-11-05 11:18:30 +00:00
if ( $this -> codeRetour == 200 ) {
/* Réponse Yahoo = < ? xml version = " 1.0 " encoding = " UTF-8 " ?>
< query xmlns : yahoo = " http://www.yahooapis.com/v1/base.rng " yahoo : count = " 1 " yahoo : created = " 2013-09-25T13:52:43Z " yahoo : lang = " en-US " >< results >< Result >< quality > 71 </ quality >
< latitude > 45.782864 </ latitude >< longitude > 4.828002 </ longitude >< offsetlat > 45.782864 </ offsetlat >< offsetlon > 4.828002 </ offsetlon >< radius > 400 </ radius >
< name />< line1 > Rue Jacques Louis - Henon </ line1 >< line2 > 69004 Lyon </ line2 >< line3 />< line4 > France </ line4 >< house />< street > Rue Jacques Louis - Henon </ street >< xstreet />
< unittype />< unit />< postal > 69004 </ postal >< neighborhood > 4 E Arrondissement </ neighborhood >< city > Lyon </ city >< county > Rhô ne </ county >< state > Rhone - Alpes </ state >
< country > France </ country >< countrycode > FR </ countrycode >< statecode />< countycode />< uzip > 69004 </ uzip >< hash />< woeid > 20068131 </ woeid >< woetype > 11 </ woetype ></ Result ></ results >
</ query ><!-- total : 90 -->
<!-- engine8 . yql . bf1 . yahoo . com -->
2014-05-29 20:10:26 +00:00
< query xmlns : yahoo = " http://www.yahooapis.com/v1/base.rng " yahoo : count = " 1 " yahoo : created = " 2014-05-20T18:13:30Z " yahoo : lang = " en-US " >< results >< Result >< quality > 87 </ quality >
< addressMatchType > POINT_ADDRESS </ addressMatchType >
< latitude > 48.281769 </ latitude >< longitude > 4.09041 </ longitude >< offsetlat > 48.281731 </ offsetlat >< offsetlon > 4.09047 </ offsetlon >< radius > 400 </ radius >
< name />< line1 > 38 B , Rue Maurice Romagon </ line1 >< line2 > 10800 Saint - Julien - les - Villas </ line2 >< line3 />< line4 > France </ line4 >< house > 38 B </ house >< street > Rue Maurice Romagon </ street >< xstreet />
< unittype />< unit />< postal > 10800 </ postal >< neighborhood />< city > Saint - Julien - les - Villas </ city >< county > Aube </ county >< state > Champagne - Ardenne </ state >< country > France </ country >< countrycode > FR </ countrycode >< statecode />< countycode > 10 </ countycode >< uzip > 10800 </ uzip >< hash > D49A3CF6AD6DEB1C </ hash >< woeid > 12722975 </ woeid >< woetype > 11 </ woetype ></ Result ></ results ></ query ><!-- total : 49 -->
2014-06-17 07:54:38 +00:00
<!-- engine4 . yql . bf1 . yahoo . com -->
2014-05-29 20:10:26 +00:00
2013-11-05 11:18:30 +00:00
*/
//echo "Yahoo :'$address'".EOL.$this->body.EOL;
if ( preg_match ( '! yahoo:count="0" !U' , $this -> body , $_match )) {
$this -> codeRetourY = 'ZERO_RESULTS' ;
//echo $this->codeRetourY.EOL;
return false ;
2014-05-29 20:10:26 +00:00
} elseif ( preg_match ( '!<quality>(.*)</quality>(?:.*)<latitude>(.*)</latitude><longitude>(.*)</longitude>!U' , $this -> body , $_match )) {
if ( preg_match ( '!<quality>(.*)</quality><addressMatchType>(.*)</addressMatchType><latitude>(.*)</latitude><longitude>(.*)</longitude>!U' , $this -> body , $_match2 )) {
$quality = $_match2 [ 1 ];
$qualityTxt = $_match2 [ 2 ];
$this -> codeRetourY = 'OK' ;
if ( $quality > 87 || $qualityTxt == 'POINT_ADDRESS' ) $this -> precision = 9 ; // POI or Coordinate
elseif ( $quality > 82 || $qualityTxt == 'INTERPOLATED' ) $this -> precision = 8 ; // Address (N° compris dans une Tranche d'adresse)
elseif ( $quality > 75 ) $this -> precision =- 7 ; // Intersection
elseif ( $quality > 70 ) $this -> precision =- 6 ; // Street match
elseif ( $quality > 40 ) $this -> precision =- 5 ; // Zip Code
elseif ( $quality > 30 ) $this -> precision =- 4 ; // Town
elseif ( $quality > 20 ) $this -> precision =- 3 ; // Sous/Région
elseif ( $quality > 10 ) $this -> precision =- 2 ; // Region/state
elseif ( $quality > 8 ) $this -> precision =- 1 ; // Country
else { $this -> precision = 0 ; // Not an address
$this -> codeRetourY = 'ZERO_RESULTS' ;
}
} else {
$quality = $_match [ 1 ];
$this -> codeRetourY = 'OK' ;
if ( $quality > 87 ) $this -> precision = 9 ; // POI or Coordinate
elseif ( $quality > 82 ) $this -> precision = 8 ; // Address
elseif ( $quality > 75 ) $this -> precision = 7 ; // Intersection
elseif ( $quality > 70 ) $this -> precision = 6 ; // Street match
elseif ( $quality > 40 ) $this -> precision = 5 ; // Zip Code
elseif ( $quality > 30 ) $this -> precision = 4 ; // Town
elseif ( $quality > 20 ) $this -> precision = 3 ; // Sous/Région
elseif ( $quality > 10 ) $this -> precision = 2 ; // Region/state
elseif ( $quality > 8 ) $this -> precision = 1 ; // Country
else { $this -> precision = 0 ; // Not an address
$this -> codeRetourY = 'ZERO_RESULTS' ;
}
2013-11-05 11:18:30 +00:00
}
$this -> latitudeDec = $_match [ 2 ];
$this -> longitudeDec = $_match [ 3 ];
$this -> latitudeDeg = dec2dms ( $this -> latitudeDec );
$this -> longitudeDeg = dec2dms ( $this -> longitudeDec );
if ( preg_match ( '!<line1>(.*)</line1>(?:|.*)<line2>(.*)</line2>(?:|.*)<line4>(.*)</line4>!Ui' , $this -> body , $_match )) {
$adrValide = utf8_decode ( $_match [ 1 ] . ', ' . $_match [ 2 ] . ', ' . $_match [ 3 ]);
$this -> adresseValidee = strtoupper ( str_replace ( ''' , " ' " , htmlspecialchars_decode ( $adrValide , ENT_QUOTES )));
$this -> codeRetourY = 'OK' ;
} elseif ( preg_match ( '!<line2>(.*)</line2>(?:|.*)<line4>(.*)</line4>!Ui' , $this -> body , $_match )) {
$adrValide = utf8_decode ( $_match [ 2 ] . ', ' . $_match [ 3 ]);
$this -> adresseValidee = strtoupper ( str_replace ( ''' , " ' " , htmlspecialchars_decode ( $adrValide , ENT_QUOTES )));
$this -> codeRetourY = 'OK' ;
} else
$this -> codeRetourY = 'INVALID_REQUEST' ;
} else
2013-11-06 14:29:20 +00:00
//die('Code Retour Yahoo 200 mais :'.$this->body.EOL);
2013-11-05 11:18:30 +00:00
2014-05-12 10:02:40 +00:00
if ( $this -> latitudeDec == 0 && ( $this -> longitudeDec == 0 || $this -> precision == 0 )) {
//die('Réponse Yahoo = '.$this->body.EOL);
return false ;
}
2013-11-05 11:18:30 +00:00
return true ; //array("lat"=>$lat,"lng"=>$lng,"address"=>$address);
} else
$this -> codeRetourY = 'INVALID_REQUEST' ;
return false ;
}
private function geoCodeAdrCpVilleG ( $adresse , $cp , $ville , $pays , $proxy = '' ) {
$this -> geocodeur = 'Google' ;
$this -> precision = 0 ;
2014-05-06 11:53:53 +00:00
$fileName = LOG_PATH . '/geoCodeur' . $this -> geocodeur . '.log' ;
2014-05-29 20:10:26 +00:00
$tmp =@ explode ( '|' , file_get_contents ( $fileName ));
$nbQuery =@ $tmp [ 1 ] * 1 ;
2013-11-05 11:18:30 +00:00
2014-05-29 20:10:26 +00:00
//$url='http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&sensor=false';
$url = 'https://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode ( $adresse . ', ' . $cp . ' ' . $ville . ', ' . $pays ) . '&sensor=false&key=' . $this -> apiKeyG ;
2013-11-05 11:18:30 +00:00
2014-05-29 20:10:26 +00:00
$page = getUrl ( $url , '' , '' , $this -> referer , false , 'maps.googleapis.com' , $proxy , 3 );
//print_r($page);
//die($url);
2013-11-05 11:18:30 +00:00
//getUrl($url, $strCookies='', $postData='', $referer='', $debug=false, $host='', $proxy='', $timeout=0) {
$this -> body = $page [ 'body' ];
$this -> codeRetour = $page [ 'code' ];
$this -> header = $page [ 'header' ];
2014-05-29 20:10:26 +00:00
$nbQuery ++ ;
file_put_contents ( $fileName , $this -> geocodeur . '|' . $nbQuery . '|' . $this -> codeRetour . " | $url | " . date ( 'Y-m-d H:i:s' ) . '|' . $this -> body . EOL );
2013-11-05 11:18:30 +00:00
if ( $this -> codeRetour == 200 ) {
// REVERSE GEOCODING
// http://maps.google.com/maps/geo?oe=utf-8&ll=48.808955,2.34227&output=xml&key=ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw
/*
0 Unknown location . ( Since 2.59 )
1 Country level accuracy . ( Since 2.59 )
2 Region ( state , province , prefecture , etc . ) level accuracy . ( Since 2.59 )
3 Sub - region ( county , municipality , etc . ) level accuracy . ( Since 2.59 )
4 Town ( city , village ) level accuracy . ( Since 2.59 )
5 Post code ( zip code ) level accuracy . ( Since 2.59 )
6 Street level accuracy . ( Since 2.59 )
7 Intersection level accuracy . ( Since 2.59 )
8 Address level accuracy . ( Since 2.59 )
*/
2014-05-29 20:10:26 +00:00
/* < ? xml version = " 1.0 " encoding = " UTF-8 " ?>
< GeocodeResponse >
< status > OK </ status >
< result >
< type > street_address </ type >
< formatted_address > 0 Impasse Saint - Germier , 31270 Frouzins , France </ formatted_address >
< address_component >
< long_name > 0 </ long_name >
< short_name > 0 </ short_name >
< type > street_number </ type >
</ address_component >
< address_component >
< long_name > Impasse Saint - Germier </ long_name >
< short_name > Imp . Saint - Germier </ short_name >
< type > route </ type >
< geometry >
< location >
< lat > 43.5160071 </ lat >
< lng > 1.3252185 </ lng >
</ location >
< location_type > RANGE_INTERPOLATED </ location_type >
</ geometry >
< partial_match > true </ partial_match >
</ result >
</ GeocodeResponse >
*/
2013-11-05 11:18:30 +00:00
$this -> codeRetourG =@ getTextInHtml ( $this -> body , '<GeocodeResponse>' , '<status>' , '</status>' );
$location_type =@ getTextInHtml ( $this -> body , '<geometry>' , '<location_type>' , '</location_type>' );
switch ( $location_type ) {
case 'ROOFTOP' : // Precise geocode for which we have location information accurate down to street address precision.
$this -> precision = 8 ;
break ;
case 'RANGE_INTERPOLATED' : // Approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
$this -> precision = 7 ;
break ;
case 'GEOMETRIC_CENTER' : // Geometric center of a result such as a polyline (for example, a street) or polygon (region).
$this -> precision = 6 ;
break ;
case 'APPROXIMATE' : // indicates that the returned result is approximate.
$this -> precision = 4 ;
break ;
default :
if ( $this -> codeRetourG == 'ZERO_RESULTS' ) // Indicates that the geocode was successful but returned no results.
$this -> precision = 0 ; // This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
break ;
}
2014-05-29 20:10:26 +00:00
$this -> adresseValidee = strtoupper ( str_replace ( ''' , " ' " , htmlspecialchars_decode ( utf8_decode ( @ getTextInHtml ( $this -> body , '<result' , '<formatted_address>' , '</formatted_address>' )), ENT_QUOTES )));
if ( preg_match ( '!<geometry>(?:.*)<location>(?:.*)<lat>(.*)</lat>(?:.*)<lng>(.*)</lng>(?:.*)</location>!Uis' , $this -> body , $matches2 )) {
$this -> latitudeDec =@ $matches2 [ 1 ];
$this -> longitudeDec =@ $matches2 [ 2 ];
2013-11-05 11:18:30 +00:00
$this -> latitudeDeg = dec2dms ( $this -> latitudeDec );
$this -> longitudeDeg = dec2dms ( $this -> longitudeDec );
2014-05-29 20:10:26 +00:00
}
2013-11-05 11:18:30 +00:00
/*
200 G_GEO_SUCCESS No errors occurred ; the address was successfully parsed and its geocode has been returneds -> geocodeur = 'Google' ;
400 G_GEO_BAD_REQUEST A directions request could not be successfully parsed .
500 G_GEO_SERVER_ERROR A geocoding or directions request could not be successfully processed , yet the exact reason for the failure is not known .
601 G_GEO_MISSING_QUERY The HTTP q parameter was either missing or had no value . For geocoding requests , this means that an empty address was
specified as input . For directions requests , this means that no query was specified in the input .
602 G_GEO_UNKNOWN_ADDRESS No corresponding geographic location could be found for the specified address . This may be due to the fact that the address
is relatively new , or it may be incorrect .
603 G_GEO_UNAVAILABLE_ADDRESS The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual
reasons .
604 G_GEO_UNKNOWN_DIRECTIONS The GDirections object could not compute directions between the points mentioned in the query . This is usually because
there is no route available between the two points , or because we do not have data for routing in that region .
610 G_GEO_BAD_KEY The given key is either invalid or does not match the domain for which it was given .
620 G_GEO_TOO_MANY_QUERIES The given key has gone over the requests limit in the 24 hour period .
< GeocodeResponse >< status > OK </ status >< result >< type > street_address </ type >< formatted_address > 2 Route du Cure , 92410 Ville - d 'Avray, France</formatted_address><address_component><long_name>2</long_name><short_name>2</short_name><type>street_number</type></address_component><address_component><long_name>Route du Cure</long_name><short_name>Route du Cure</short_name><type>route</type></address_component><address_component><long_name>Ville-d' Avray </ long_name >< short_name > Ville - d ' Avray </ short_name >< type > locality </ type >< type > political </ type ></ address_component >< address_component >< long_name > Hauts - de - Seine </ long_name >< short_name > 92 </ short_name >< type > administrative_area_level_2 </ type >< type > political </ type ></ address_component >< address_component >< long_name > Île - de - France </ long_name >< short_name > IDF </ short_name >< type > administrative_area_level_1 </ type >< type > political </ type ></ address_component >< address_component >< long_name > France </ long_name >< short_name > FR </ short_name >< type > country </ type >< type > political </ type ></ address_component >< address_component >< long_name > 92410 </ long_name >< short_name > 92410 </ short_name >< type > postal_code </ type ></ address_component >< geometry >< location >< lat > 48.8252802 </ lat >< lng > 2.1821693 </ lng ></ location >
/*
" OK " indicates that no errors occurred ; the address was successfully parsed and at least one geocode was returned .
" OVER_QUERY_LIMIT " indicates that you are over your quota .
" REQUEST_DENIED " indicates that your request was denied , generally because of lack of a sensor parameter .
" " generally indicates that the query ( address or latlng ) is missing .
UNKNOWN_ERROR indicates that the request could not be processed due to a server error . The request may succeed if you try again .
*/
2014-05-29 20:10:26 +00:00
/*
< ? xml version = " 1.0 " encoding = " UTF-8 " ?>
< GeocodeResponse >
< status > OVER_QUERY_LIMIT </ status >
< error_message > You have exceeded your daily request quota for this API .</ error_message >
</ GeocodeResponse >
*/
if ( $this -> codeRetourG == 'OK' ) {
//echo $this->body.EOL;
//echo 'Adr='.$this->adresseValidee.EOL;
//echo 'Lat='.$this->latitudeDec.EOL;
//echo 'Lon='.$this->longitudeDec.EOL;
//echo 'Pre='.$this->precision.EOL;
//die();
2013-11-05 11:18:30 +00:00
return true ;
2014-05-29 20:10:26 +00:00
}
2013-11-05 11:18:30 +00:00
elseif ( $this -> codeRetourG == 'ZERO_RESULTS' || // http://maps.googleapis.com/maps/api/geocode/xml?address=0044+RUE+JACQUES+-+LOUIS+HENON%2C+69004+LYON+4EME%2C+France&sensor=false
$this -> codeRetourG == 'INVALID_REQUEST' || // http://maps.googleapis.com/maps/api/geocode/xml?address=0028+B+RUE+MGR+DE+BEAUMONT%2C+97400+SAINT+DENIS%2C+La+R%E9union&sensor=false
$this -> codeRetourG == 'OVER_QUERY_LIMIT' ) {
return false ;
} else {
2013-11-06 14:29:20 +00:00
return false ;
//echo $url.' ('.$this->codeRetour.')'.EOL;
//die('Code Retour Google ='.$this->codeRetourG.EOL);
2013-11-05 11:18:30 +00:00
}
}
return false ;
}
2014-06-17 07:54:38 +00:00
/** Géocodage d ' une adresse
0 Unknown location . ( Since 2.59 )
1 Country level accuracy . ( Since 2.59 )
2 Region ( state , province , prefecture , etc . ) level accuracy . ( Since 2.59 )
3 Sub - region ( county , municipality , etc . ) level accuracy . ( Since 2.59 )
4 Town ( city , village ) level accuracy . ( Since 2.59 )
5 Post code ( zip code ) level accuracy . ( Since 2.59 )
6 Street level accuracy . ( Since 2.59 )
7 Intersection level accuracy . ( Since 2.59 )
8 Address level accuracy . ( Since 2.59 )
9 Address level accuracy +++
**/
public function geoCodeAdresse ( $adrNum , $adrIndRep , $adrTypeVoieCourt , $adrTypeVoieLong , $adrLibVoie , $cp , $ville = '' , $pays = 'France' , $codeRivoli = '' )
2014-06-02 08:41:24 +00:00
{
2015-04-07 15:38:59 +00:00
$tabRep = array ();
$adrNum = str_pad ( $adrNum , 4 , 0 , STR_PAD_LEFT );
$adresse = addslashes ( trim ( preg_replace ( '/ +/' , ' ' , " $adrNum $adrIndRep $adrTypeVoieLong $adrLibVoie " )));
$ville = addslashes ( $ville );
2015-04-27 15:05:08 +00:00
$ret = $this -> iDb -> select ( 'jo.zonageXY' , 'lat, lon, l93_x, l93_y, alt, precis, adresseValidee, dateInsert' ,
2014-06-17 07:54:38 +00:00
" address=' $adresse ' AND adr_cp=' $cp ' AND adr_ville=' $ville ' " , false , MYSQL_ASSOC );
2015-04-07 15:38:59 +00:00
2014-06-17 07:54:38 +00:00
//Existe dans la base
2013-11-05 11:18:30 +00:00
if ( count ( $ret ) > 0 ) {
$zonage = $ret [ 0 ];
$this -> precision = $zonage [ 'precis' ] * 1 ;
$this -> adresseValidee = strtoupper ( $zonage [ 'adresseValidee' ]);
$this -> latitudeDec = $zonage [ 'lat' ] * 1 ;
$this -> longitudeDec = $zonage [ 'lon' ] * 1 ;
$this -> l93x = $zonage [ 'l93_x' ];
$this -> l93y = $zonage [ 'l93_y' ];
$this -> altitude = $zonage [ 'alt' ];
if ( $this -> altitude == NULL && $this -> precision > 5 ) {
if ( $this -> accesDist ) {
$alt = $this -> getAltitude ( $this -> latitudeDec , $this -> longitudeDec );
$this -> altitude = $alt [ 'alt' ];
}
}
if ( $this -> l93x == NULL && $this -> precision > 5 ) {
$tmp = geos2lambert93 ( $this -> latitudeDec , $this -> longitudeDec );
$this -> l93x = $tmp [ 'x_93' ];
$this -> l93y = $tmp [ 'y_93' ];
}
if ( $this -> altitude <> NULL || $this -> l93x <> NULL ) {
2014-06-17 07:54:38 +00:00
$tabUpdate = array (
'alt' => $this -> altitude ,
'l93_x' => $this -> l93x ,
'l93_y' => $this -> l93y
);
2015-04-27 14:26:46 +00:00
$this -> iDb -> update ( 'jo.zonageXY' , $tabUpdate , " address=' $adresse ' AND adr_cp=' $cp ' AND adr_ville=' $ville ' " );
2013-11-05 11:18:30 +00:00
}
2014-06-17 07:54:38 +00:00
$this -> latitudeDeg = dec2dms ( $this -> latitudeDec );
$this -> longitudeDeg = dec2dms ( $this -> longitudeDec );
2013-11-05 11:18:30 +00:00
$this -> enCache = true ;
$ligne = 'En base : ' . print_r ( $zonage , true );
2014-06-17 07:54:38 +00:00
}
//Acces Distant
elseif ( $this -> accesDist )
{
2013-11-05 11:18:30 +00:00
$this -> enCache = false ;
2014-05-29 20:10:26 +00:00
$retG = $retY = $retC = $retM = false ;
2013-11-05 11:18:30 +00:00
if ( substr ( $codeRivoli , 0 , 3 ) * 1 == 971 ) $pays = 'Guadeloupe' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 972 ) $pays = 'Martinique' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 973 ) $pays = 'Guyane' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 974 ) $pays = 'La Réunion' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 975 ) $pays = 'Saint-Pierre-et-Miquelon' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 976 ) $pays = 'Mayotte' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 977 ) $pays = 'Saint-Martin' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 978 ) $pays = 'Saint-Barthélémy' ;
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 985 ) $pays = 'Saint-Pierre-et-Miquelon' ; //98501 à 98502 St Pierre et Miquelon (anciens codes non compatibles 97501 à 97502)
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 986 ) $pays = 'Wallis-et-Futuna' ; // 98601 à 98617 Mayotte (anciens codes non compatibles : 98501 à 98517)
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 987 ) $pays = 'Polynésie française' ; // 98711 à 98758,98799 Polynésie française (sans changement)
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 988 ) $pays = 'Nouvelle Calédonie' ; // 98801 à 98832 Nouvelle Calédonie (sans changement)
elseif ( substr ( $codeRivoli , 0 , 3 ) * 1 == 989 ) $pays = 'Wallis-et-Futuna' ; // 98911 à 98913 Wallis et Futuna (anciens codes non compatibles : 98611 à 98613)
2014-05-29 20:10:26 +00:00
/* elseif ( substr ( $codeRivoli , 0 , 2 ) * 1 > 96 && substr ( $codeRivoli , 0 , 2 ) * 1 < 99 )
die ( " Code Rivoli non géré : ' $codeRivoli ' " . EOL ); */
2013-11-05 11:18:30 +00:00
$retG = $this -> geoCodeAdrCpVilleG ( $adresse , $cp , $ville , $pays );
if ( $this -> codeRetourG == 'OVER_QUERY_LIMIT' || $this -> precision == 0 ) {
$retY = $this -> geoCodeAdrCpVilleY ( " $adresse , $cp $ville , $pays " );
if ( $this -> codeRetourY == 'OVER_QUERY_LIMIT' || $this -> codeRetourY <> 'OK' || $this -> precision == 0 )
$retC = $this -> geoCodeAdrCpVilleC ( $adresse , $cp , $ville , $pays );
// $retM=$this->geoCodeAdrCpVilleM($adresse, $cp, $ville, $pays);
}
// On récupère l'altitude
2014-03-27 13:50:14 +00:00
//echo ('Précision : '. $this->precision.EOL);
2013-11-05 11:18:30 +00:00
if ( $this -> precision > 5 && $this -> latitudeDec <> 0 && $this -> longitudeDec <> 0 ) {
$alt = $this -> getAltitude ( $this -> latitudeDec , $this -> longitudeDec );
$this -> altitude = $alt [ 'alt' ];
}
$tmp = geos2lambert93 ( $this -> latitudeDec , $this -> longitudeDec );
$this -> l93x = $tmp [ 'x_93' ];
$this -> l93y = $tmp [ 'y_93' ];
2014-03-27 13:50:14 +00:00
//echo ('$retG='.$retG.EOL.'$retY='.$retY.EOL.'$retC='.$retC.EOL.'$retM='.$retM.EOL);
2013-11-05 11:18:30 +00:00
if ( $retG || $retY || $retM || $retC ) {
$adresse = stripslashes ( strtoupper ( trim ( preg_replace ( '/ +/' , ' ' , " $adrNum $adrIndRep $adrTypeVoieLong $adrLibVoie " ))));
$ville = stripslashes ( $ville );
$tabInsert = array ( 'address' => $adresse ,
'adr_cp' => $cp ,
'adr_ville' => $ville ,
'adrNum' => $adrNum ,
'adrIndRep' => $adrIndRep ,
'adrTypeVoie' => $adrTypeVoieCourt ,
'adrLibVoie' => $adrLibVoie ,
'rivoli' => $codeRivoli ,
'adresseValidee' => $this -> adresseValidee ,
'lat' => $this -> latitudeDec ,
'lon' => $this -> longitudeDec ,
'l93_x' => $this -> l93x ,
'l93_y' => $this -> l93y ,
'alt' => $this -> altitude ,
'precis' => $this -> precision ,
'source' => $this -> geocodeur ,
'dateInsert' => DATETIME ,
);
/** Insertion de l ' adresse que si elle est possible
**/
2014-03-27 13:50:14 +00:00
//echo ('Avant Insert '.$this->latitudeDec.EOL.$this->longitudeDec.EOL);
2014-05-29 20:10:26 +00:00
if ( $this -> latitudeDec <> 0 && $this -> longitudeDec <> 0 && $this -> precision > 0 ) {
// print_r($tabInsert);
//echo ($this->latitudeDec.EOL.$this->longitudeDec.EOL);
2015-04-27 14:25:04 +00:00
$this -> iDb -> insert ( 'jo.zonageXY' , $tabInsert );
2014-05-29 20:10:26 +00:00
/*if (mysql_errno()>0) echo mysql_error().die(EOL);*/
2013-11-05 11:18:30 +00:00
} else {
$this -> precision = $this -> latitudeDec = $this -> longitudeDec = 0 ;
$this -> adresseValidee = '' ;
$this -> latitudeDeg = $this -> longitudeDeg = '' ;
$ligne = " Erreur Geocodage : $adrNum , $adrIndRep , $adrTypeVoieCourt , $adrTypeVoieLong , $adrLibVoie , $cp , $ville , $pays , $codeRivoli , " . $this -> body ;
//die('Latitude et longitude à zero :'.$this->latitudeDec.EOL.$this->longitudeDec.EOL);
}
2014-03-27 13:50:14 +00:00
//echo ('Après Insert : '.$this->latitudeDec.EOL.$this->longitudeDec.EOL);
2013-11-05 11:18:30 +00:00
$ligne = 'Accès Google : ' . print_r ( $tabInsert , true );
}
else {
$this -> precision = $this -> latitudeDec = $this -> longitudeDec = 0 ;
$this -> adresseValidee = '' ;
$this -> latitudeDeg = $this -> longitudeDeg = '' ;
$ligne = " Erreur : $adrNum , $adrIndRep , $adrTypeVoieCourt , $adrTypeVoieLong , $adrLibVoie , $cp , $ville , $pays , $codeRivoli , " . $this -> body ;
}
}
}
/** Retourne la distance en kilomètres entre 2 coordonnées GPS à la surface de la terre
**
** @ param double $latA Latitude du point A en décimal
** @ param double $lonA Longitude du point A en décimal
** @ param double $latB Latitude du point B en décimal
** @ param double $lonB Longitude du point B en décimal
** @ param string $sphere Type de sphère
** @ return unknown
**/
function distance ( $latA = 0 , $lonA = 0 , $latB = 0 , $lonB = 0 , $sphere = 'GRS80' ) {
switch ( $sphere ) {
case 'HAYFORD' : $R = 6378.388 ; // Demi grand axe ou Rayon de la sphère International Hayford 1909 en Kms
$f = 1 / 297 ; // Aplatissement
break ;
case 'PICARD' : $R = 6371.598 ; // Demi grand axe ou Rayon de la sphère Picard en Kms
break ;
case 'GRS80' :
default : $R = 6378.137 ; // Demi grand axe ou Rayon de la sphère GRS80 en Kms
$f = 1 / 298.257222101 ;
break ;
}
$a = pi () / 180 ;
$e = $latA * $a ;
$f = $lonA * $a ;
$g = $latB * $a ;
$h = $lonB * $a ;
$j = acos ( cos ( $e ) * cos ( $g ) * cos ( $f ) * cos ( $h ) + cos ( $e ) * sin ( $f ) * cos ( $g ) * sin ( $h ) + sin ( $e ) * sin ( $g ));
return round ( $R * $j , 3 ); // div par 1.852 ==> résultat en miles nautiques
}
/** Retourne la distance en mètres entre 2 points sur une surface plane
** @ param double $x1 Coordonnée X du point 1 en décimal
** @ param double $y1 Coordonnée Y du point 1 en décimal
** @ param double $x2 Coordonnée X du point 2 en décimal
** @ param double $y2 Coordonnée Y du point 2 en décimal
** @ return double
**/
function distanceLambert ( $x1 , $y1 , $x2 , $y2 ) {
return sqrt ( pow ( $x1 - $x2 , 2 ) + ( pow ( $y1 - $y2 , 2 ) ) );
}
/** Retourne l 'altitude en mètres d' un point GPS . Shuttle Radar Topography Mission ( SRTM ) elevation data ( resolution 90 mx90m )
** @ url http :// ws . geonames . org / export / web - services . html
** @ param double $tabLatLon Latitude du point ou Tableau de Points avec latitudes longitudes array ( 'lat' => x , 'lon' => y )
** @ param double $lon Longitude ou false si tableau
** @ return double
**/
function getAltitude ( $tabLatLon , $lon = false ) {
if ( $lon ) {
/* Elevation - SRTM3
Shuttle Radar Topography Mission ( SRTM ) elevation data . SRTM consisted of a specially modified radar system that flew onboard the Space Shuttle Endeavour during an 11 - day mission in February of 2000. The dataset covers land areas between 60 degrees north and 56 degrees south .
This web service is using SRTM3 data with data points located every 3 - arc - second ( approximately 90 meters ) on a latitude / longitude grid . Documentation : Nasa
Webservice Type : REST
Url : api . geonames . org / srtm3 ?
Parameters : lat , lng ;
sample area : ca 90 m x 90 m Result : a single number giving the elevation in meters according to srtm3 , ocean areas have been masked as " no data " and have been assigned a value of - 32768
Example http :// api . geonames . org / srtm3 ? lat = 50.01 & lng = 10.2 & username = demo
This service is also available in XML and JSON format : api . geonames . org / srtm3XML ? lat = 50.01 & lng = 10.2 & username = demo api . geonames . org / srtm3JSON ? lat = 50.01 & lng = 10.2 & username = demo
The text version of the service also accepts a list of lat / lng for the parameters 'lats' and 'lngs' . On the free server the number of points per call is limited to 20 , for the premium service the limit is 2000 :
[ 0 ] => the daily limit of 30000 credits 78.31 . 45.206 has been exceeded . Please throttle your requests or use the commercial service
[ 1 ] => daily
[ 2 ] => 30000
[ 3 ] => 78.31 . 45.206
*/
2014-05-29 20:10:26 +00:00
$url = " http://ws.geonames.org/srtm3?lat= $tabLatLon &lng= $lon &username=scores_et_decisions&password=bj10sx " ;
2013-11-05 11:18:30 +00:00
$page = getUrl ( $url , '' , '' , '' , false , '' , '' , 3 );
$alt = trim ( $page [ 'body' ]);
if ( preg_match ( '/the (.*) limit of (.*) credits(.*) has been exceeded\. Please throttle your requests or use the commercial service/Uis' , $alt , $matches )) {
print_r ( $matches );
$alt = NULL ;
} elseif ( $page [ 'code' ] <> 200 || $alt ==- 32768 ) {
if ( $page [ 'code' ] <> 200 ) echo '==========================>' . $page [ 'code' ] . '<==================================' . EOL ;
$alt = NULL ;
}
return array ( 'lat' => $tabLatLon , 'lon' => $lon , 'alt' => $alt );
} else {
$LatLon = '' ;
$Lats = '' ;
$Lons = '' ;
foreach ( $tabLatLon as $i => $latlon ) {
$lat = $latlon [ 'lat' ];
$lon2 = $latlon [ 'lon' ];
if ( $i > 0 ) {
$LatLon .= " %0D%0A " ;
$Lats .= ',' ;
$Lons .= ',' ;
}
$LatLon .= " $lat %2C $lon2 " ;
$Lats .= $lat ;
$Lons .= $lon ;
}
// http://api.geonames.org/srtm3?lats=50.01,51.01&lngs=10.2,11.2&username=demo
/* $url = " http://api.geonames.org/srtm3?lats= $Lats &lng= $Lons &username=demo " ;
$page = getUrl ( $url , '' , '' , '' , false , '' , '' , 3 );
$alt = trim ( $page [ 'body' ]);
die ( $alt );
if ( $page [ 'code' ] <> 200 || $alt ==- 32768 ) {
if ( $page [ 'code' ] <> 200 ) echo '==========================>' . $page [ 'code' ] . '<==================================' . EOL ;
$alt = NULL ;
}
return array ( 'lat' => $tabLatLon , 'lon' => $lon , 'alt' => $alt );
*/
}
$url = 'http://www.fredorando.fr/Pages/altitude.php' ;
$post = array ( 'LatLon' => $LatLon , 'qui' => '' );
$page = getUrl ( $url , '' , $post , '' , false , '' , '' , 3 );
$body = $page [ 'body' ];
$tabRet = false ;
if ( preg_match ( '/<BODY>\s+IP\:(?:.*)<br\/>\s+url\:(?:.*)<br\/>(?:.*)<br\/>(?:.*)<br\/>(.*)<br\/>(?:.*)<a href="http/Uis' , $body , $matches )) {
$tabRet = array ();
$tabTmp = explode ( '<br />' , $matches [ 1 ]);
foreach ( $tabTmp as $i => $ret ) {
$ret2 = explode ( ',' , trim ( $ret ));
$alt = $ret2 [ 2 ];
if ( $alt ==- 32768 ) $alt = NULL ;
$tabRet [ $i ] =@ array ( 'lat' => $ret2 [ 0 ], 'lon' => $ret2 [ 1 ], 'alt' => $alt );
}
unset ( $tabRet [ $i ]);
}
if ( $lon ) return $tabRet [ 0 ];
return $tabRet ;
}
}
if ( ! function_exists ( 'json_decode' ) ){
function json_decode ( $content , $assoc = false ){
require_once 'Services/JSON.php' ;
if ( $assoc ){
$json = new Services_JSON ( SERVICES_JSON_LOOSE_TYPE );
} else {
$json = new Services_JSON ;
}
return $json -> decode ( $content );
}
}
if ( ! function_exists ( 'json_encode' ) ){
function json_encode ( $content ){
require_once 'Services/JSON.php' ;
$json = new Services_JSON ;
return $json -> encode ( $content );
}
}
?>