This commit is contained in:
Michael RICOIS 2014-05-27 12:56:14 +00:00
parent 300e4bd3c9
commit e225e6c336
3 changed files with 126 additions and 55 deletions

View File

@ -515,7 +515,8 @@ class MMap {
public $adresseValidee='';
public $enCache=false;
private $apiKeyG='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw';
// private $apiKeyG='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw';
private $apiKeyG='AIzaSyBfyIMaVwm1nn8AupBf-asC816R71LZl8g';
// private $apiKey='ABQIAAAAuKBtUyFonYJBl1fqfc78tRT4Qe_2x2fax4Crd4sBzQI-tDkl3BRm2l2feTV5Lnx0Ah-aTIlwHtglpA';
private $apiKeyY='klII0gzV34Ho2TCsN3XiXeh4No033AifxMeDXfFXj8TDCXO3WAtOLj9c74VsV45HcII-';
private $apiKeyC='ae5216123e414fcd84b8ca9a0f43a68c';
@ -566,7 +567,7 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
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
default: die('Precisions Inconnue : "'.$result->geocode_level->code.'"='.$result->geocode_level->label.EOL.$page['body']); break;
default: /*die('Precisions Inconnue : "'.$result->geocode_level->code.'"='.$result->geocode_level->label.EOL.$page['body']);*/ break;
}
$this->adresseValidee=@preg_replace('/ +/', ' ', strtoupper(str_replace(''', "'", trim(htmlspecialchars_decode($result->road_element->number.' '.$result->way->name,ENT_QUOTES)))));
@ -615,8 +616,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$this->precision=0;
$fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log';
$tmp=@explode(',',file_get_contents($filename));
$nbQuery=$tmp[0]*1;
$tmp=@explode('|',file_get_contents($fileName));
$nbQuery=@$tmp[1]*1;
if ($pays=='') $pays='France';
/*if (preg_match('/^([0-9]{1,4} )(.*)$/', $adresse, $matches)) {
@ -632,8 +633,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$this->codeRetour=$page['code'];
$this->header=$page['header'];
$nbQuery=($nbQuery*1)+1;
file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL);
$nbQuery++;
file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL);
$res=@json_decode(utf8_decode($page['body']));
if ($this->codeRetour==200 && $res->status->success==1) {
@ -643,6 +644,9 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
case 'housenumber': $this->precision=8; break;
case 'street': $this->precision=6; break;
case 'zip': $this->precision=5; break;
case 'city': $this->precision=4; break;
case 'district': $this->precision=3; break;
case 'sight': $this->precision=0; break;
default:
//print_r($res);
//die('addressType inconnue : '.$geoCodage->addressType.EOL);
@ -663,7 +667,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
echo 'lon='.$this->longitudeDec.EOL;
echo 'precis='.$this->precision.EOL;
die($url);*/
return true;
if ($this->precision>0)
return true;
}
//print_r($page);
//print_r($res);
@ -677,18 +682,18 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$this->precision=0;
$fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log';
$tmp=@explode(',',file_get_contents($filename));
$nbQuery=$tmp[0]*1;
$tmp=@explode('|',file_get_contents($fileName));
$nbQuery=@$tmp[1]*1;
$_url='http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text%3D%22'.rawurlencode($address).'%22&format=xml';
$url='http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text%3D%22'.rawurlencode($address).'%22&format=xml';
$_result = false;
$page=getUrl($_url, '', '', '', false, '', '', 3);
$page=getUrl($url, '', '', '', false, '', '', 3);
$this->body=$page['body'];
$this->codeRetour=$page['code'];
$this->header=$page['header'];
$nbQuery=($nbQuery*1)+1;
file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL);
$nbQuery++;
file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL);
if ($this->codeRetour==200) {
@ -700,6 +705,14 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
<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 -->
<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>38B, Rue Maurice Romagon</line1><line2>10800 Saint-Julien-les-Villas</line2><line3/><line4>France</line4><house>38B</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 -->
<!-- engine4.yql.bf1.yahoo.com -->
*/
//echo "Yahoo :'$address'".EOL.$this->body.EOL;
@ -707,20 +720,38 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$this->codeRetourY='ZERO_RESULTS';
//echo $this->codeRetourY.EOL;
return false;
} elseif (preg_match('!<quality>(.*)</quality><latitude>(.*)</latitude><longitude>(.*)</longitude>!U', $this->body, $_match)) {
$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';
} 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';
}
}
$this->latitudeDec=$_match[2];
$this->longitudeDec=$_match[3];
@ -755,19 +786,22 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$this->precision=0;
$fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log';
$tmp=@explode(',',file_get_contents($filename));
$nbQuery=$tmp[0]*1;
$tmp=@explode('|',file_get_contents($fileName));
$nbQuery=@$tmp[1]*1;
$url='http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&sensor=false';
//$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;
$page=getUrl($url, '', '', $this->referer, false, 'maps.google.com', $proxy,3);
$page=getUrl($url, '', '', $this->referer, false, 'maps.googleapis.com', $proxy,3);
//print_r($page);
//die($url);
//getUrl($url, $strCookies='', $postData='', $referer='', $debug=false, $host='', $proxy='', $timeout=0) {
$this->body=$page['body'];
$this->codeRetour=$page['code'];
$this->header=$page['header'];
$nbQuery=($nbQuery*1)+1;
file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL);
$nbQuery++;
file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL);
if ($this->codeRetour==200) {
// REVERSE GEOCODING
@ -784,6 +818,32 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
7 Intersection level accuracy. (Since 2.59)
8 Address level accuracy. (Since 2.59)
*/
/* <?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>
*/
$this->codeRetourG=@getTextInHtml($this->body, '<GeocodeResponse>', '<status>', '</status>');
$location_type=@getTextInHtml($this->body, '<geometry>', '<location_type>', '</location_type>');
switch($location_type) {
@ -805,17 +865,16 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
break;
}
$this->adresseValidee=strtoupper(str_replace('&apos;', "'", htmlspecialchars_decode(utf8_decode(@getTextInHtml($this->body, '<Placemark', '<address>', '</address>')),ENT_QUOTES)));
$strTmp=@getTextInHtml($this->body, '<Point><coordinates>', '<coordinates>', '</coordinates>');
$tabTmp=explode(',', $strTmp);
$this->latitudeDec=@$tabTmp[1];
$this->longitudeDec=$tabTmp[0];
$this->adresseValidee=strtoupper(str_replace('&apos;', "'", 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];
$this->latitudeDeg=dec2dms($this->latitudeDec);
$this->longitudeDeg=dec2dms($this->longitudeDec);
}
/*
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
@ -840,8 +899,23 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
UNKNOWN_ERROR indicates that the request could not be processed due to a server error. The request may succeed if you try again.
*/
if ($this->codeRetourG=='OK')
/*
<?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();
return true;
}
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') {
@ -907,7 +981,7 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
$ligne='En base : '.print_r($zonage, true);
} elseif ($this->accesDist) {
$this->enCache=false;
$retM=$retY=false;
$retG=$retY=$retC=$retM=false;
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';
@ -921,8 +995,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
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)
elseif (substr($codeRivoli,0,2)*1>96 && substr($codeRivoli,0,2)*1<99)
die("Code Rivoli non géré : '$codeRivoli'".EOL);
/*elseif (substr($codeRivoli,0,2)*1>96 && substr($codeRivoli,0,2)*1<99)
die("Code Rivoli non géré : '$codeRivoli'".EOL);*/
$retG=$this->geoCodeAdrCpVilleG($adresse, $cp, $ville, $pays);
if ($this->codeRetourG=='OVER_QUERY_LIMIT' || $this->precision==0) {
@ -968,11 +1042,11 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999
/** Insertion de l'adresse que si elle est possible
**/
//echo ('Avant Insert '.$this->latitudeDec.EOL.$this->longitudeDec.EOL);
if ($this->latitudeDec<>0 && $this->longitudeDec<>0) {
print_r($tabInsert);
echo ($this->latitudeDec.EOL.$this->longitudeDec.EOL);
if ($this->latitudeDec<>0 && $this->longitudeDec<>0 && $this->precision>0) {
// print_r($tabInsert);
//echo ($this->latitudeDec.EOL.$this->longitudeDec.EOL);
$iDb->insert('zonageXY', $tabInsert);
if (mysql_errno()>0) echo mysql_error().die(EOL);
/*if (mysql_errno()>0) echo mysql_error().die(EOL);*/
} else {
$this->precision=$this->latitudeDec=$this->longitudeDec=0;
$this->adresseValidee='';
@ -1074,7 +1148,7 @@ The text version of the service also accepts a list of lat/lng for the parameter
[3] => 78.31.45.206
*/
$url="http://ws.geonames.org/srtm3?lat=$tabLatLon&lng=$lon";
$url="http://ws.geonames.org/srtm3?lat=$tabLatLon&lng=$lon&username=scores_et_decisions&password=bj10sx";
$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)) {

View File

@ -53,11 +53,7 @@ $sql = $commandesM->select()
->where("dateStart != '0000-00-00 00:00:00'")
->where("dateStop = '0000-00-00 00:00:00'");
$result = $commandesM->fetchAll($sql);
if ( count($result)>0 ) {
} else {
if ( count($result)==0 ) {
//Si pas de traitement en cours alors on lance
$sql = $commandesM->select()
@ -69,7 +65,8 @@ if ( count($result)>0 ) {
if (count($result)>0) {
$info = $result->current();
echo "Lancement enrichissement $info->id\n";
exec('php '.realpath(dirname(__FILE__))."/jobs/enrichissement.php --id ".$info->id." &");
$log = $application->profil->path->data.'/log/'.$info->id.'.log';
exec('php '.__DIR__."/jobs/enrichissement.php --id ".$info->id." 2>&1 >> ".$log." &");
}
}

View File

@ -1463,7 +1463,7 @@ function GPSData($siren, $nic, $values = false)
$result = $iDb->select(
'etablissements e',
"e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, e.adr_cp, e.adr_ville",
"LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville",
"siren=$siren AND nic=$nic", false, MYSQL_ASSOC);
if (count($result)>0) {
$MInsee = new MInsee($iDb);